Mercurial > hg > dmlib
annotate minijss/jssmix.c @ 1269:4b22da2a309f
Comments, cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 03 Jun 2015 16:17:04 +0300 |
parents | 848a88ce7a57 |
children | 6aa0897265e8 |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Mixing device and channel handling | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
1163 | 4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) |
0 | 5 */ |
6 #include "jssmix.h" | |
7 | |
8 | |
9 #ifdef DM_USE_C | |
10 #define JMIXER_HEADER | |
49
033c660c25f5
Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
11 #include "jmix_c_in.c" |
0 | 12 #undef JMIXER_HEADER |
13 #endif | |
14 | |
15 #undef DM_USE_SIMD | |
16 | |
17 #ifdef DM_USE_SIMD | |
18 #define JMIXER_HEADER | |
49
033c660c25f5
Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
19 #include "jmix_mmx_in.c" |
0 | 20 #undef JMIXER_HEADER |
21 #endif | |
22 | |
23 | |
24 typedef struct | |
25 { | |
26 int mixerID; | |
27 int outFormat; | |
28 int outChannels; | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
29 |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
30 int (*jvmMixChannel_FW)(JSSMixer *, JSSChannel *, JMIXER_ADDBUF_TYPE *, const int, const DMFixedPoint); |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
31 int (*jvmMixChannel_BW)(JSSMixer *, JSSChannel *, JMIXER_ADDBUF_TYPE *, const int, const DMFixedPoint); |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
32 void (*jvmPostProcess)(JMIXER_ADDBUF_TYPE *, void *, const int); |
0 | 33 } JSSMixingRoutine; |
34 | |
35 | |
36 /* This table should be sorted from fastest to slowest, e.g. MMX/x86 | |
37 * optimized routines first, pure C versions last. | |
38 */ | |
39 static JSSMixingRoutine jvmMixRoutines[] = | |
40 { | |
41 #ifdef DM_USE_SIMD | |
42 { JMIX_MMX, JSS_AUDIO_U8, JSS_AUDIO_MONO, jvmMix_Mono_MMX_FW, jvmMix_Mono_MMX_BW, jvmPostProcess_U8_MMX }, | |
43 { JMIX_MMX, JSS_AUDIO_S8, JSS_AUDIO_MONO, jvmMix_Mono_MMX_FW, jvmMix_Mono_MMX_BW, jvmPostProcess_S8_MMX }, | |
44 { JMIX_MMX, JSS_AUDIO_U8, JSS_AUDIO_STEREO, jvmMix_Stereo_MMX_FW, jvmMix_Stereo_MMX_BW, jvmPostProcess_U8_MMX }, | |
45 { JMIX_MMX, JSS_AUDIO_S8, JSS_AUDIO_STEREO, jvmMix_Stereo_MMX_FW, jvmMix_Stereo_MMX_BW, jvmPostProcess_S8_MMX }, | |
46 | |
47 { JMIX_MMX, JSS_AUDIO_U16, JSS_AUDIO_MONO, jvmMix_Mono_MMX_FW, jvmMix_Mono_MMX_BW, jvmPostProcess_U16_MMX }, | |
48 { JMIX_MMX, JSS_AUDIO_S16, JSS_AUDIO_MONO, jvmMix_Mono_MMX_FW, jvmMix_Mono_MMX_BW, jvmPostProcess_S16_MMX }, | |
49 { JMIX_MMX, JSS_AUDIO_U16, JSS_AUDIO_STEREO, jvmMix_Stereo_MMX_FW, jvmMix_Stereo_MMX_BW, jvmPostProcess_U16_MMX }, | |
50 { JMIX_MMX, JSS_AUDIO_S16, JSS_AUDIO_STEREO, jvmMix_Stereo_MMX_FW, jvmMix_Stereo_MMX_BW, jvmPostProcess_S16_MMX }, | |
51 #endif | |
52 | |
53 #ifdef DM_USE_C | |
54 { JMIX_C, JSS_AUDIO_U8, JSS_AUDIO_MONO, jvmMix_Mono_C_FW, jvmMix_Mono_C_BW, jvmPostProcess_U8_C }, | |
55 { JMIX_C, JSS_AUDIO_S8, JSS_AUDIO_MONO, jvmMix_Mono_C_FW, jvmMix_Mono_C_BW, jvmPostProcess_S8_C }, | |
56 { JMIX_C, JSS_AUDIO_U8, JSS_AUDIO_STEREO, jvmMix_Stereo_C_FW, jvmMix_Stereo_C_BW, jvmPostProcess_U8_C }, | |
57 { JMIX_C, JSS_AUDIO_S8, JSS_AUDIO_STEREO, jvmMix_Stereo_C_FW, jvmMix_Stereo_C_BW, jvmPostProcess_S8_C }, | |
58 | |
59 { JMIX_C, JSS_AUDIO_U16, JSS_AUDIO_MONO, jvmMix_Mono_C_FW, jvmMix_Mono_C_BW, jvmPostProcess_U16_C }, | |
60 { JMIX_C, JSS_AUDIO_S16, JSS_AUDIO_MONO, jvmMix_Mono_C_FW, jvmMix_Mono_C_BW, jvmPostProcess_S16_C }, | |
61 { JMIX_C, JSS_AUDIO_U16, JSS_AUDIO_STEREO, jvmMix_Stereo_C_FW, jvmMix_Stereo_C_BW, jvmPostProcess_U16_C }, | |
62 { JMIX_C, JSS_AUDIO_S16, JSS_AUDIO_STEREO, jvmMix_Stereo_C_FW, jvmMix_Stereo_C_BW, jvmPostProcess_S16_C }, | |
63 #endif | |
64 }; | |
65 | |
66 static const int jvmNMixRoutines = sizeof(jvmMixRoutines) / sizeof(jvmMixRoutines[0]); | |
67 | |
68 | |
69 static int jvmFindMixRoutine(int outFormat, int outChannels, int mixerID) | |
70 { | |
71 int i; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
72 |
0 | 73 for (i = 0; i < jvmNMixRoutines; i++) |
74 { | |
75 if (jvmMixRoutines[i].outFormat == outFormat && | |
76 jvmMixRoutines[i].outChannels == outChannels && | |
77 (mixerID == JMIX_AUTO || jvmMixRoutines[i].mixerID == mixerID)) | |
78 return i; | |
79 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
80 |
0 | 81 return -1; |
82 } | |
83 | |
84 | |
85 JSSMixer *jvmInit(const int outFormat, const int outChannels, const int outFreq, const int mixerID) | |
86 { | |
87 JSSMixer *mixer; | |
49
033c660c25f5
Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
88 int mixerIdx; |
0 | 89 |
843
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
90 // Sanity check |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
91 if (jvmNMixRoutines == 0) |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
92 { |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
93 JSSERROR(DMERR_INTERNAL, NULL, |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
94 "No mixing routines compiled in?\n"); |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
95 return NULL; |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
96 } |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
97 |
0 | 98 // Check settings |
99 if (outChannels < 1) | |
100 { | |
101 JSSERROR(DMERR_INVALID_ARGS, NULL, | |
102 "Invalid number of channels %d\n", outChannels); | |
103 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
104 |
1269 | 105 if (outFreq < 1000) |
0 | 106 { |
107 JSSERROR(DMERR_INVALID_ARGS, NULL, | |
108 "Invalid mixing frequency %d\n", outFreq); | |
109 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
110 |
0 | 111 /* Select mixing routines: |
112 * Here we try to choose the most fitting mixing routines | |
113 * from the compiled in routines, unless caller is forcing | |
114 * us to select specific ones. | |
115 */ | |
116 if (mixerID == JMIX_AUTO) | |
117 { | |
118 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_SSE); | |
119 if (mixerIdx < 0) | |
120 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_MMX); | |
121 if (mixerIdx < 0) | |
122 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_AUTO); | |
123 } | |
124 else | |
125 { | |
126 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, mixerID); | |
127 } | |
128 | |
129 if (mixerIdx < 0) | |
130 { | |
131 JSSERROR(DMERR_INVALID_ARGS, NULL, | |
132 "Could not find mixing routine for outFormat=%d, outChannels=%d, outFreq=%d.\n", | |
133 outFormat, outChannels, outFreq); | |
134 return NULL; | |
135 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
136 |
0 | 137 // Allocate a mixer device structure |
138 mixer = dmMalloc0(sizeof(JSSMixer)); | |
139 if (mixer == NULL) | |
140 { | |
141 JSSERROR(DMERR_MALLOC, NULL, | |
142 "Could not allocate mixing device structure.\n"); | |
143 } | |
144 | |
145 // Initialize variables | |
146 #ifdef JSS_SUP_THREADS | |
147 mixer->mutex = dmCreateMutex(); | |
148 #endif | |
149 mixer->outFormat = outFormat; | |
1269 | 150 mixer->outChannels = outChannels; |
0 | 151 mixer->outFreq = outFreq; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
152 |
0 | 153 mixer->jvmMixChannel_FW = jvmMixRoutines[mixerIdx].jvmMixChannel_FW; |
154 mixer->jvmMixChannel_BW = jvmMixRoutines[mixerIdx].jvmMixChannel_BW; | |
155 mixer->jvmPostProcess = jvmMixRoutines[mixerIdx].jvmPostProcess; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
156 |
0 | 157 // Allocate addBuffer |
291 | 158 mixer->addBufSize = outChannels * outFreq * 2; |
53
a83f7c4d9e08
No need to allocate with dmCalloc, when a plain dmMalloc is fine.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
159 mixer->addBuffer = dmMalloc(mixer->addBufSize * sizeof(JMIXER_ADDBUF_TYPE)); |
0 | 160 if (mixer->addBuffer == NULL) |
161 { | |
162 JSSERROR(DMERR_MALLOC, NULL, | |
163 "Could not allocate mixing addition buffer.\n"); | |
164 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
165 |
0 | 166 return mixer; |
167 } | |
168 | |
169 | |
170 int jvmClose(JSSMixer * mixer) | |
171 { | |
172 if (mixer == NULL) | |
173 return DMERR_NULLPTR; | |
174 | |
175 // Deallocate resources | |
176 #ifdef JSS_SUP_THREADS | |
177 dmDestroyMutex(mixer->mutex); | |
178 #endif | |
179 dmFree(mixer->addBuffer); | |
180 | |
1167 | 181 dmMemset(mixer, 0, sizeof(JSSMixer)); |
0 | 182 dmFree(mixer); |
183 | |
184 return DMERR_OK; | |
185 } | |
186 | |
187 | |
188 int jvmGetSampleSize(JSSMixer *mixer) | |
189 { | |
190 int sampSize = 1; | |
191 assert(mixer); | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
192 |
0 | 193 switch (mixer->outChannels) |
194 { | |
195 case JSS_AUDIO_STEREO: | |
196 case JSS_AUDIO_MONO: | |
197 sampSize = mixer->outChannels; | |
198 break; | |
199 default: | |
200 JSSERROR(DMERR_INVALID_ARGS, -1, | |
201 "outChannels=%d not stereo or mono!\n", mixer->outChannels); | |
202 break; | |
203 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
204 |
0 | 205 switch (mixer->outFormat) |
206 { | |
207 case JSS_AUDIO_U16: sampSize *= sizeof(Uint16); break; | |
208 case JSS_AUDIO_S16: sampSize *= sizeof(Sint16); break; | |
54 | 209 case JSS_AUDIO_U8: sampSize *= sizeof(Uint8); break; |
210 case JSS_AUDIO_S8: sampSize *= sizeof(Sint8); break; | |
0 | 211 default: |
212 JSSERROR(DMERR_INVALID_ARGS, -1, | |
213 "outFormat=%d is not supported!\n", mixer->outFormat); | |
214 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
215 |
0 | 216 return sampSize; |
217 } | |
218 | |
219 | |
220 int jvmGetSampleRes(JSSMixer *mixer) | |
221 { | |
54 | 222 int sampRes = 0; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
223 |
0 | 224 assert(mixer); |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
225 |
0 | 226 switch (mixer->outFormat) |
227 { | |
228 case JSS_AUDIO_U16: case JSS_AUDIO_S16: sampRes = 16; break; | |
54 | 229 case JSS_AUDIO_U8: case JSS_AUDIO_S8: sampRes = 8; break; |
0 | 230 default: |
231 JSSERROR(DMERR_INVALID_ARGS, -1, | |
232 "outFormat=%d is not supported!\n", mixer->outFormat); | |
233 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
234 |
0 | 235 return sampRes; |
236 } | |
237 | |
238 | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
239 static void jvmMixChannel(JSSMixer *mixer, JSSChannel *chn, JMIXER_ADDBUF_TYPE *addBuffer, const int mixLength) |
0 | 240 { |
241 int mixDone = mixLength, mixResult; | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
242 JMIXER_ADDBUF_TYPE *ab = addBuffer; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
243 |
0 | 244 if (!chn->chPlaying || chn->chMute) |
245 return; | |
246 | |
247 DBG("%s(%p, %d)\n", __FUNCTION__, chn, mixLength); | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
248 |
0 | 249 while (mixDone > 0) |
250 { | |
251 if (chn->chDirection) | |
252 { | |
253 // Channel is playing FORWARDS | |
254 if (chn->chFlags & jsfLooped) | |
255 { | |
256 // Sample is looped | |
257 if (chn->chFlags & jsfBiDi) | |
258 { | |
259 // Bi-directional loop | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
260 if (chn->chPos.dw >= chn->chLoopE.dw) |
0 | 261 { |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
262 DMFixedPoint end; |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
263 FP_ADD_R(end, chn->chLoopE, chn->chLoopE); |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
264 FP_SUB_R(chn->chPos, end, chn->chPos); |
0 | 265 chn->chDirection = FALSE; |
266 } | |
267 } | |
268 else | |
269 { | |
270 // Normal forward loop | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
271 if (chn->chPos.dw >= chn->chLoopE.dw) |
0 | 272 { |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
273 DMFixedPoint diff; |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
274 FP_SUB_R(diff, chn->chPos, chn->chLoopE); |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
275 FP_ADD_R(chn->chPos, chn->chLoopS, diff); |
0 | 276 } |
277 } | |
278 } | |
279 else | |
280 { | |
281 // Normal (non-looped) sample | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
282 if (chn->chPos.dw >= chn->chSize.dw) |
0 | 283 { |
284 chn->chPlaying = FALSE; | |
285 return; | |
286 } | |
287 } | |
288 } | |
289 else | |
290 { | |
291 // Channel is playing BACKWARDS | |
292 if (chn->chFlags & jsfLooped) | |
293 { | |
294 // Sample is looped | |
295 if (chn->chFlags & jsfBiDi) | |
296 { | |
297 // Bi-directional loop | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
298 if (chn->chPos.dw <= chn->chLoopS.dw) |
0 | 299 { |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
300 DMFixedPoint start; |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
301 FP_ADD_R(start, chn->chLoopS, chn->chLoopS); |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
302 FP_SUB_R(chn->chPos, start, chn->chPos); |
0 | 303 chn->chDirection = TRUE; |
304 } | |
305 } | |
306 else | |
307 { | |
308 // Normal forward loop | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
309 if (chn->chPos.dw <= chn->chLoopS.dw) |
0 | 310 { |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
311 DMFixedPoint diff; |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
312 FP_SUB_R(diff, chn->chLoopE, chn->chLoopS); |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
313 FP_ADD(chn->chPos, diff); |
0 | 314 } |
315 } | |
316 } | |
317 else | |
318 { | |
319 // Normal (non-looped) sample | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
320 if (chn->chPos.dw <= 0) |
0 | 321 { |
322 chn->chPlaying = FALSE; | |
323 return; | |
324 } | |
325 } | |
326 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
327 |
0 | 328 // Call the mixing innerloop functions |
329 if (chn->chDirection) | |
330 { | |
331 DBG("MIX_FW[%p : %d : ", ab, mixDone); | |
332 if (chn->chFlags & jsfLooped) | |
333 { | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
334 DBG("%d (%x)] {loop}\n", FP_GETH32(chn->chLoopE), FP_GETH32(chn->chLoopE)); |
0 | 335 mixResult = mixer->jvmMixChannel_FW((void *) mixer, chn, |
336 ab, mixDone, chn->chLoopE); | |
337 } | |
338 else | |
339 { | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
340 DBG("%d (%x)]\n", FP_GETH32(chn->chSize), FP_GETH32(chn->chSize)); |
0 | 341 mixResult = mixer->jvmMixChannel_FW((void *) mixer, chn, |
342 ab, mixDone, chn->chSize); | |
343 } | |
344 } | |
345 else | |
346 { | |
347 DBG("MIX_BW[%p : %d : ", ab, mixDone); | |
348 if (chn->chFlags & jsfLooped) | |
349 { | |
350 DBG("%d (%x)] {loop}\n", chn->chLoopS, chn->chLoopS); | |
351 mixResult = mixer->jvmMixChannel_BW(mixer, chn, | |
352 ab, mixDone, chn->chLoopS); | |
353 } | |
354 else | |
355 { | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
356 static const DMFixedPoint zero = { 0 }; |
0 | 357 DBG("%d (%x)]\n", 0, 0); |
358 mixResult = mixer->jvmMixChannel_BW(mixer, chn, | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
359 ab, mixDone, zero); |
0 | 360 } |
361 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
362 |
0 | 363 mixDone -= mixResult; |
364 ab += mixResult * mixer->outChannels; | |
365 } | |
366 | |
367 #ifdef JSS_DEBUG | |
368 if (mixDone < 0) | |
369 JSSWARNING(DMERR_BOUNDS,, "mixDone < 0 in mixing logic loop.\n"); | |
370 #endif | |
371 } | |
372 | |
373 | |
374 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength) | |
375 { | |
376 int i, blockLength, mixLeft; | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
377 JMIXER_ADDBUF_TYPE *ab; |
0 | 378 |
379 JSS_LOCK(mixer); | |
380 | |
381 assert(mixer != NULL); | |
382 assert(mixBuffer != NULL); | |
383 assert(mixLength > 0); | |
52 | 384 assert(mixLength * mixer->outChannels <= mixer->addBufSize); |
0 | 385 |
386 // Clear mixer->addBuffer | |
1167 | 387 dmMemset(mixer->addBuffer, 0, mixLength * mixer->outChannels * sizeof(JMIXER_ADDBUF_TYPE)); |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
388 |
0 | 389 ab = mixer->addBuffer; |
390 mixLeft = mixLength; | |
391 while (mixLeft > 0) | |
392 { | |
393 // Check for callbacks | |
394 blockLength = mixLeft; | |
395 | |
396 if (mixer->cbFunction) | |
397 { | |
398 if (mixer->cbCounter <= 0) | |
399 { | |
400 mixer->cbFunction(mixer, mixer->cbData); | |
401 mixer->cbCounter = mixer->cbFreq; | |
402 } | |
403 | |
404 if (mixer->cbCounter < blockLength) | |
405 blockLength = mixer->cbCounter; | |
406 } | |
407 | |
408 // Do mixing | |
409 for (i = 0; i < jsetNChannels; i++) | |
410 { | |
411 JSSChannel *chn = &(mixer->channels[i]); | |
412 if (chn->chPlaying && !chn->chMute) | |
413 jvmMixChannel(mixer, chn, ab, blockLength); | |
414 } | |
415 | |
416 /* | |
417 if (chn->chPlaying) | |
418 { | |
419 if (!chn->chMute) | |
420 jvmMixChannel(mixer, chn, ab, blockLength); | |
421 else | |
422 jvmAdvanceChannel(mixer, chn, blockLength); | |
423 } | |
424 */ | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
425 |
0 | 426 ab += blockLength * mixer->outChannels; |
427 mixLeft -= blockLength; | |
428 mixer->cbCounter -= blockLength; | |
429 } | |
430 | |
431 // Post-process | |
432 mixer->jvmPostProcess(mixer->addBuffer, mixBuffer, mixLength * mixer->outChannels); | |
433 | |
434 JSS_UNLOCK(mixer); | |
435 } | |
436 | |
437 | |
438 int jvmSetCallback(JSSMixer * mixer, void (*cbFunction) (void *, void *), void *cbData) | |
439 { | |
440 assert(mixer); | |
441 | |
442 if (cbFunction == NULL) | |
443 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, "NULL pointer given as cbFunction"); | |
444 | |
445 JSS_LOCK(mixer); | |
446 | |
447 mixer->cbFunction = cbFunction; | |
448 mixer->cbData = cbData; | |
449 | |
450 JSS_UNLOCK(mixer); | |
451 | |
452 return DMERR_OK; | |
453 } | |
454 | |
455 | |
456 void jvmRemoveCallback(JSSMixer * mixer) | |
457 { | |
458 assert(mixer); | |
459 | |
460 JSS_LOCK(mixer); | |
461 | |
462 mixer->cbFunction = NULL; | |
463 mixer->cbData = NULL; | |
464 mixer->cbFreq = mixer->cbCounter = 0; | |
465 | |
466 JSS_UNLOCK(mixer); | |
467 } | |
468 | |
469 | |
470 int jvmSetCallbackFreq(JSSMixer * mixer, const int cbFreq) | |
471 { | |
472 assert(mixer); | |
473 | |
474 JSS_LOCK(mixer); | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
475 |
186
dc22e3f77c9a
Fix tempo (callback frequency) calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
476 mixer->cbFreq = cbFreq; |
0 | 477 mixer->cbCounter = 0; |
478 | |
479 //fprintf(stderr, "set(outFreq = %d, cbFreq = %d) = %d\n", mixer->outFreq, cbFreq, mixer->cbFreq); | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
480 |
0 | 481 JSS_UNLOCK(mixer); |
482 return DMERR_OK; | |
483 } | |
484 | |
485 | |
486 /* Channel manipulation routines | |
487 */ | |
488 void jvmPlay(JSSMixer * mixer, const int channel) | |
489 { | |
490 JSS_LOCK(mixer); | |
491 mixer->channels[channel].chPlaying = TRUE; | |
492 JSS_UNLOCK(mixer); | |
493 } | |
494 | |
495 | |
496 void jvmStop(JSSMixer * mixer, const int channel) | |
497 { | |
498 JSS_LOCK(mixer); | |
499 mixer->channels[channel].chPlaying = FALSE; | |
500 JSS_UNLOCK(mixer); | |
501 } | |
502 | |
503 | |
227
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
504 void jvmReset(JSSMixer * mixer, const int channel) |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
505 { |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
506 JSSChannel *c; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
507 |
227
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
508 JSS_LOCK(mixer); |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
509 c = &mixer->channels[channel]; |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
510 |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
511 c->chDirection = TRUE; |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
512 c->chPos.dw = c->chDeltaO.dw = 0; |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
513 |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
514 JSS_UNLOCK(mixer); |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
515 } |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
516 |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
517 |
0 | 518 void jvmSetSample(JSSMixer * mixer, const int channel, |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
519 void *data, const Sint32 size, const Sint32 loopS, |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
520 const Sint32 loopE, const int flags) |
0 | 521 { |
522 JSSChannel *c; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
523 |
0 | 524 JSS_LOCK(mixer); |
525 c = &mixer->channels[channel]; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
526 |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
527 FP_SETHL(c->chSize, size, 0); |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
528 FP_SETHL(c->chLoopS, loopS, 0); |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
529 FP_SETHL(c->chLoopE, loopE, 0); |
54 | 530 c->chData = data; |
531 c->chFlags = flags; | |
0 | 532 c->chDirection = TRUE; |
54 | 533 c->chPos.dw = c->chDeltaO.dw = 0; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
534 |
0 | 535 JSS_UNLOCK(mixer); |
536 } | |
537 | |
538 | |
539 void jvmSetFreq(JSSMixer * mixer, const int channel, const int freq) | |
540 { | |
541 JSS_LOCK(mixer); | |
542 | |
543 mixer->channels[channel].chFreq = freq; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
544 |
0 | 545 if (mixer->outFreq > 0) |
546 { | |
547 DMFixedPoint a, b; | |
548 FP_SETHL(a, freq, 0); | |
549 FP_CONV(b, mixer->outFreq); | |
550 FP_DIV_R(mixer->channels[channel].chDeltaO, a, b); | |
551 } | |
552 else | |
553 { | |
554 FP_SET(mixer->channels[channel].chDeltaO, 0); | |
555 } | |
556 | |
557 JSS_UNLOCK(mixer); | |
558 } | |
559 | |
560 | |
561 int jvmGetFreq(JSSMixer * mixer, const int channel) | |
562 { | |
563 int tmp; | |
564 | |
565 JSS_LOCK(mixer); | |
566 tmp = mixer->channels[channel].chFreq; | |
567 JSS_UNLOCK(mixer); | |
568 | |
569 return tmp; | |
570 } | |
571 | |
572 | |
573 void jvmSetVolume(JSSMixer * mixer, const int channel, const int volume) | |
574 { | |
575 JSS_LOCK(mixer); | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
576 FP_SETHL(mixer->channels[channel].chVolume, volume, 0); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
577 mixer->channels[channel].chVolumeD = 0; |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
578 mixer->channels[channel].chDeltaV.dw = 0; |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
579 JSS_UNLOCK(mixer); |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
580 } |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
581 |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
582 |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
583 void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len) |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
584 { |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
585 int tmp; |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
586 DMFixedPoint a, b; |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
587 JSS_LOCK(mixer); |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
588 FP_SETHL(mixer->channels[channel].chVolume, start, 0); |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
589 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
590 tmp = mixer->channels[channel].chVolumeD = |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
591 len > 0 ? ((mixer->outFreq * len) / 1000) : mixer->cbFreq; |
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
592 |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
593 FP_SETHL(a, (end - start), 0); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
594 FP_CONV(b, tmp); |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
595 FP_DIV_R(mixer->channels[channel].chDeltaV, a, b); |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
596 |
0 | 597 JSS_UNLOCK(mixer); |
598 } | |
599 | |
600 | |
601 int jvmGetVolume(JSSMixer * mixer, const int channel) | |
602 { | |
603 int tmp; | |
604 | |
605 JSS_LOCK(mixer); | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
606 tmp = FP_GETH32(mixer->channels[channel].chVolume); |
0 | 607 JSS_UNLOCK(mixer); |
608 | |
609 return tmp; | |
610 } | |
611 | |
612 | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
613 void jvmSetPos(JSSMixer * mixer, const int channel, const Sint32 pos) |
0 | 614 { |
615 JSS_LOCK(mixer); | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
616 FP_SETHL(mixer->channels[channel].chPos, pos, 0); |
0 | 617 JSS_UNLOCK(mixer); |
618 } | |
619 | |
620 | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
621 Sint32 jvmGetPos(JSSMixer * mixer, const int channel) |
0 | 622 { |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
623 Sint32 tmp; |
0 | 624 |
625 JSS_LOCK(mixer); | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
626 tmp = FP_GETH32(mixer->channels[channel].chPos); |
0 | 627 JSS_UNLOCK(mixer); |
628 | |
629 return tmp; | |
630 } | |
631 | |
632 | |
633 void jvmSetPan(JSSMixer * mixer, const int channel, const int panning) | |
634 { | |
635 JSS_LOCK(mixer); | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
636 FP_SETHL(mixer->channels[channel].chPanning, panning, 0); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
637 mixer->channels[channel].chPanningD = 0; |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
638 mixer->channels[channel].chDeltaP.dw = 0; |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
639 JSS_UNLOCK(mixer); |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
640 } |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
641 |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
642 |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
643 void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len) |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
644 { |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
645 int tmp; |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
646 DMFixedPoint a, b; |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
647 JSS_LOCK(mixer); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
648 |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
649 FP_SETHL(mixer->channels[channel].chPanning, start, 0); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
650 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
651 tmp = mixer->channels[channel].chPanningD = |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
652 len > 0 ? ((mixer->outFreq * len) / 1000) : mixer->cbFreq; |
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
653 |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
654 FP_SETHL(a, (end - start), 0); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
655 FP_CONV(b, tmp); |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
656 FP_DIV_R(mixer->channels[channel].chDeltaP, a, b); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
657 |
0 | 658 JSS_UNLOCK(mixer); |
659 } | |
660 | |
661 | |
662 int jvmGetPan(JSSMixer * mixer, const int channel) | |
663 { | |
664 int tmp; | |
665 | |
666 JSS_LOCK(mixer); | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
667 tmp = FP_GETH32(mixer->channels[channel].chPanning); |
0 | 668 JSS_UNLOCK(mixer); |
669 | |
670 return tmp; | |
671 } | |
672 | |
673 | |
674 void jvmMute(JSSMixer * mixer, const int channel, const BOOL mute) | |
675 { | |
676 JSS_LOCK(mixer); | |
677 mixer->channels[channel].chMute = mute; | |
678 JSS_UNLOCK(mixer); | |
679 } | |
680 | |
681 | |
141
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
682 BOOL jvmGetMute(JSSMixer * mixer, const int channel) |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
683 { |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
684 BOOL tmp; |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
685 |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
686 JSS_LOCK(mixer); |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
687 tmp = mixer->channels[channel].chMute; |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
688 JSS_UNLOCK(mixer); |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
689 |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
690 return tmp; |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
691 } |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
692 |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
693 |
0 | 694 void jvmClear(JSSMixer * mixer, const int channel) |
695 { | |
696 JSS_LOCK(mixer); | |
1167 | 697 dmMemset(&mixer->channels[channel], 0, sizeof(JSSChannel)); |
0 | 698 JSS_UNLOCK(mixer); |
699 } | |
700 | |
701 | |
702 void jvmSetGlobalVol(JSSMixer * mixer, const int volume) | |
703 { | |
704 JSS_LOCK(mixer); | |
705 mixer->globalVol = volume; | |
706 JSS_UNLOCK(mixer); | |
707 } | |
708 | |
709 | |
710 int jvmGetGlobalVol(JSSMixer * mixer) | |
711 { | |
712 int tmp; | |
713 | |
714 JSS_LOCK(mixer); | |
715 tmp = mixer->globalVol; | |
716 JSS_UNLOCK(mixer); | |
717 | |
718 return tmp; | |
719 } |