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