seqptest.c
6.67 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
/* sequence player test */
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <libaudio.h>
#define MAX_VOICES 16
#define MAX_UPDATES 128
#define EVT_COUNT 32
#define FRAME_SIZE 160
#define FX_BUFFER_SIZE 8192
#define AUDIO_HEAP_SIZE (16384 + 2*AL_FX_BUFFER_SIZE)
void meminit(char *ptr, int len);
ALGlobals g;
ALSynConfig c;
ALSeqpConfig seqc;
ALSeqPlayer sequencePlayer;
ALSeq sequence;
Acmd cmdList[10*1024];
short outBuf[2048];
ALSound sound;
short fxBuf[8192];
char audioHeap[AUDIO_HEAP_SIZE];
ALEventListItem evtList[EVT_COUNT];
ALVoiceState voiceList[MAX_VOICES];
static char usage[] = "-verbose <filename>";
/* ###
* ### hack from file virtual.c
*/
#define K0_TO_PHYS(x) ((unsigned)(x)&0x1FFFFFFF) /* kseg0 to physical */
unsigned int
osVirtualToPhysical(void *virtualAddress)
{
return(K0_TO_PHYS(virtualAddress));
}
int dmaCallBack(int addr, int len)
{
return addr;
}
main(int argc, char **argv)
{
ALSeqPlayer *seqp = &sequencePlayer;
ALSeq *seq = &sequence;
ALSound *snd = &sound;
ALHeap hp;
int ch;
extern char *optarg;
extern int optind;
int errflg=0;
char *ifile;
int verbose;
int len;
char *ptr;
FILE *seqfile;
int rv;
int done=0;
int count;
char *ofile=0;
FILE *cmdfile;
int frameCount=0;
FILE *wavefile;
int theTempo = 0;
char *wfile = "tst.tbl";
int wavelen;
char *waveptr;
FILE *bankfile;
char *bfile = "tst.bnk";
int banklen;
char *bankptr;
ALBank *bank=0;
ALBankFile *bnkf=0;
int heapSize;
meminit((char *)&g, sizeof(ALGlobals));
meminit((char *)&c, sizeof(ALSynConfig));
meminit((char *)&sequencePlayer, sizeof(sequencePlayer));
meminit((char *)&sequence, sizeof(sequence));
meminit((char *)&sound, sizeof(sound));
meminit((char *)&fxBuf, sizeof(fxBuf));
/*************************************************************
* parse the command line arguments
*************************************************************/
while ((ch = getopt(argc, argv, "vt:o:")) != EOF) {
switch (ch) {
case 'v':
verbose = 1;
break;
case 'o':
ofile = optarg;
break;
case 't':
theTempo = atoi(optarg);
break;
case '?':
errflg++;
break;
}
}
if (errflg || optind == argc) {
(void)fprintf(stderr, "%s %s\n", argv[0], usage);
exit (2);
}
ifile = argv[optind++];
if (optind != argc) {
fprintf(stderr, "warning: only first file (%s) used, rest ignored\n",
ifile);
}
/*************************************************************
* open the output file
*************************************************************/
if (ofile) {
cmdfile = fopen(ofile, "w");
if (!cmdfile) {
printf("Can't open command file\n");
exit(1);
}
}
/*************************************************************
* load the sequence
*************************************************************/
seqfile = fopen(ifile, "r");
if (!seqfile) {
printf("Can't open sequence file\n");
exit(1);
}
fseek(seqfile, 0, SEEK_END);
len = ftell(seqfile);
rewind(seqfile);
ptr = malloc(len);
if (!ptr) {
printf("Can't allocate memory for sequence\n");
exit(1);
}
rv = fread(ptr, sizeof(char), len, seqfile);
if (rv != len) {
printf("Can't read sequence file, len = %d\n",len);
exit(1);
}
/*************************************************************
* load the wavetable
*************************************************************/
wavefile = fopen(wfile, "r");
if (!wavefile) {
printf("Can't open sound file\n");
exit(1);
}
fseek(wavefile, 0, SEEK_END);
wavelen = ftell(wavefile);
rewind(wavefile);
waveptr = malloc(wavelen);
if (!waveptr) {
printf("Can't allocate memory for wave table\n");
exit(1);
}
rv = fread(waveptr, sizeof(char), wavelen, wavefile);
if (rv != wavelen) {
printf("Can't read sound file, len = %d\n",wavelen);
exit(1);
}
/*************************************************************
* load the bank
*************************************************************/
bankfile = fopen(bfile, "r");
if (!bankfile) {
printf("Can't open sound file\n");
exit(1);
}
fseek(bankfile, 0, SEEK_END);
banklen = ftell(bankfile);
rewind(bankfile);
bankptr = malloc(banklen);
if (!bankptr) {
printf("Can't allocate memory for sound\n");
exit(1);
}
rv = fread(bankptr, sizeof(char), banklen, bankfile);
if (rv != banklen) {
printf("Can't read bank file, len = %d\n",banklen);
exit(1);
}
/*************************************************************
* initialize the Audio Library
*************************************************************/
alHeapInit(&hp, audioHeap, AUDIO_HEAP_SIZE);
c.maxVVoices = MAX_VOICES;
c.maxPVoices = MAX_VOICES;
c.maxUpdates = MAX_UPDATES;
c.dmaproc = &dmaCallBack;
c.heap = &hp;
c.fxSize = FX_BUFFER_SIZE;
c.ratio = 1.0;
c.outputRate = 44100;
alInit(&g, &c);
seqc.maxVoices = MAX_VOICES;
seqc.maxEvents = EVT_COUNT;
seqc.maxChannels = 16;
seqc.heap = &hp;
alSeqpNew(seqp, &seqc);
alSeqNew(seq, ptr, len);
alSeqpSetSeq(seqp, seq);
alBnkfNew((ALBankFile *)bankptr, waveptr);
bank = ((ALBankFile *)bankptr)->bankArray[0];
alSeqpSetBank(seqp, bank);
if (theTempo){
printf("The default tempo was: %d\n",seqp->uspt);
alSeqpSetTempo(seqp, theTempo);
}
alSeqpPlay(seqp);
while (seqp->state == AL_PLAYING) {
alAudioFrame(cmdList, &count, outBuf, FRAME_SIZE);
frameCount++;
if (ofile)
fwrite(cmdList, sizeof(Acmd), count, cmdfile);
}
printf("total frames = %d\n", frameCount);
alSeqpStop(seqp);
alSeqpStop(seqp);
alClose(&g);
if (ofile) {
fflush(cmdfile);
fclose(cmdfile);
}
}
void meminit(char *ptr, int len)
{
int i;
for (i = 0; i < len; i++){
*ptr++ = 0x5a;
}
}