seqpActions.c
8.85 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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/*====================================================================
* seqpActions.c
*
* Synopsis:
*
* Player for testing of driver functions
*
* 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 <libaudio.h>
#include <assert.h>
#include "audiotest.h" /* romCopy */
#include "audio.h"
#include "seqpActions.h"
#include "UniversalSP.h"
#define MIN_TIME 0
#define MAX_TIME 10000
#define MAX_INT 0x7fffffff
#define MAX_SHORT 0x7fff
#define VERBOSE 1
#if VERBOSE
#define MaybePRINTF PRINTF
#else
#define MaybePRINTF NULL
#endif
extern ALHeap gHeapRec;
extern ALBankFile * gBankFile;
extern ALSeqFile * gSeqFile;
extern ALUSPlayer * gSeqp;
extern ALUSeq * gSeq;
extern u8 * gSeqData;
static char sHasBank;
static void __GetRandomSeq (ALUSeq **ppSeq);
static void __GetRandomBank (ALBank **ppBank);
static s32 __GetNumVoices (void);
char
actNull (void)
{
MaybePRINTF("\tnull\n");
return TRUE;
}
char
actDone (void)
{
MaybePRINTF("\tdone\n");
return TRUE;
}
char
actSeqpNew (void)
{
ALSeqpConfig seqc;
MaybePRINTF("\tnew seqp\n");
seqc.maxVoices = MAX_SEQP_VOICES;
seqc.maxEvents = MAX_SEQP_EVENTS;
seqc.maxChannels = 16;
seqc.heap = &gHeapRec;
seqc.initOsc = 0;
seqc.updateOsc = 0;
seqc.stopOsc = 0;
#ifdef _DEBUG
seqc.debugFlags = NO_VOICE_ERR_MASK |NOTE_OFF_ERR_MASK | NO_SOUND_ERR_MASK;
#endif
alUSPNew(gSeqp, &seqc);
sHasBank = FALSE;
return TRUE;
}
char
actSeqpDelete (void)
{
MaybePRINTF("\tdelete seqp\n");
alUSPDelete (gSeqp);
return TRUE;
}
char
actSeqpSetNonNULLSeq (void)
{
ALUSeq * pSeq;
MaybePRINTF("\tset seq\n");
__GetRandomSeq (&pSeq); /* This may set pSeq to be a NULL sequence. */
alUSPSetSeq (gSeqp, pSeq);
return TRUE;
}
char
actSeqpSetMaybeNULLSeq (void)
{
ALUSeq * pSeq;
MaybePRINTF("\tset seq\n");
if (GetRandomNumber (0, 4))
__GetRandomSeq (&pSeq);
else
pSeq = NULL;
alUSPSetSeq (gSeqp, pSeq);
return TRUE;
}
char
actSeqpGetSeq (void)
{
ALUSeq * pSeq;
MaybePRINTF("\tget seq\n");
pSeq = alUSPGetSeq (gSeqp);
return TRUE;
}
char
actSeqpSetBank (void)
{
ALBank * pBank;
if (alUSPGetState (gSeqp) == AL_STOPPED)
{
MaybePRINTF("\tset bank\n");
__GetRandomBank (&pBank);
alUSPSetBank (gSeqp, pBank);
sHasBank = TRUE;
}
else
MaybePRINTF("\tcan't set bank\n");
return TRUE;
}
char
actSeqpPlay (void)
{
if (sHasBank)
{
MaybePRINTF("\tplay:%d\n", __GetNumVoices ());
#ifndef COMP_SEQ_PLAY
if (gSeq->curPtr - gSeq->base >= gSeq->len)
MaybePRINTF("\tEND OF SEQUENCE\n");
#endif
alUSPPlay (gSeqp);
return TRUE;
}
else
{
MaybePRINTF("\tcan't play\n");
return FALSE;
}
}
char
actSeqpStop (void)
{
MaybePRINTF("\tstop\n");
alUSPStop (gSeqp);
return TRUE;
}
char
actSeqpGetState (void)
{
s32 state = alUSPGetState (gSeqp);
MaybePRINTF("\tget state:%s\n",
state == AL_STOPPED ? "AL_STOPPED" :
state == AL_PLAYING ? "AL_PLAYING" : "AL_STOPPING");
return TRUE;
}
char
actSeqpSetTempo (void)
{
s32 tempo = GetRandomNumber (500000-200000, 500000+100000);
alUSPSetTempo (gSeqp, tempo);
MaybePRINTF("\tset tempo: 0x%0x\n", tempo);
return TRUE;
}
char
actSeqpGetTempo (void)
{
s32 tempo;
tempo = alUSPGetTempo (gSeqp);
MaybePRINTF("\tget tempo: 0x%0x\n", tempo);
return TRUE;
}
char
actSeqpSetPriority (void)
{
u8 chan = GetRandomNumber (1, 16);
u8 priority = GetRandomNumber (0, 127);
alUSPSetChlPriority (gSeqp, chan, priority);
MaybePRINTF("\tset chl priority: %d %d\n", chan, priority);
return TRUE;
}
char
actSeqpGetPriority (void)
{
u8 chan = GetRandomNumber (1, 16);
u8 priority;
priority = alUSPGetChlPriority (gSeqp, chan);
MaybePRINTF("\tget chl priority: %d %d\n", chan, priority);
return TRUE;
}
char
actSeqpSetProgram (void)
{
u8 chan = GetRandomNumber (1, 16);
u8 program = GetRandomNumber (0, 127);
if (sHasBank)
{
alUSPSetChlProgram (gSeqp, chan, program);
MaybePRINTF("\tset chl program: %d %d\n", chan, program);
}
return TRUE;
}
char
actSeqpGetProgram (void)
{
u8 chan = GetRandomNumber (1, 16);
u8 program;
program = alUSPGetChlProgram (gSeqp, chan);
MaybePRINTF("\tget chl program: %d %d\n", chan, program);
return TRUE;
}
char
actSeqpSetFXMix (void)
{
u8 chan = GetRandomNumber (1, 16);
u8 fxmix = GetRandomNumber (0, 127);
alUSPSetChlFXMix (gSeqp, chan, fxmix);
MaybePRINTF("\tset chl fxmix: %d %d\n", chan, fxmix);
return TRUE;
}
char
actSeqpGetFXMix (void)
{
u8 chan = GetRandomNumber (1, 16);
u8 fxmix;
fxmix = alUSPGetChlFXMix (gSeqp, chan);
MaybePRINTF("\tget chl fxmix: %d %d\n", chan, fxmix);
return TRUE;
}
char
actSeqpSetChlVol (void)
{
u8 chan = GetRandomNumber (1, 16);
u8 vol = GetRandomNumber (0, 127);
alUSPSetChlVol (gSeqp, chan, vol);
MaybePRINTF("\tset chl vol: %d %d\n", chan, vol);
return TRUE;
}
char
actSeqpGetChlVol (void)
{
u8 chan = GetRandomNumber (1, 16);
u8 vol;
vol = alUSPGetChlVol (gSeqp, chan);
MaybePRINTF("\tget chl vol: %d %d\n", chan, vol);
return TRUE;
}
char
actSeqpSetPan (void)
{
u8 chan = GetRandomNumber (1, 16);
ALPan pan = GetRandomNumber (0, 127);
alUSPSetChlPan (gSeqp, chan, pan);
MaybePRINTF("\tset chl pan: %d %d\n", chan, pan);
return TRUE;
}
char
actSeqpGetPan (void)
{
u8 chan = GetRandomNumber (1, 16);
ALPan pan;
pan = alUSPGetChlPan (gSeqp, chan);
MaybePRINTF("\tget chl pan: %d %d\n", chan, pan);
return TRUE;
}
char
actSeqpSetVol (void)
{
s16 vol = GetRandomNumber (0, MAX_SHORT);
alUSPSetVol (gSeqp, vol);
MaybePRINTF("\tset vol: %x\n", vol);
return TRUE;
}
char
actSeqpGetVol (void)
{
s16 vol;
vol = alUSPGetVol (gSeqp);
MaybePRINTF("\tget vol: %x\n", vol);
return TRUE;
}
char
actSeqpSendMidi (void)
{
MaybePRINTF("\tsend midi\n");
return TRUE;
}
char
actSeqpSetLoop (void)
{
MaybePRINTF("\tloop not tested!\n");
return TRUE;
}
char
actSeqRTZ (void)
{
ALUSMarker marker;
alUSNewMarker (gSeq, &marker, 0);
alUSSetLoc (gSeq, &marker);
MaybePRINTF("\trtz\n");
return TRUE;
}
char
actSeqEOS (void)
{
ALUSMarker marker;
alUSNewMarker (gSeq, &marker, 0x7fffffff);
alUSSetLoc (gSeq, &marker);
MaybePRINTF("\teos\n");
return TRUE;
}
static u8 noteChan;
static u8 noteKey;
char
actSeqpSendNoteOn (void)
{
u8 vel = GetRandomNumber (32, 127);
noteChan = GetRandomNumber (1, 16);
noteKey = GetRandomNumber (20, 80);
alUSPSendMidi(gSeqp, 0, AL_MIDI_NoteOn | noteChan, noteKey, vel);
return TRUE;
}
char
actSeqpSendNoteOff (void)
{
alUSPSendMidi(gSeqp, 0, AL_MIDI_NoteOff | noteChan, noteKey, 0);
return TRUE;
}
/*
*
* Random Number Helper Routines
*
*/
int
GetRandomNumber (int min, int max)
{
float frand, fmin, fmax;
static long seed = 1;
seed = seed * 1103515245 + 12345;
frand = (float)(seed & MAX_INT)/(float)MAX_INT; /* assume int = long */
fmin = (float)min;
fmax = (float)max;
frand = frand * (max - min) + min;
return (int)(frand + 0.5);
}
/*
Initializes 'seq' with a random sequence.
Assumes that gSeqFile and gSeqData have been fully initialized!
*/
void
__GetRandomSeq (ALUSeq **ppSeq)
{
int seqNum;
s32 len;
u8 *romData;
seqNum = GetRandomNumber (0, gSeqFile->seqCount-1);
romData = gSeqFile->seqArray[seqNum].offset;
len = gSeqFile->seqArray[seqNum].len;
if (len & 0x1)
len++;
if (len > MAX_SEQ_LENGTH)
PRINTF("\tsequence %d too big!!!\n", seqNum);
romCopy (romData, gSeqData, len);
alUSNew (gSeq, gSeqData, len);
*ppSeq = gSeq;
}
void
__GetRandomBank (ALBank **ppBank)
{
int bankNum = GetRandomNumber (0, gBankFile->bankCount-1);
*ppBank = gBankFile->bankArray[bankNum];
}
s32
__GetNumVoices (void)
{
ALVoiceState *vs;
s32 vCount = 0;
for (vs = gSeqp->vAllocHead; vs != 0; vs = vs->next)
vCount++;
return vCount;
}