forked from Tronix286/AIL2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTPLAY.C
269 lines (229 loc) · 8.89 KB
/
STPLAY.C
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
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
//ÛÛ ÛÛ
//ÛÛ STPLAY.C ÛÛ
//ÛÛ ÛÛ
//ÛÛ Creative Voice File (.VOC) stereo performance ÛÛ
//ÛÛ utility with dual-buffer playback ÛÛ
//ÛÛ ÛÛ
//ÛÛ V2.00 of 09-Oct-91 ÛÛ
//ÛÛ V2.01 of 14-Dec-91: Pause/resume added ÛÛ
//ÛÛ V2.02 of 09-Apr-92: Buffer preformatting added ÛÛ
//ÛÛ ÛÛ
//ÛÛ Project: IBM Audio Interface Library ÛÛ
//ÛÛ Author: John Miles ÛÛ
//ÛÛ ÛÛ
//ÛÛ C source compatible with Turbo C++ v1.0 or later ÛÛ
//ÛÛ ÛÛ
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
//ÛÛ ÛÛ
//ÛÛ stplay.obj: stplay.c gen.h ail.h ÛÛ
//ÛÛ bcc -ml -c -v stplay.c ÛÛ
//ÛÛ ÛÛ
//ÛÛ stplay.exe: stplay.obj gen.lib ail.obj ÛÛ
//ÛÛ tlink @stplay.lls ÛÛ
//ÛÛ ÛÛ
//ÛÛ Contents of STPLAY.LLS: ÛÛ
//ÛÛ /c /v /x + ÛÛ
//ÛÛ \bc\lib\c0l.obj + ÛÛ
//ÛÛ stplay ail, + ÛÛ
//ÛÛ stplay.exe, + ÛÛ
//ÛÛ stplay.map, + ÛÛ
//ÛÛ \bc\lib\cl.lib gen.lib ÛÛ
//ÛÛ ÛÛ
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
//ÛÛ ÛÛ
//ÛÛ Copyright (C) 1991, 1992 Miles Design, Inc. ÛÛ
//ÛÛ ÛÛ
//ÛÛ Miles Design, Inc. ÛÛ
//ÛÛ 10926 Jollyville #308 ÛÛ
//ÛÛ Austin, TX 78759 ÛÛ
//ÛÛ (512) 345-2642 / FAX (512) 338-9630 / BBS (512) 454-9990 ÛÛ
//ÛÛ ÛÛ
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <alloc.h>
#include <io.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include "ail.h" // Audio Interface Library API header file
#include "gen.h" // General DOS and system functions
const char VERSION[] = "2.01";
char far buf1[16384], far buf2[16384];
/*****************************************************************/
void main(int argc, char *argv[])
{
HDRIVER hdriver;
FILE *vfile;
char far *drvr;
drvr_desc far *desc;
sound_buff firstblock,tempblock;
int i,done,bufnum,paused;
printf("\nSTPLAY version %s Copyright (C) 1991, 1992 Miles Design, Inc.\n",VERSION);
printf("-------------------------------------------------------------------------------\n\n");
if (argc != 3)
{
printf("This program plays a raw 8-bit stereo sample at 22 kHz\n");
printf("through any Audio Interface Library digital stereo driver.\n\n");
printf("Usage: STPLAY ST_filename driver_filename\n");
exit(1);
}
AIL_startup();
//
// Load, install, describe, and initialize the Sound Blaster-
// compatible driver
//
drvr = load_driver(argv[2]);
if (drvr == NULL)
{
printf("Couldn't load driver.\n");
AIL_shutdown(NULL);
exit(1);
}
hdriver = AIL_register_driver(drvr);
if (hdriver==-1)
{
printf("Driver %s not compatible with linked API version.\n",
argv[2]);
AIL_shutdown(NULL);
exit(1);
}
desc = AIL_describe_driver(hdriver);
if (desc->drvr_type != DSP_DRVR)
{
printf("%s is not a digital sound driver.\n",argv[2]);
AIL_shutdown(NULL);
exit(1);
}
if (!AIL_detect_device(hdriver,desc->default_IO,desc->default_IRQ,
desc->default_DMA,desc->default_DRQ))
{
printf("Sound hardware not found.\n");
AIL_shutdown(NULL);
exit(1);
}
AIL_init_driver(hdriver,desc->default_IO,desc->default_IRQ,
desc->default_DMA,desc->default_DRQ);
vfile = fopen(argv[1],"rb");
if (vfile == NULL)
{
printf("Couldn't open %s.\n",argv[1]);
AIL_shutdown(NULL);
exit(1);
}
//
// Play the block as a series of double-buffered 16K chunks
//
printf("U D to increase/decrease volume\n");
printf("P R to pause/resume playback\n");
printf("< > to pan left, right\n");
printf("ESC to stop playback\n\n");
//
// Copy sample rate and packing type to working sound buffer
// structure
//
// Sound Blaster standard sample rate: 256-(1000000-freq in Hz.)
//
firstblock.sample_rate = 234; // 22.050 kHz (stereo 44.1 kHz)
firstblock.pack_type = 0 | 0x80; // 8-bit stereo sample
firstblock.len = filelength(fileno(vfile));
bufnum = 0;
tempblock = firstblock;
//
// Sample application main loop ...
//
done = paused = 0;
do
{
//
// (Application-specific events here)
//
if (kbhit())
{
switch (toupper(getch()))
{
case 'P':
AIL_pause_digital_playback(hdriver);
paused = 1;
break;
case 'R':
AIL_resume_digital_playback(hdriver);
paused = 0;
break;
case 'U':
i = AIL_digital_playback_volume(hdriver);
i+=10;
if (i>127) i=127;
AIL_set_digital_playback_volume(hdriver,i);
break;
case 'D':
i = AIL_digital_playback_volume(hdriver);
i-=10;
if (i<0) i=0;
AIL_set_digital_playback_volume(hdriver,i);
break;
case ',':
case '<':
i = AIL_digital_playback_panpot(hdriver);
i+=10;
if (i>127) i=127;
AIL_set_digital_playback_panpot(hdriver,i);
break;
case '.':
case '>':
i = AIL_digital_playback_panpot(hdriver);
i-=10;
if (i<0) i=0;
AIL_set_digital_playback_panpot(hdriver,i);
break;
case 27:
done=1;
break;
}
}
//
// Update sound DMA buffers and ensure sound output is active
//
if (!paused)
{
for (i=0;i<2;i++)
if ((AIL_sound_buffer_status(hdriver,i) == DAC_DONE)
&& firstblock.len)
{
tempblock.len = min(16384L,firstblock.len);
firstblock.len -= tempblock.len;
if (!(bufnum ^= 1))
{
fread(buf1,(unsigned) tempblock.len,1,vfile);
tempblock.data = buf1;
}
else
{
fread(buf2,(unsigned) tempblock.len,1,vfile);
tempblock.data = buf2;
}
AIL_register_sound_buffer(hdriver,i,&tempblock);
AIL_format_sound_buffer(hdriver,&tempblock);
printf(".");
}
AIL_start_digital_playback(hdriver);
}
//
// Playback ends when no bytes are left in the source data and
// the status of both buffers equals DAC_DONE
//
if (!firstblock.len)
if ((AIL_sound_buffer_status(hdriver,0) == DAC_DONE)
&& (AIL_sound_buffer_status(hdriver,1) == DAC_DONE))
done = 1;
}
while (!done);
while (kbhit()) getch();
fclose(vfile);
printf("\n\nSTPLAY stopped.\n");
AIL_shutdown(NULL);
}