annotate playercode/mdriver.c @ 8:b30908f9d9f9

Initial entry of mikmod into the CVS tree.
author darius
date Fri, 23 Jan 1998 16:05:10 +0000
parents 42e11dc15457
children 437e8455d862
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
42e11dc15457 Initial revision
darius
parents:
diff changeset
1 /*
42e11dc15457 Initial revision
darius
parents:
diff changeset
2
42e11dc15457 Initial revision
darius
parents:
diff changeset
3 Name: MDRIVER.C
42e11dc15457 Initial revision
darius
parents:
diff changeset
4
42e11dc15457 Initial revision
darius
parents:
diff changeset
5 Description:
42e11dc15457 Initial revision
darius
parents:
diff changeset
6 These routines are used to access the available soundcard drivers.
42e11dc15457 Initial revision
darius
parents:
diff changeset
7
42e11dc15457 Initial revision
darius
parents:
diff changeset
8 Portability:
42e11dc15457 Initial revision
darius
parents:
diff changeset
9 All systems - all compilers
42e11dc15457 Initial revision
darius
parents:
diff changeset
10
42e11dc15457 Initial revision
darius
parents:
diff changeset
11 */
42e11dc15457 Initial revision
darius
parents:
diff changeset
12
42e11dc15457 Initial revision
darius
parents:
diff changeset
13 #include "mikmod.h"
42e11dc15457 Initial revision
darius
parents:
diff changeset
14
42e11dc15457 Initial revision
darius
parents:
diff changeset
15 MDRIVER *firstdriver = NULL, *md_driver = &drv_nos;
42e11dc15457 Initial revision
darius
parents:
diff changeset
16
42e11dc15457 Initial revision
darius
parents:
diff changeset
17 UWORD md_device = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
18 UWORD md_mixfreq = 44100;
42e11dc15457 Initial revision
darius
parents:
diff changeset
19 UWORD md_mode = DMODE_STEREO | DMODE_16BITS | DMODE_SURROUND;
42e11dc15457 Initial revision
darius
parents:
diff changeset
20 UWORD md_dmabufsize = 50;
42e11dc15457 Initial revision
darius
parents:
diff changeset
21 UBYTE md_pansep = 128; // 128 == 100% (full left/right)
42e11dc15457 Initial revision
darius
parents:
diff changeset
22
42e11dc15457 Initial revision
darius
parents:
diff changeset
23 UBYTE md_reverb = 6; // Reverb
42e11dc15457 Initial revision
darius
parents:
diff changeset
24
42e11dc15457 Initial revision
darius
parents:
diff changeset
25 UBYTE md_volume = 96; // Global sound volume (0-128)
42e11dc15457 Initial revision
darius
parents:
diff changeset
26 UBYTE md_musicvolume = 128; // volume of song
42e11dc15457 Initial revision
darius
parents:
diff changeset
27 UBYTE md_sndfxvolume = 128; // volume of sound effects
42e11dc15457 Initial revision
darius
parents:
diff changeset
28
42e11dc15457 Initial revision
darius
parents:
diff changeset
29 UBYTE md_bpm = 125;
42e11dc15457 Initial revision
darius
parents:
diff changeset
30
42e11dc15457 Initial revision
darius
parents:
diff changeset
31
42e11dc15457 Initial revision
darius
parents:
diff changeset
32 // Do not modify the numchn variables yourself! use MD_SetVoices()
42e11dc15457 Initial revision
darius
parents:
diff changeset
33
42e11dc15457 Initial revision
darius
parents:
diff changeset
34 UBYTE md_numchn = 0, md_sngchn = 0, md_sfxchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
35 UBYTE md_hardchn = 0, md_softchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
36
42e11dc15457 Initial revision
darius
parents:
diff changeset
37
42e11dc15457 Initial revision
darius
parents:
diff changeset
38 void (*md_player)(void) = Player_HandleTick;
42e11dc15457 Initial revision
darius
parents:
diff changeset
39 static BOOL isplaying = 0, initialized = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
40 static UBYTE *sfxinfo;
42e11dc15457 Initial revision
darius
parents:
diff changeset
41 static int sfxpool;
42e11dc15457 Initial revision
darius
parents:
diff changeset
42
42e11dc15457 Initial revision
darius
parents:
diff changeset
43 static SAMPLE **md_sample = NULL;
42e11dc15457 Initial revision
darius
parents:
diff changeset
44
42e11dc15457 Initial revision
darius
parents:
diff changeset
45 // Backup variables. This way, the end programmer can fiddle with the
42e11dc15457 Initial revision
darius
parents:
diff changeset
46 // main globals without mikmod blowing up.
42e11dc15457 Initial revision
darius
parents:
diff changeset
47
42e11dc15457 Initial revision
darius
parents:
diff changeset
48 static UWORD idevice, imixfreq, imode, idmabufsize;
42e11dc15457 Initial revision
darius
parents:
diff changeset
49
42e11dc15457 Initial revision
darius
parents:
diff changeset
50
42e11dc15457 Initial revision
darius
parents:
diff changeset
51 static void LimitHardVoices(int limit)
42e11dc15457 Initial revision
darius
parents:
diff changeset
52
42e11dc15457 Initial revision
darius
parents:
diff changeset
53 // Limits the number of hardware voices to the specified amount.
42e11dc15457 Initial revision
darius
parents:
diff changeset
54 // This function should only be used by the low-level drivers.
42e11dc15457 Initial revision
darius
parents:
diff changeset
55
42e11dc15457 Initial revision
darius
parents:
diff changeset
56 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
57 int t = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
58
42e11dc15457 Initial revision
darius
parents:
diff changeset
59 if(!(md_mode & DMODE_SOFT_SNDFX) && (md_sfxchn > limit)) md_sfxchn = limit;
42e11dc15457 Initial revision
darius
parents:
diff changeset
60 if(!(md_mode & DMODE_SOFT_MUSIC) && (md_sngchn > limit)) md_sngchn = limit;
42e11dc15457 Initial revision
darius
parents:
diff changeset
61
42e11dc15457 Initial revision
darius
parents:
diff changeset
62 if(!(md_mode & DMODE_SOFT_SNDFX))
42e11dc15457 Initial revision
darius
parents:
diff changeset
63 md_hardchn = md_sfxchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
64 else
42e11dc15457 Initial revision
darius
parents:
diff changeset
65 md_hardchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
66
42e11dc15457 Initial revision
darius
parents:
diff changeset
67 if(!(md_mode & DMODE_SOFT_MUSIC))
42e11dc15457 Initial revision
darius
parents:
diff changeset
68 md_hardchn += md_sngchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
69
42e11dc15457 Initial revision
darius
parents:
diff changeset
70 while(md_hardchn > limit)
42e11dc15457 Initial revision
darius
parents:
diff changeset
71 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
72 if(++t & 1)
42e11dc15457 Initial revision
darius
parents:
diff changeset
73 if(!(md_mode & DMODE_SOFT_SNDFX) && (md_sfxchn > 4)) md_sfxchn--;
42e11dc15457 Initial revision
darius
parents:
diff changeset
74 else
42e11dc15457 Initial revision
darius
parents:
diff changeset
75 if(!(md_mode & DMODE_SOFT_MUSIC) && (md_sngchn > 8)) md_sngchn--;
42e11dc15457 Initial revision
darius
parents:
diff changeset
76
42e11dc15457 Initial revision
darius
parents:
diff changeset
77 if(!(md_mode & DMODE_SOFT_SNDFX))
42e11dc15457 Initial revision
darius
parents:
diff changeset
78 md_hardchn = md_sfxchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
79 else
42e11dc15457 Initial revision
darius
parents:
diff changeset
80 md_hardchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
81
42e11dc15457 Initial revision
darius
parents:
diff changeset
82 if(!(md_mode & DMODE_SOFT_MUSIC))
42e11dc15457 Initial revision
darius
parents:
diff changeset
83 md_hardchn += md_sngchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
84 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
85
42e11dc15457 Initial revision
darius
parents:
diff changeset
86 md_numchn = md_hardchn + md_softchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
87 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
88
42e11dc15457 Initial revision
darius
parents:
diff changeset
89
42e11dc15457 Initial revision
darius
parents:
diff changeset
90 static void LimitSoftVoices(int limit)
42e11dc15457 Initial revision
darius
parents:
diff changeset
91
42e11dc15457 Initial revision
darius
parents:
diff changeset
92 // Limits the number of hardware voices to the specified amount.
42e11dc15457 Initial revision
darius
parents:
diff changeset
93 // This function should only be used by the low-level drivers.
42e11dc15457 Initial revision
darius
parents:
diff changeset
94
42e11dc15457 Initial revision
darius
parents:
diff changeset
95 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
96 int t = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
97
42e11dc15457 Initial revision
darius
parents:
diff changeset
98 if((md_mode & DMODE_SOFT_SNDFX) && (md_sfxchn > limit)) md_sfxchn = limit;
42e11dc15457 Initial revision
darius
parents:
diff changeset
99 if((md_mode & DMODE_SOFT_MUSIC) && (md_sngchn > limit)) md_sngchn = limit;
42e11dc15457 Initial revision
darius
parents:
diff changeset
100
42e11dc15457 Initial revision
darius
parents:
diff changeset
101 if(md_mode & DMODE_SOFT_SNDFX)
42e11dc15457 Initial revision
darius
parents:
diff changeset
102 md_softchn = md_sfxchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
103 else
42e11dc15457 Initial revision
darius
parents:
diff changeset
104 md_softchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
105
42e11dc15457 Initial revision
darius
parents:
diff changeset
106 if(md_mode & DMODE_SOFT_MUSIC)
42e11dc15457 Initial revision
darius
parents:
diff changeset
107 md_softchn += md_sngchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
108
42e11dc15457 Initial revision
darius
parents:
diff changeset
109 while(md_softchn > limit)
42e11dc15457 Initial revision
darius
parents:
diff changeset
110 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
111 if(++t & 1)
42e11dc15457 Initial revision
darius
parents:
diff changeset
112 if((md_mode & DMODE_SOFT_SNDFX) && (md_sfxchn > 4)) md_sfxchn--;
42e11dc15457 Initial revision
darius
parents:
diff changeset
113 else
42e11dc15457 Initial revision
darius
parents:
diff changeset
114 if((md_mode & DMODE_SOFT_MUSIC) && (md_sngchn > 8)) md_sngchn--;
42e11dc15457 Initial revision
darius
parents:
diff changeset
115
42e11dc15457 Initial revision
darius
parents:
diff changeset
116 if(!(md_mode & DMODE_SOFT_SNDFX))
42e11dc15457 Initial revision
darius
parents:
diff changeset
117 md_softchn = md_sfxchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
118 else
42e11dc15457 Initial revision
darius
parents:
diff changeset
119 md_softchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
120
42e11dc15457 Initial revision
darius
parents:
diff changeset
121 if(!(md_mode & DMODE_SOFT_MUSIC))
42e11dc15457 Initial revision
darius
parents:
diff changeset
122 md_softchn += md_sngchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
123 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
124
42e11dc15457 Initial revision
darius
parents:
diff changeset
125 md_numchn = md_hardchn + md_softchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
126 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
127
42e11dc15457 Initial revision
darius
parents:
diff changeset
128
42e11dc15457 Initial revision
darius
parents:
diff changeset
129 // Note: 'type' indicates whether the returned value should be for music
42e11dc15457 Initial revision
darius
parents:
diff changeset
130 // or for sound effects.
42e11dc15457 Initial revision
darius
parents:
diff changeset
131
42e11dc15457 Initial revision
darius
parents:
diff changeset
132 ULONG MD_SampleSpace(int type)
42e11dc15457 Initial revision
darius
parents:
diff changeset
133 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
134 if(type==MD_MUSIC)
42e11dc15457 Initial revision
darius
parents:
diff changeset
135 type = (md_mode & DMODE_SOFT_MUSIC) ? MD_SOFTWARE : MD_HARDWARE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
136 else if(type==MD_SNDFX)
42e11dc15457 Initial revision
darius
parents:
diff changeset
137 type = (md_mode & DMODE_SOFT_SNDFX) ? MD_SOFTWARE : MD_HARDWARE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
138
42e11dc15457 Initial revision
darius
parents:
diff changeset
139 return md_driver->FreeSampleSpace(type);
42e11dc15457 Initial revision
darius
parents:
diff changeset
140 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
141
42e11dc15457 Initial revision
darius
parents:
diff changeset
142
42e11dc15457 Initial revision
darius
parents:
diff changeset
143 ULONG MD_SampleLength(int type, SAMPLE *s)
42e11dc15457 Initial revision
darius
parents:
diff changeset
144 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
145 if(type==MD_MUSIC)
42e11dc15457 Initial revision
darius
parents:
diff changeset
146 type = (md_mode & DMODE_SOFT_MUSIC) ? MD_SOFTWARE : MD_HARDWARE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
147 else if(type==MD_SNDFX)
42e11dc15457 Initial revision
darius
parents:
diff changeset
148 type = (md_mode & DMODE_SOFT_SNDFX) ? MD_SOFTWARE : MD_HARDWARE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
149
42e11dc15457 Initial revision
darius
parents:
diff changeset
150 return md_driver->RealSampleLength(type, s);
42e11dc15457 Initial revision
darius
parents:
diff changeset
151 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
152
42e11dc15457 Initial revision
darius
parents:
diff changeset
153
42e11dc15457 Initial revision
darius
parents:
diff changeset
154 UWORD MD_SetDMA(int secs)
42e11dc15457 Initial revision
darius
parents:
diff changeset
155
42e11dc15457 Initial revision
darius
parents:
diff changeset
156 // Converts the given number of 1/10th seconds into the number of bytes of
42e11dc15457 Initial revision
darius
parents:
diff changeset
157 // audio that a sample # 1/10th seconds long would require at the current md_*
42e11dc15457 Initial revision
darius
parents:
diff changeset
158 // settings.
42e11dc15457 Initial revision
darius
parents:
diff changeset
159
42e11dc15457 Initial revision
darius
parents:
diff changeset
160 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
161 ULONG result;
42e11dc15457 Initial revision
darius
parents:
diff changeset
162
42e11dc15457 Initial revision
darius
parents:
diff changeset
163 result = (md_mixfreq * ((md_mode & DMODE_STEREO) ? 2 : 1) *
42e11dc15457 Initial revision
darius
parents:
diff changeset
164 ((md_mode & DMODE_16BITS) ? 2 : 1) * secs) * 10;
42e11dc15457 Initial revision
darius
parents:
diff changeset
165
42e11dc15457 Initial revision
darius
parents:
diff changeset
166 if(result > 32000) result = 32000;
42e11dc15457 Initial revision
darius
parents:
diff changeset
167 return(md_dmabufsize = (result & ~3)); // round it off to an 8 byte boundry
42e11dc15457 Initial revision
darius
parents:
diff changeset
168 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
169
42e11dc15457 Initial revision
darius
parents:
diff changeset
170
42e11dc15457 Initial revision
darius
parents:
diff changeset
171 void MD_InfoDriver(void)
42e11dc15457 Initial revision
darius
parents:
diff changeset
172 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
173 int t;
42e11dc15457 Initial revision
darius
parents:
diff changeset
174 MDRIVER *l;
42e11dc15457 Initial revision
darius
parents:
diff changeset
175
42e11dc15457 Initial revision
darius
parents:
diff changeset
176 // list all registered devicedrivers:
42e11dc15457 Initial revision
darius
parents:
diff changeset
177 for(t=1,l=firstdriver; l!=NULL; l=l->next, t++)
42e11dc15457 Initial revision
darius
parents:
diff changeset
178 printf("%d. %s\n",t,l->Version);
42e11dc15457 Initial revision
darius
parents:
diff changeset
179 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
180
42e11dc15457 Initial revision
darius
parents:
diff changeset
181
42e11dc15457 Initial revision
darius
parents:
diff changeset
182 void MD_RegisterDriver(MDRIVER *drv)
42e11dc15457 Initial revision
darius
parents:
diff changeset
183 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
184 MDRIVER *cruise = firstdriver;
42e11dc15457 Initial revision
darius
parents:
diff changeset
185
42e11dc15457 Initial revision
darius
parents:
diff changeset
186 if(cruise!=NULL)
42e11dc15457 Initial revision
darius
parents:
diff changeset
187 { while(cruise->next!=NULL) cruise = cruise->next;
42e11dc15457 Initial revision
darius
parents:
diff changeset
188 cruise->next = drv;
42e11dc15457 Initial revision
darius
parents:
diff changeset
189 } else
42e11dc15457 Initial revision
darius
parents:
diff changeset
190 firstdriver = drv;
42e11dc15457 Initial revision
darius
parents:
diff changeset
191 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
192
42e11dc15457 Initial revision
darius
parents:
diff changeset
193
42e11dc15457 Initial revision
darius
parents:
diff changeset
194 SWORD MD_SampleLoad(SAMPLOAD *s, int type, FILE *fp)
42e11dc15457 Initial revision
darius
parents:
diff changeset
195 // type - sample type .. MD_MUSIC or MD_SNDFX
42e11dc15457 Initial revision
darius
parents:
diff changeset
196 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
197 SWORD result;
42e11dc15457 Initial revision
darius
parents:
diff changeset
198
42e11dc15457 Initial revision
darius
parents:
diff changeset
199 if(type==MD_MUSIC)
42e11dc15457 Initial revision
darius
parents:
diff changeset
200 type = (md_mode & DMODE_SOFT_MUSIC) ? MD_SOFTWARE : MD_HARDWARE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
201 else if(type==MD_SNDFX)
42e11dc15457 Initial revision
darius
parents:
diff changeset
202 type = (md_mode & DMODE_SOFT_SNDFX) ? MD_SOFTWARE : MD_HARDWARE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
203
42e11dc15457 Initial revision
darius
parents:
diff changeset
204 SL_Init(s);
42e11dc15457 Initial revision
darius
parents:
diff changeset
205 result = md_driver->SampleLoad(s, type, fp);
42e11dc15457 Initial revision
darius
parents:
diff changeset
206 SL_Exit(s);
42e11dc15457 Initial revision
darius
parents:
diff changeset
207
42e11dc15457 Initial revision
darius
parents:
diff changeset
208 return result;
42e11dc15457 Initial revision
darius
parents:
diff changeset
209 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
210
42e11dc15457 Initial revision
darius
parents:
diff changeset
211
42e11dc15457 Initial revision
darius
parents:
diff changeset
212 void MD_SampleUnLoad(SWORD handle)
42e11dc15457 Initial revision
darius
parents:
diff changeset
213 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
214 md_driver->SampleUnLoad(handle);
42e11dc15457 Initial revision
darius
parents:
diff changeset
215 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
216
42e11dc15457 Initial revision
darius
parents:
diff changeset
217
42e11dc15457 Initial revision
darius
parents:
diff changeset
218 void MD_SetBPM(UBYTE bpm)
42e11dc15457 Initial revision
darius
parents:
diff changeset
219 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
220 md_bpm = bpm;
42e11dc15457 Initial revision
darius
parents:
diff changeset
221 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
222
42e11dc15457 Initial revision
darius
parents:
diff changeset
223
42e11dc15457 Initial revision
darius
parents:
diff changeset
224 void MikMod_RegisterPlayer(void (*player)(void))
42e11dc15457 Initial revision
darius
parents:
diff changeset
225 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
226 md_player = player;
42e11dc15457 Initial revision
darius
parents:
diff changeset
227 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
228
42e11dc15457 Initial revision
darius
parents:
diff changeset
229
42e11dc15457 Initial revision
darius
parents:
diff changeset
230 void MikMod_Update(void)
42e11dc15457 Initial revision
darius
parents:
diff changeset
231 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
232 if(isplaying) md_driver->Update();
42e11dc15457 Initial revision
darius
parents:
diff changeset
233 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
234
42e11dc15457 Initial revision
darius
parents:
diff changeset
235
42e11dc15457 Initial revision
darius
parents:
diff changeset
236 void Voice_SetVolume(int voice, UWORD vol)
42e11dc15457 Initial revision
darius
parents:
diff changeset
237 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
238 ULONG tmp;
42e11dc15457 Initial revision
darius
parents:
diff changeset
239
42e11dc15457 Initial revision
darius
parents:
diff changeset
240 if((voice<0) || (voice>=md_numchn)) return;
42e11dc15457 Initial revision
darius
parents:
diff changeset
241 tmp = (ULONG)vol * (ULONG)md_volume * ((voice < md_sngchn) ? (ULONG)md_musicvolume : (ULONG)md_sndfxvolume);
42e11dc15457 Initial revision
darius
parents:
diff changeset
242 md_driver->VoiceSetVolume(voice,tmp/16384UL);
42e11dc15457 Initial revision
darius
parents:
diff changeset
243 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
244
42e11dc15457 Initial revision
darius
parents:
diff changeset
245
42e11dc15457 Initial revision
darius
parents:
diff changeset
246 void Voice_SetFrequency(int voice, ULONG frq)
42e11dc15457 Initial revision
darius
parents:
diff changeset
247 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
248 if((voice < 0) || (voice >= md_numchn)) return;
42e11dc15457 Initial revision
darius
parents:
diff changeset
249 if(md_sample[voice]!=NULL && md_sample[voice]->divfactor!=0) frq/=md_sample[voice]->divfactor;
42e11dc15457 Initial revision
darius
parents:
diff changeset
250 md_driver->VoiceSetFrequency(voice, frq);
42e11dc15457 Initial revision
darius
parents:
diff changeset
251 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
252
42e11dc15457 Initial revision
darius
parents:
diff changeset
253
42e11dc15457 Initial revision
darius
parents:
diff changeset
254 void Voice_SetPanning(int voice, ULONG pan)
42e11dc15457 Initial revision
darius
parents:
diff changeset
255 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
256 if((voice < 0) || (voice >= md_numchn)) return;
42e11dc15457 Initial revision
darius
parents:
diff changeset
257 if(pan!=PAN_SURROUND)
42e11dc15457 Initial revision
darius
parents:
diff changeset
258 { if(md_mode & DMODE_REVERSE) pan = 255-pan;
42e11dc15457 Initial revision
darius
parents:
diff changeset
259 pan = (((SWORD)(pan-128)*md_pansep) / 128)+128;
42e11dc15457 Initial revision
darius
parents:
diff changeset
260 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
261 md_driver->VoiceSetPanning(voice, pan);
42e11dc15457 Initial revision
darius
parents:
diff changeset
262 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
263
42e11dc15457 Initial revision
darius
parents:
diff changeset
264
42e11dc15457 Initial revision
darius
parents:
diff changeset
265 void Voice_Play(int voice, SAMPLE *s, ULONG start)
42e11dc15457 Initial revision
darius
parents:
diff changeset
266 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
267 ULONG repend;
42e11dc15457 Initial revision
darius
parents:
diff changeset
268
42e11dc15457 Initial revision
darius
parents:
diff changeset
269 if((voice < 0) || (voice >= md_numchn) || (start >= s->length)) return;
42e11dc15457 Initial revision
darius
parents:
diff changeset
270
42e11dc15457 Initial revision
darius
parents:
diff changeset
271 md_sample[voice] = s;
42e11dc15457 Initial revision
darius
parents:
diff changeset
272 repend = s->loopend;
42e11dc15457 Initial revision
darius
parents:
diff changeset
273
42e11dc15457 Initial revision
darius
parents:
diff changeset
274 if(s->flags&SF_LOOP)
42e11dc15457 Initial revision
darius
parents:
diff changeset
275 if(repend > s->length) repend = s->length; // repend can't be bigger than size
42e11dc15457 Initial revision
darius
parents:
diff changeset
276
42e11dc15457 Initial revision
darius
parents:
diff changeset
277 md_driver->VoicePlay(voice,s->handle,start,s->length,s->loopstart,repend,s->flags);
42e11dc15457 Initial revision
darius
parents:
diff changeset
278 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
279
42e11dc15457 Initial revision
darius
parents:
diff changeset
280
42e11dc15457 Initial revision
darius
parents:
diff changeset
281 void Voice_Stop(int voice)
42e11dc15457 Initial revision
darius
parents:
diff changeset
282 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
283 if((voice < 0) || (voice >= md_numchn)) return;
42e11dc15457 Initial revision
darius
parents:
diff changeset
284 if(voice >= md_sngchn)
42e11dc15457 Initial revision
darius
parents:
diff changeset
285 { // It is a sound effects channel, so flag the voice as non-critical!
42e11dc15457 Initial revision
darius
parents:
diff changeset
286 sfxinfo[voice-md_sngchn] = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
287 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
288
42e11dc15457 Initial revision
darius
parents:
diff changeset
289 md_driver->VoiceStop(voice);
42e11dc15457 Initial revision
darius
parents:
diff changeset
290 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
291
42e11dc15457 Initial revision
darius
parents:
diff changeset
292
42e11dc15457 Initial revision
darius
parents:
diff changeset
293 BOOL Voice_Stopped(int voice)
42e11dc15457 Initial revision
darius
parents:
diff changeset
294 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
295 if((voice < 0) || (voice >= md_numchn)) return 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
296 return(md_driver->VoiceStopped(voice));
42e11dc15457 Initial revision
darius
parents:
diff changeset
297 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
298
42e11dc15457 Initial revision
darius
parents:
diff changeset
299
42e11dc15457 Initial revision
darius
parents:
diff changeset
300 SLONG Voice_GetPosition(int voice)
42e11dc15457 Initial revision
darius
parents:
diff changeset
301 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
302 if((voice < 0) || (voice >= md_numchn)) return 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
303 return(md_driver->VoiceGetPosition(voice));
42e11dc15457 Initial revision
darius
parents:
diff changeset
304 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
305
42e11dc15457 Initial revision
darius
parents:
diff changeset
306
42e11dc15457 Initial revision
darius
parents:
diff changeset
307 ULONG Voice_RealVolume(int voice)
42e11dc15457 Initial revision
darius
parents:
diff changeset
308 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
309 if((voice < 0) || (voice >= md_numchn)) return 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
310 return(md_driver->VoiceRealVolume(voice));
42e11dc15457 Initial revision
darius
parents:
diff changeset
311 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
312
42e11dc15457 Initial revision
darius
parents:
diff changeset
313
42e11dc15457 Initial revision
darius
parents:
diff changeset
314 // ================================
42e11dc15457 Initial revision
darius
parents:
diff changeset
315 // Functions prefixed with MikMod
42e11dc15457 Initial revision
darius
parents:
diff changeset
316 // ================================
42e11dc15457 Initial revision
darius
parents:
diff changeset
317
42e11dc15457 Initial revision
darius
parents:
diff changeset
318 BOOL MikMod_Init(void)
42e11dc15457 Initial revision
darius
parents:
diff changeset
319 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
320 UWORD t;
42e11dc15457 Initial revision
darius
parents:
diff changeset
321
42e11dc15457 Initial revision
darius
parents:
diff changeset
322 _mm_critical = 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
323
42e11dc15457 Initial revision
darius
parents:
diff changeset
324 // if md_device==0, try to find a device number
42e11dc15457 Initial revision
darius
parents:
diff changeset
325
42e11dc15457 Initial revision
darius
parents:
diff changeset
326 if(md_device==0)
42e11dc15457 Initial revision
darius
parents:
diff changeset
327 { for(t=1,md_driver=firstdriver; md_driver!=NULL; md_driver=md_driver->next, t++)
42e11dc15457 Initial revision
darius
parents:
diff changeset
328 { if(md_driver->IsPresent()) break;
42e11dc15457 Initial revision
darius
parents:
diff changeset
329 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
330
42e11dc15457 Initial revision
darius
parents:
diff changeset
331 if(md_driver==NULL)
42e11dc15457 Initial revision
darius
parents:
diff changeset
332 { _mm_errno = MMERR_DETECTING_DEVICE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
333 if(_mm_errorhandler!=NULL) _mm_errorhandler();
42e11dc15457 Initial revision
darius
parents:
diff changeset
334 md_driver = &drv_nos;
42e11dc15457 Initial revision
darius
parents:
diff changeset
335 return 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
336 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
337
42e11dc15457 Initial revision
darius
parents:
diff changeset
338 md_device = t;
42e11dc15457 Initial revision
darius
parents:
diff changeset
339 } else
42e11dc15457 Initial revision
darius
parents:
diff changeset
340 { // if n>0 use that driver
42e11dc15457 Initial revision
darius
parents:
diff changeset
341 for(t=1,md_driver=firstdriver; (md_driver!=NULL) && (t!=md_device); md_driver=md_driver->next, t++);
42e11dc15457 Initial revision
darius
parents:
diff changeset
342
42e11dc15457 Initial revision
darius
parents:
diff changeset
343 if(md_driver==NULL)
42e11dc15457 Initial revision
darius
parents:
diff changeset
344 { _mm_errno = MMERR_INVALID_DEVICE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
345 if(_mm_errorhandler!=NULL) _mm_errorhandler();
42e11dc15457 Initial revision
darius
parents:
diff changeset
346 md_driver = &drv_nos;
42e11dc15457 Initial revision
darius
parents:
diff changeset
347 return 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
348 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
349
42e11dc15457 Initial revision
darius
parents:
diff changeset
350 if(!md_driver->IsPresent())
42e11dc15457 Initial revision
darius
parents:
diff changeset
351 { _mm_errno = MMERR_DETECTING_DEVICE;
42e11dc15457 Initial revision
darius
parents:
diff changeset
352 if(_mm_errorhandler!=NULL) _mm_errorhandler();
42e11dc15457 Initial revision
darius
parents:
diff changeset
353 md_driver = &drv_nos;
42e11dc15457 Initial revision
darius
parents:
diff changeset
354 return 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
355 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
356 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
357
42e11dc15457 Initial revision
darius
parents:
diff changeset
358 if(md_driver->Init())
42e11dc15457 Initial revision
darius
parents:
diff changeset
359 { MikMod_Exit();
42e11dc15457 Initial revision
darius
parents:
diff changeset
360 if(_mm_errorhandler!=NULL) _mm_errorhandler();
42e11dc15457 Initial revision
darius
parents:
diff changeset
361 return 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
362 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
363
42e11dc15457 Initial revision
darius
parents:
diff changeset
364 idevice = md_device; imode = md_mode;
42e11dc15457 Initial revision
darius
parents:
diff changeset
365 imixfreq = md_mixfreq; idmabufsize = md_dmabufsize;
42e11dc15457 Initial revision
darius
parents:
diff changeset
366 initialized = 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
367 _mm_critical = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
368
42e11dc15457 Initial revision
darius
parents:
diff changeset
369 return 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
370 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
371
42e11dc15457 Initial revision
darius
parents:
diff changeset
372
42e11dc15457 Initial revision
darius
parents:
diff changeset
373 void MikMod_Exit(void)
42e11dc15457 Initial revision
darius
parents:
diff changeset
374 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
375 MikMod_DisableOutput();
42e11dc15457 Initial revision
darius
parents:
diff changeset
376 md_driver->Exit();
42e11dc15457 Initial revision
darius
parents:
diff changeset
377 md_numchn = md_sfxchn = md_sngchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
378 md_driver = &drv_nos;
42e11dc15457 Initial revision
darius
parents:
diff changeset
379 initialized = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
380 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
381
42e11dc15457 Initial revision
darius
parents:
diff changeset
382
42e11dc15457 Initial revision
darius
parents:
diff changeset
383 BOOL MikMod_Reset(void)
42e11dc15457 Initial revision
darius
parents:
diff changeset
384
42e11dc15457 Initial revision
darius
parents:
diff changeset
385 // Reset the driver using the new global variable settings.
42e11dc15457 Initial revision
darius
parents:
diff changeset
386 // If the driver has not been initialized, it will be now.
42e11dc15457 Initial revision
darius
parents:
diff changeset
387
42e11dc15457 Initial revision
darius
parents:
diff changeset
388 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
389 if(!initialized) return MikMod_Init();
42e11dc15457 Initial revision
darius
parents:
diff changeset
390 if((md_driver->Reset == NULL) || (md_device != idevice))
42e11dc15457 Initial revision
darius
parents:
diff changeset
391 { // md_driver->Reset was NULL, or md_device was changed,
42e11dc15457 Initial revision
darius
parents:
diff changeset
392 // so do a full reset of the driver.
42e11dc15457 Initial revision
darius
parents:
diff changeset
393
42e11dc15457 Initial revision
darius
parents:
diff changeset
394 if(isplaying) md_driver->PlayStop();
42e11dc15457 Initial revision
darius
parents:
diff changeset
395 md_driver->Exit();
42e11dc15457 Initial revision
darius
parents:
diff changeset
396 if(MikMod_Init())
42e11dc15457 Initial revision
darius
parents:
diff changeset
397 { MikMod_Exit();
42e11dc15457 Initial revision
darius
parents:
diff changeset
398 if(_mm_errorhandler!=NULL) _mm_errorhandler();
42e11dc15457 Initial revision
darius
parents:
diff changeset
399 return 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
400 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
401 if(isplaying) md_driver->PlayStart();
42e11dc15457 Initial revision
darius
parents:
diff changeset
402 } else
42e11dc15457 Initial revision
darius
parents:
diff changeset
403 { if(md_driver->Reset())
42e11dc15457 Initial revision
darius
parents:
diff changeset
404 { MikMod_Exit();
42e11dc15457 Initial revision
darius
parents:
diff changeset
405 if(_mm_errorhandler!=NULL) _mm_errorhandler();
42e11dc15457 Initial revision
darius
parents:
diff changeset
406 return 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
407 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
408 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
409
42e11dc15457 Initial revision
darius
parents:
diff changeset
410 return 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
411 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
412
42e11dc15457 Initial revision
darius
parents:
diff changeset
413
42e11dc15457 Initial revision
darius
parents:
diff changeset
414 BOOL MikMod_SetNumVoices(int music, int sfx)
42e11dc15457 Initial revision
darius
parents:
diff changeset
415
42e11dc15457 Initial revision
darius
parents:
diff changeset
416 // If either parameter is -1, the current set value will be retained.
42e11dc15457 Initial revision
darius
parents:
diff changeset
417
42e11dc15457 Initial revision
darius
parents:
diff changeset
418 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
419 BOOL resume = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
420 int t, oldchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
421
42e11dc15457 Initial revision
darius
parents:
diff changeset
422 if((music==0) && (sfx==0)) return 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
423
42e11dc15457 Initial revision
darius
parents:
diff changeset
424 _mm_critical = 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
425
42e11dc15457 Initial revision
darius
parents:
diff changeset
426 if(isplaying)
42e11dc15457 Initial revision
darius
parents:
diff changeset
427 { MikMod_DisableOutput();
42e11dc15457 Initial revision
darius
parents:
diff changeset
428 oldchn = md_numchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
429 resume = 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
430 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
431
42e11dc15457 Initial revision
darius
parents:
diff changeset
432 if(sfxinfo!=NULL) free(sfxinfo);
42e11dc15457 Initial revision
darius
parents:
diff changeset
433 if(md_sample!=NULL) free(md_sample);
42e11dc15457 Initial revision
darius
parents:
diff changeset
434 md_sample = NULL;
42e11dc15457 Initial revision
darius
parents:
diff changeset
435 sfxinfo = NULL;
42e11dc15457 Initial revision
darius
parents:
diff changeset
436
42e11dc15457 Initial revision
darius
parents:
diff changeset
437 /*md_softchn = md_hardchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
438
42e11dc15457 Initial revision
darius
parents:
diff changeset
439 if(md_mode & DMODE_SOFT_SNDFX)
42e11dc15457 Initial revision
darius
parents:
diff changeset
440 md_softchn = sfx; else md_hardchn = sfx;
42e11dc15457 Initial revision
darius
parents:
diff changeset
441
42e11dc15457 Initial revision
darius
parents:
diff changeset
442 if(md_mode & DMODE_SOFT_MUSIC)
42e11dc15457 Initial revision
darius
parents:
diff changeset
443 md_softchn += music; else md_hardchn += music;
42e11dc15457 Initial revision
darius
parents:
diff changeset
444 */
42e11dc15457 Initial revision
darius
parents:
diff changeset
445
42e11dc15457 Initial revision
darius
parents:
diff changeset
446 if(music != -1) md_sngchn = music;
42e11dc15457 Initial revision
darius
parents:
diff changeset
447 if(sfx != -1) md_sfxchn = sfx;
42e11dc15457 Initial revision
darius
parents:
diff changeset
448
42e11dc15457 Initial revision
darius
parents:
diff changeset
449 md_numchn = md_sngchn + md_sfxchn;
42e11dc15457 Initial revision
darius
parents:
diff changeset
450
42e11dc15457 Initial revision
darius
parents:
diff changeset
451 LimitHardVoices(md_driver->HardVoiceLimit);
42e11dc15457 Initial revision
darius
parents:
diff changeset
452 LimitSoftVoices(md_driver->SoftVoiceLimit);
42e11dc15457 Initial revision
darius
parents:
diff changeset
453
42e11dc15457 Initial revision
darius
parents:
diff changeset
454 if(md_driver->SetNumVoices())
42e11dc15457 Initial revision
darius
parents:
diff changeset
455 { MikMod_Exit();
42e11dc15457 Initial revision
darius
parents:
diff changeset
456 md_numchn = md_softchn = md_hardchn = md_sfxchn = md_sngchn = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
457 if(_mm_errorhandler!=NULL) _mm_errorhandler();
42e11dc15457 Initial revision
darius
parents:
diff changeset
458 return 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
459 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
460
42e11dc15457 Initial revision
darius
parents:
diff changeset
461 if(md_sngchn || md_sfxchn)
42e11dc15457 Initial revision
darius
parents:
diff changeset
462 md_sample = (SAMPLE **)_mm_calloc(md_sngchn+md_sfxchn, sizeof(SAMPLE *));
42e11dc15457 Initial revision
darius
parents:
diff changeset
463 if(md_sfxchn)
42e11dc15457 Initial revision
darius
parents:
diff changeset
464 sfxinfo = (UBYTE *)_mm_calloc(md_sfxchn, sizeof(UBYTE));
42e11dc15457 Initial revision
darius
parents:
diff changeset
465
42e11dc15457 Initial revision
darius
parents:
diff changeset
466 // make sure the player doesn't start with garbage
42e11dc15457 Initial revision
darius
parents:
diff changeset
467 for(t=oldchn; t<md_numchn; t++) Voice_Stop(t);
42e11dc15457 Initial revision
darius
parents:
diff changeset
468
42e11dc15457 Initial revision
darius
parents:
diff changeset
469 sfxpool = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
470
42e11dc15457 Initial revision
darius
parents:
diff changeset
471 if(resume) MikMod_EnableOutput();
42e11dc15457 Initial revision
darius
parents:
diff changeset
472 _mm_critical = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
473
42e11dc15457 Initial revision
darius
parents:
diff changeset
474 return 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
475 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
476
42e11dc15457 Initial revision
darius
parents:
diff changeset
477
42e11dc15457 Initial revision
darius
parents:
diff changeset
478 BOOL MikMod_EnableOutput(void)
42e11dc15457 Initial revision
darius
parents:
diff changeset
479 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
480 // safety valve, prevents entering
42e11dc15457 Initial revision
darius
parents:
diff changeset
481 // playstart twice:
42e11dc15457 Initial revision
darius
parents:
diff changeset
482
42e11dc15457 Initial revision
darius
parents:
diff changeset
483 _mm_critical = 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
484 if(!isplaying)
42e11dc15457 Initial revision
darius
parents:
diff changeset
485 { if(md_driver->PlayStart()) return 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
486 isplaying = 1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
487 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
488 _mm_critical = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
489 return 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
490 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
491
42e11dc15457 Initial revision
darius
parents:
diff changeset
492
42e11dc15457 Initial revision
darius
parents:
diff changeset
493 void MikMod_DisableOutput(void)
42e11dc15457 Initial revision
darius
parents:
diff changeset
494 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
495 // safety valve, prevents calling playStop when playstart
42e11dc15457 Initial revision
darius
parents:
diff changeset
496 // hasn't been called:
42e11dc15457 Initial revision
darius
parents:
diff changeset
497
42e11dc15457 Initial revision
darius
parents:
diff changeset
498 if(isplaying && md_driver!=NULL)
42e11dc15457 Initial revision
darius
parents:
diff changeset
499 { isplaying = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
500 md_driver->PlayStop();
42e11dc15457 Initial revision
darius
parents:
diff changeset
501 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
502 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
503
42e11dc15457 Initial revision
darius
parents:
diff changeset
504
42e11dc15457 Initial revision
darius
parents:
diff changeset
505 BOOL MikMod_Active(void)
42e11dc15457 Initial revision
darius
parents:
diff changeset
506 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
507 return isplaying;
42e11dc15457 Initial revision
darius
parents:
diff changeset
508 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
509
42e11dc15457 Initial revision
darius
parents:
diff changeset
510
42e11dc15457 Initial revision
darius
parents:
diff changeset
511 int MikMod_PlaySample(SAMPLE *s, ULONG start, UBYTE flags)
42e11dc15457 Initial revision
darius
parents:
diff changeset
512
42e11dc15457 Initial revision
darius
parents:
diff changeset
513 // Plays a sound effects sample. Picks a voice from the number of voices
42e11dc15457 Initial revision
darius
parents:
diff changeset
514 // allocated for use as sound effects (loops through voices, skipping all
42e11dc15457 Initial revision
darius
parents:
diff changeset
515 // active criticals).
42e11dc15457 Initial revision
darius
parents:
diff changeset
516 //
42e11dc15457 Initial revision
darius
parents:
diff changeset
517 // Returns the voice that the sound is being played on.
42e11dc15457 Initial revision
darius
parents:
diff changeset
518
42e11dc15457 Initial revision
darius
parents:
diff changeset
519 {
42e11dc15457 Initial revision
darius
parents:
diff changeset
520 int orig = sfxpool; // for cases where all channels are critical
42e11dc15457 Initial revision
darius
parents:
diff changeset
521 int c;
42e11dc15457 Initial revision
darius
parents:
diff changeset
522
42e11dc15457 Initial revision
darius
parents:
diff changeset
523 if(md_sfxchn==0) return -1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
524 if(s->volume > 64) s->volume = 64;
42e11dc15457 Initial revision
darius
parents:
diff changeset
525
42e11dc15457 Initial revision
darius
parents:
diff changeset
526 // check the first location after sfxpool
42e11dc15457 Initial revision
darius
parents:
diff changeset
527 do
42e11dc15457 Initial revision
darius
parents:
diff changeset
528 { if(sfxinfo[sfxpool] & SFX_CRITICAL)
42e11dc15457 Initial revision
darius
parents:
diff changeset
529 { if(md_driver->VoiceStopped(c=sfxpool+md_sngchn))
42e11dc15457 Initial revision
darius
parents:
diff changeset
530 { sfxinfo[sfxpool] = flags;
42e11dc15457 Initial revision
darius
parents:
diff changeset
531 Voice_Play(c, s, start);
42e11dc15457 Initial revision
darius
parents:
diff changeset
532 md_driver->VoiceSetVolume(c,s->volume<<2);
42e11dc15457 Initial revision
darius
parents:
diff changeset
533 md_driver->VoiceSetPanning(c,s->panning);
42e11dc15457 Initial revision
darius
parents:
diff changeset
534 md_driver->VoiceSetFrequency(c,s->speed);
42e11dc15457 Initial revision
darius
parents:
diff changeset
535 sfxpool++;
42e11dc15457 Initial revision
darius
parents:
diff changeset
536 if(sfxpool >= md_sfxchn) sfxpool = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
537 return c;
42e11dc15457 Initial revision
darius
parents:
diff changeset
538 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
539 } else
42e11dc15457 Initial revision
darius
parents:
diff changeset
540 { sfxinfo[sfxpool] = flags;
42e11dc15457 Initial revision
darius
parents:
diff changeset
541 Voice_Play(c=sfxpool+md_sngchn, s, start);
42e11dc15457 Initial revision
darius
parents:
diff changeset
542 md_driver->VoiceSetVolume(c,s->volume<<2);
42e11dc15457 Initial revision
darius
parents:
diff changeset
543 md_driver->VoiceSetPanning(c,s->panning);
42e11dc15457 Initial revision
darius
parents:
diff changeset
544 md_driver->VoiceSetFrequency(c,s->speed);
42e11dc15457 Initial revision
darius
parents:
diff changeset
545 sfxpool++;
42e11dc15457 Initial revision
darius
parents:
diff changeset
546 if(sfxpool >= md_sfxchn) sfxpool = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
547 return c;
42e11dc15457 Initial revision
darius
parents:
diff changeset
548 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
549
42e11dc15457 Initial revision
darius
parents:
diff changeset
550 sfxpool++;
42e11dc15457 Initial revision
darius
parents:
diff changeset
551 if(sfxpool >= md_sfxchn) sfxpool = 0;
42e11dc15457 Initial revision
darius
parents:
diff changeset
552 } while(sfxpool!=orig);
42e11dc15457 Initial revision
darius
parents:
diff changeset
553
42e11dc15457 Initial revision
darius
parents:
diff changeset
554 return -1;
42e11dc15457 Initial revision
darius
parents:
diff changeset
555 }
42e11dc15457 Initial revision
darius
parents:
diff changeset
556