-
Notifications
You must be signed in to change notification settings - Fork 0
/
I_SOUND.C
408 lines (347 loc) · 8.62 KB
/
I_SOUND.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
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
#include <stdio.h>
#include <stdlib.h>
#include "doomdef.h"
#include "dmx.h"
#include "sounds.h"
#include "i_sound.h"
#include "i_system.h"
#include "GUS.H" /* FS: For internal HT_GUS1M.WAD */
boolean hasGUS = false; /* FS */
/* FS: Use internal GUS1M WAD */
extern int useIntGus;
extern char *htgus;
int tsm_ID = -1;
void I_StartupTimer (void)
{
#ifndef NOTIMER
extern int I_TimerISR(void);
tprintf("I_StartupTimer()\n", 0);
/* installs master timer. Must be done before StartupTimer()! */
TSM_Install(SND_TICRATE);
tsm_ID = TSM_NewService (I_TimerISR, 35, 255, 0); /* max priority */
if (tsm_ID == -1)
{
I_Error("Can't register 35 Hz timer w/ DMX library");
}
#endif
}
void I_ShutdownTimer (void)
{
TSM_DelService(tsm_ID);
TSM_Remove();
}
/* sound information */
#if 0
const char *dnames[] = { "None",
"PC_Speaker",
"Adlib",
"Sound_Blaster",
"ProAudio_Spectrum16",
"Gravis_Ultrasound",
"MPU",
"AWE32"
};
#endif
const char snd_prefixen[] = { 'P', 'P', 'A', 'S', 'S', 'S', 'M', 'M', 'M', 'S' };
int snd_Channels;
int snd_DesiredMusicDevice, snd_DesiredSfxDevice;
int snd_MusicDevice, /* current music card # (index to dmxCodes) */
snd_SfxDevice, /* current sfx card # (index to dmxCodes) */
snd_MaxVolume, /* maximum volume for sound */
snd_MusicVolume; /* maximum volume for music */
int dmxCodes[NUM_SCARDS]; /* the dmx code for a given card */
int snd_SBport, snd_SBirq, snd_SBdma; /* sound blaster variables */
int snd_Mport; /* midi variables */
extern boolean snd_MusicAvail, /* whether music is available */
snd_SfxAvail; /* whether sfx are available */
void I_PauseSong (int handle)
{
MUS_PauseSong(handle);
}
void I_ResumeSong (int handle)
{
MUS_ResumeSong(handle);
}
void I_SetMusicVolume (int volume)
{
MUS_SetMasterVolume(volume * 8);
// snd_MusicVolume = volume;
}
void I_SetSfxVolume (int volume)
{
snd_MaxVolume = volume; /* THROW AWAY? */
}
int I_RegisterSong (void *data)
{
int rc = MUS_RegisterSong(data);
#ifdef SNDDEBUG
if (rc < 0)
printf("MUS_Reg() returned %d\n", rc);
#endif
return rc;
}
void I_UnRegisterSong (int handle)
{
int rc = MUS_UnregisterSong(handle);
#ifdef SNDDEBUG
if (rc < 0)
printf("MUS_Unreg() returned %d\n", rc);
#endif
}
int I_QrySongPlaying (int handle)
{
int rc = MUS_QrySongPlaying(handle);
#ifdef SNDDEBUG
if (rc < 0)
printf("MUS_QrySP() returned %d\n", rc);
#endif
return rc;
}
void I_StopSong (int handle) /* MUST be called before I_UnregisterSong(). */
{
int rc, s;
extern volatile int ticcount;
rc = MUS_StopSong(handle);
#ifdef SNDDEBUG
if (rc < 0)
printf("MUS_StopSong() returned %d\n", rc);
#endif
/* Fucking kluge pause */
for (s = ticcount; ticcount - s < 10; );
}
void I_PlaySong (int handle, boolean looping)
{
int rc;
rc = MUS_ChainSong(handle, looping ? handle : -1);
#ifdef SNDDEBUG
if (rc < 0)
printf("MUS_ChainSong() returned %d\n", rc);
#endif
rc = MUS_PlaySong(handle, snd_MusicVolume);
#ifdef SNDDEBUG
if (rc < 0)
printf("MUS_PlaySong() returned %d\n", rc);
#endif
}
/* Gets lump nums of the named sound. Returns pointer which will be
* passed to I_StartSound() when you want to start an SFX. Must be
* sure to pass this to UngetSoundEffect() so that they can be
* freed!
*/
int I_GetSfxLumpNum (sfxinfo_t *sound)
{
char namebuf[9];
if (sound->name == 0)
return 0;
if (sound->link)
sound = sound->link;
return W_GetNumForName(sound->name);
}
int I_StartSound (int id, void *data, int vol, int sep, int pitch, int priority)
{
return SFX_PlayPatch(data, pitch, sep, vol, 0, 0);
}
void I_StopSound (int handle)
{
SFX_StopPatch(handle);
}
int I_SoundIsPlaying (int handle)
{
return SFX_Playing(handle);
}
void I_UpdateSoundParams (int handle, int vol, int sep, int pitch)
{
SFX_SetOrigin(handle, pitch, sep, vol);
}
/* Why PC's Suck, Reason #8712 */
void I_sndArbitrateCards (void)
{
char tmp[160];
boolean gus, adlib, pc, sb, midi;
int i, rc, mputype, p, opltype, wait, dmxlump, retval;
// snd_MaxVolume = 127;
// Damn you, Dave Taylor!
snd_MusicDevice = snd_DesiredMusicDevice;
snd_SfxDevice = snd_DesiredSfxDevice;
/* check command-line parameters- overrides config file */
if (M_CheckParm("-nosound"))
snd_MusicDevice = snd_SfxDevice = snd_none;
if (M_CheckParm("-nosfx"))
snd_SfxDevice = snd_none;
if (M_CheckParm("-nomusic"))
snd_MusicDevice = snd_none;
if (M_CheckParm("-usesb")) /* FS: Force SB if you're using a GUS combo */
{
snd_MusicDevice = snd_SfxDevice = snd_SB;
snd_SBport = 0x220;
snd_SBirq = 5;
snd_SBdma = 1;
printf(" Forcing SB detection at A%03xh I%d D%d.\n", snd_SBport, snd_SBirq, snd_SBdma);
}
if (snd_MusicDevice > snd_MPU && snd_MusicDevice <= snd_MPU3)
snd_MusicDevice = snd_MPU;
if (snd_MusicDevice == snd_SB)
snd_MusicDevice = snd_Adlib;
if (snd_MusicDevice == snd_PAS)
snd_MusicDevice = snd_Adlib;
/* figure out what i've got to initialize */
gus = snd_MusicDevice == snd_GUS || snd_SfxDevice == snd_GUS;
sb = snd_SfxDevice == snd_SB || snd_MusicDevice == snd_SB;
adlib = snd_MusicDevice == snd_Adlib;
pc = snd_SfxDevice == snd_PC;
midi = snd_MusicDevice == snd_MPU;
/* initialize whatever i've got */
if (gus)
{
byte *gusbuffer; /* FS: Use an external GUS ini file */
int gusfilelength, p;
retval = GF1_Detect();
if (retval)
{
sprintf(tmp, "Dude. The GUS ain't responding retval=%d.\n", retval);
tprintf(tmp, 1);
}
else
{
hasGUS = true;
tprintf("SB_Init: Loading GUS patches.\n", 1);
hgotoxy(17, 9);
hprintf("Loading GUS patches.", 0x3f);
p = M_CheckParm("-usegusini"); /* FS: Use an external GUS ini file */
if (p)
{
if (p < myargc - 1)
{
char *gusfile = myargv[p + 1];
gusfilelength = M_ReadFile(gusfile, &gusbuffer);
GF1_SetMap((char *)gusbuffer, gusfilelength);
Z_Free(gusbuffer);
}
else
{
I_ShutdownKeyboard();
printf("ERROR: No external GUS file specified! Use -usegusini <filename.ini>.\n");
exit(1);
}
}
else
{
if (M_CheckParm("-gus") || useIntGus)
{
int length = strlen(htgus);
tprintf(" using internal HT_GUS1M.WAD\n", 1);
GF1_SetMap(htgus, length);
}
else
{
dmxlump = W_GetNumForName("dmxgus");
GF1_SetMap(W_CacheLumpNum(dmxlump, PU_CACHE), lumpinfo[dmxlump].size);
}
}
}
}
if (sb)
{
if (debugmode)
{
sprintf(tmp, "cfg p=%03xh, i=%d, d=%d\n", snd_SBport, snd_SBirq, snd_SBdma);
tprintf(tmp, 0);
}
retval = SB_Detect(&snd_SBport, &snd_SBirq, &snd_SBdma, 0);
if (retval)
{
sprintf(tmp, "SB isn't responding at p=%03xh, i=%d, d=%d, retval=%d\n", snd_SBport, snd_SBirq, snd_SBdma, retval);
tprintf(tmp, 0);
}
else
{
SB_SetCard(snd_SBport, snd_SBirq, snd_SBdma);
}
if (debugmode)
{
sprintf(tmp, "SB_Detect returned p=%03xh,i=%d,d=%d,retval=%d\n", snd_SBport, snd_SBirq, snd_SBdma, retval);
tprintf(tmp, 0);
}
}
if (adlib)
{
retval = AL_Detect(&wait, 0);
if (retval)
{
sprintf(tmp, "Dude. The Adlib isn't responding retval=%d.\n", retval);
tprintf(tmp, 1);
}
else
{
AL_SetCard(wait, W_CacheLumpName("genmidi", PU_STATIC));
}
}
if (midi)
{
if (debugmode)
{
sprintf(tmp, "cfg p=%03xh\n", snd_Mport);
tprintf(tmp, 0);
}
retval = MPU_Detect(&snd_Mport, &i);
if (retval)
{
sprintf(tmp, "The MPU-401 isn't reponding @ p=%03xh, retval=%d.\n", snd_Mport, retval);
tprintf(tmp, 0);
}
else
{
MPU_SetCard(snd_Mport);
}
}
}
void I_StartupSound (void)
{
char tmp[80];
int rc, i;
if (debugmode)
tprintf("I_StartupSound: Hope you hear a pop.\n", 1);
dmxCodes[0] = 0;
dmxCodes[snd_PC] = AHW_PC_SPEAKER;
dmxCodes[snd_Adlib] = AHW_ADLIB;
dmxCodes[snd_SB] = AHW_SOUND_BLASTER;
dmxCodes[snd_PAS] = AHW_MEDIA_VISION;
dmxCodes[snd_GUS] = AHW_ULTRA_SOUND;
dmxCodes[snd_MPU] = AHW_MPU_401;
dmxCodes[snd_AWE] = AHW_AWE32;
/* inits sound library timer stuff */
I_StartupTimer();
/* pick the sound cards i'm going to use */
I_sndArbitrateCards();
if (debugmode)
{
sprintf(tmp, " Music device #%d & dmxCode=%d\n", snd_MusicDevice, dmxCodes[snd_MusicDevice]);
tprintf(tmp, 0);
sprintf(tmp, " Sfx device #%d & dmxCode=%d\n", snd_SfxDevice, dmxCodes[snd_SfxDevice]);
tprintf(tmp, 0);
}
tprintf(" calling DMX_Init\n", 0);
rc = DMX_Init(SND_TICRATE, SND_MAXSONGS, dmxCodes[snd_MusicDevice],
dmxCodes[snd_SfxDevice]);
if (debugmode)
{
sprintf(tmp, " DMX_Init() returned %d\n", rc);
tprintf(tmp, 0);
}
}
void I_ShutdownSound (void)
{
DMX_DeInit();
I_ShutdownTimer();
}
void I_SetChannels (int channels)
{
if (M_CheckParm("-s8"))
WAV_PlayMode(channels, 8000);
else if (M_CheckParm("-s11"))
WAV_PlayMode(channels, 11025);
else if (M_CheckParm("-s22"))
WAV_PlayMode(channels, 22050);
else
WAV_PlayMode(channels, SND_SAMPLERATE);
}