annotate playercode/mdriver.c @ 22:d9f79436e0af default tip

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