synScript.c
9.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*====================================================================
* synScript.c
*
* Synopsis: This test file was actually built off of test2.c and
* was rewritten to perform scripted actions not random actions.
* I used this to track down the "stopping and stopped voice" bug.
* Currently, this test only provides one voice and one sound.
*
* Copyright 1993, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
#include <assert.h>
#include <libaudio.h>
#include "audiotest.h"
#include "audio.h"
#include "synScript.h"
static void InitTest(u32 subTestNum);
static void StopTest(u32 subTestNum);
static void ButtonProc(u16 oldButtons,u16 newButtons);
static void InitScript0(TScript *pScript);
static void playerNew(TTestPlayer *p, int numVoices, ALBank *bank);
static void playerDelete(TTestPlayer *p);
static void playerSetBank(TTestPlayer *p, ALBank *bank);
static int playerPlay(TTestPlayer *p);
static int playerStop(TTestPlayer *p);
static ALMicroTime _voiceHandler(void *node);
static ALMicroTime _voiceHandler2(void *node);
static void nullAction(TTestPlayer *p);
static void done(TTestPlayer *p);
static void allocVoice(TTestPlayer *p);
static void freeVoice(TTestPlayer *p);
static void startVoice(TTestPlayer *p);
static void stopVoice(TTestPlayer *p);
static void TestPitchLimit (void);
static TTestPlayer *p;
static char doStart = FALSE, doStop = FALSE;
extern ALHeap gHeapRec;
extern u8 gHeapBuf[AUDIO_HEAP_SIZE];
test_cntrl synScriptTest = {
&InitTest,
&StopTest,
&ButtonProc,
NULL,
NULL, /* void *retraceData */
1 /* u32 numSubTests */
};
static TScriptAction script0[] =
{
(TScriptActionProc)allocVoice, 0,
(TScriptActionProc)stopVoice, 0,
(TScriptActionProc)startVoice, 2*ONE_SEC,
(TScriptActionProc)stopVoice, 0,
(TScriptActionProc)stopVoice, 2*ONE_SEC,
(TScriptActionProc)stopVoice, 2*ONE_SEC,
(TScriptActionProc)stopVoice, 0,
(TScriptActionProc)startVoice, 2*ONE_SEC,
(TScriptActionProc)stopVoice, 0,
(TScriptActionProc)done, END_OF_SCRIPT
};
static
void InitTest (u32 subTestNum)
{
ALSynConfig c;
u32 bankLen;
ALBankFile *bankPtr;
ALBank *bank;
amConfig amc;
alHeapInit(&gHeapRec, gHeapBuf, sizeof(gHeapBuf));
/**** Load the bank file from ROM ****/
bankLen = _midibankSegmentRomEnd - _midibankSegmentRomStart;
bankPtr = alHeapAlloc(&gHeapRec, 1, bankLen);
romCopy(_midibankSegmentRomStart, (char *)bankPtr, bankLen);
alBnkfNew(bankPtr, (u8 *) _miditableSegmentRomStart);
bank = bankPtr->bankArray[0];
/**** Create the Audio Manager ****/
c.maxVVoices = MAX_SYNTH_VVOICES;
c.maxPVoices = MAX_SYNTH_PVOICES;
c.maxUpdates = MAX_SYNTH_UPDATES;
c.dmaproc = 0; /* audio mgr will fill this in */
c.fxType = AL_FX_NONE;
c.heap = &gHeapRec;
amc.outputRate = 44100;
amc.framesPerField = NUM_FIELDS;
amc.maxACMDSize = MAX_RSP_CMDS;
amCreateAudioMgr(&c, AUDIO_PRIORITY, &amc);
/* create the test player */
p = (TTestPlayer *) alHeapAlloc(&gHeapRec, 1 , sizeof(TTestPlayer));
playerNew(p, MAX_VOICES, bank);
}
static void StopTest (u32 subTestNum)
{
playerDelete(p);
amDestroyAM();
}
static void ButtonProc(u16 oldButtons,u16 newButtons)
{
u16 button;
button = oldButtons^newButtons; /* get the ones that have changed */
button &= newButtons; /* get only button downs */
/* CONT_A and CONT_B controls only affect _voiceHander2 */
if (button & CONT_A)
doStop = TRUE;
if (button & CONT_B)
doStart = TRUE;
if (button & CONT_START)
TestDone ();
if (button & CONT_C)
TestPitchLimit ();
}
/***********************************************************************
* Player for this test
***********************************************************************/
static void playerNew(TTestPlayer *p, int numVoices, ALBank *bank)
{
int i;
PRINTF("\tnew player\n");
p->numVoices = numVoices;
p->drvr = &alGlobals->drvr;
/* initialize the state machine */
InitScript0 (&p->script);
/* initialize the wave tables */
p->numWaveTables = 0;
playerSetBank(p, bank);
/* add ourselves to the driver */
p->node.next = NULL;
p->node.handler = _voiceHandler;
p->node.clientData = p;
alSynAddPlayer(p->drvr, &p->node);
}
void
playerDelete(TTestPlayer *p)
{
PRINTF("\tdelete player\n");
alSynRemovePlayer(p->drvr, &p->node);
}
void
playerSetBank(TTestPlayer *p, ALBank *bank)
{
int i, k;
ALInstrument *inst;
ALSound *sound;
for (i = 0; i < bank->instCount; i++)
{
inst = bank->instArray[i];
for (k = 0; k < inst->soundCount; k++)
{
sound = inst->soundArray[k];
p->waves[p->numWaveTables++] = sound->wavetable;
if (p->numWaveTables >= MAX_WAVES)
return;
}
}
}
/*
This script tests stopping and already stopped voice.
This caused a crash in ultra 2.0C and before.
*/
static void
InitScript0 (TScript *pScript)
{
PRINTF("Test stopping an already stopped voice.\n");
PRINTF("Press start to continue when test completes.\n");
pScript->fActionIndex = 0;
pScript->fActionTable = script0;
}
/*
This is the default voice handler.
It simply executes the scripted actions defined
in the player's script.
*/
ALMicroTime
_voiceHandler (void *node)
{
TTestPlayer * p = (TTestPlayer *)node;
TScript * pScript = &p->script;
TScriptAction * pAction;
do
{
pAction = &pScript->fActionTable[pScript->fActionIndex++];
(*(pAction->fActionProc))((TTestPlayerPtr)p);
} while (pAction->fDeltaUsecs == 0);
return pAction->fDeltaUsecs;
}
/*
This is another useful voice handler worth keeping around.
It simply starts and stops voices according to controller
commands.
*/
ALMicroTime
_voiceHandler2 (void *node)
{
TTestPlayer * p = (TTestPlayer *)node;
static char allocated = FALSE;
if (!allocated)
{
allocated = TRUE;
allocVoice (p);
}
if (doStart)
{
startVoice (p);
doStart = FALSE;
}
if (doStop)
{
stopVoice (p);
doStop = FALSE;
}
return 1000;
}
void
nullAction(TTestPlayer *p)
{
PRINTF("\tnull\n");
}
void
done(TTestPlayer *p)
{
PRINTF("\tdone\n");
}
void
allocVoice(TTestPlayer *p)
{
ALVoiceConfig vc;
vc.priority = AL_MAX_PRIORITY; /* voice priority */
vc.fxBus = 0; /* bus assignment */
vc.unityPitch = 0;
PRINTF("\talloc voice\n");
if (alSynAllocVoice(p->drvr, &p->voices[0], &vc) == 0)
PRINTF("\talloc failed\n");
}
void
freeVoice(TTestPlayer *p)
{
PRINTF("\tfree voice\n");
alSynFreeVoice(p->drvr, &p->voices[0]);
}
void
startVoice(TTestPlayer *p)
{
if (!p->numWaveTables)
{
PRINTF("\tcan't start voice\n");
return;
}
PRINTF("\tstart voice\n");
alSynStartVoiceParams(p->drvr, &p->voices[0], p->waves[0], 1.0, 0x7fff, AL_PAN_CENTER, AL_DEFAULT_FXMIX, 0);
}
void
stopVoice(TTestPlayer *p)
{
PRINTF("\tstop voice\n");
alSynStopVoice(p->drvr, &p->voices[0]);
}
static void
TestPitchLimit (void)
{
#define kTinyInt 1
#define kBigInt 0x7fffffff
#define kTinyFloat 1.07549430E-38 /* from /usr/include/float.h */
#define kBigFloat 3.40282347E+38 /* from /usr/include/float.h */
#define kMinFloat kTinyFloat /*(kBigInt * kTinyFloat - kTinyFloat) */
s32 opInt, resultInt;
float opFloat, resultFloat;
opInt = kBigInt;
opFloat = kBigFloat;
PRINTF("big/big:\t%d / %e = ", opInt, opFloat);
resultFloat = opInt/opFloat;
resultInt = resultFloat;
PRINTF("%e, %d\n\n", resultFloat, resultInt);
opInt = kTinyInt;
opFloat = kBigFloat;
PRINTF("tiny/big:\t%d / %e = ", opInt, opFloat);
resultFloat = opInt/opFloat;
resultInt = resultFloat;
PRINTF("%e, %d\n\n", resultFloat, resultInt);
opInt = kTinyInt;
opFloat = kMinFloat;
/*PRINTF("tiny/tiny:\t%d / %e = ", opInt, opFloat);*/
PRINTF("tiny/tiny: ");
resultFloat = opInt/opFloat;
resultInt = resultFloat;
/*PRINTF("%e, %d\n\n", resultFloat, resultInt);*/
/* PRINTF("%d\n\n", resultInt); */
opInt = kBigInt;
opFloat = kMinFloat;
/*PRINTF("big/tiny:\t%d / %e = ", opInt, opFloat); */
PRINTF("big/tiny: ");
resultFloat = opInt/opFloat;
resultInt = resultFloat;
/*PRINTF("%e, %d\n\n", resultFloat, resultInt);*/
/*PRINTF("%d\n\n", resultInt);*/
}