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
|
|
12 #include "jmix_c.c"
|
|
13 #undef JMIXER_HEADER
|
|
14 #endif
|
|
15
|
|
16 #undef DM_USE_SIMD
|
|
17
|
|
18 #ifdef DM_USE_SIMD
|
|
19 #define JMIXER_HEADER
|
|
20 #include "jmix_mmx.h"
|
|
21 #undef JMIXER_HEADER
|
|
22 #endif
|
|
23
|
|
24
|
|
25 typedef struct
|
|
26 {
|
|
27 int mixerID;
|
|
28 int outFormat;
|
|
29 int outChannels;
|
|
30 int (*jvmMixChannel_FW)(JSSMixer *, JSSChannel *, Sint32 *, const int, const Uint32);
|
|
31 int (*jvmMixChannel_BW)(JSSMixer *, JSSChannel *, Sint32 *, const int, const Uint32);
|
|
32 void (*jvmPostProcess)(Sint32 *, void *, const int);
|
|
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;
|
|
72
|
|
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 }
|
|
80
|
|
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;
|
|
88 int mixerIdx, v, i;
|
|
89
|
|
90 // Check settings
|
|
91 if (outChannels < 1)
|
|
92 {
|
|
93 JSSERROR(DMERR_INVALID_ARGS, NULL,
|
|
94 "Invalid number of channels %d\n", outChannels);
|
|
95 }
|
|
96
|
|
97 if (outFreq < 4000)
|
|
98 {
|
|
99 JSSERROR(DMERR_INVALID_ARGS, NULL,
|
|
100 "Invalid mixing frequency %d\n", outFreq);
|
|
101 }
|
|
102
|
|
103 /* Select mixing routines:
|
|
104 * Here we try to choose the most fitting mixing routines
|
|
105 * from the compiled in routines, unless caller is forcing
|
|
106 * us to select specific ones.
|
|
107 */
|
|
108 if (mixerID == JMIX_AUTO)
|
|
109 {
|
|
110 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_SSE);
|
|
111 if (mixerIdx < 0)
|
|
112 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_MMX);
|
|
113 if (mixerIdx < 0)
|
|
114 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_AUTO);
|
|
115 }
|
|
116 else
|
|
117 {
|
|
118 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, mixerID);
|
|
119 }
|
|
120
|
|
121 if (mixerIdx < 0)
|
|
122 {
|
|
123 JSSERROR(DMERR_INVALID_ARGS, NULL,
|
|
124 "Could not find mixing routine for outFormat=%d, outChannels=%d, outFreq=%d.\n",
|
|
125 outFormat, outChannels, outFreq);
|
|
126 return NULL;
|
|
127 }
|
|
128
|
|
129 // Allocate a mixer device structure
|
|
130 mixer = dmMalloc0(sizeof(JSSMixer));
|
|
131 if (mixer == NULL)
|
|
132 {
|
|
133 JSSERROR(DMERR_MALLOC, NULL,
|
|
134 "Could not allocate mixing device structure.\n");
|
|
135 }
|
|
136
|
|
137 // Initialize variables
|
|
138 #ifdef JSS_SUP_THREADS
|
|
139 mixer->mutex = dmCreateMutex();
|
|
140 #endif
|
|
141 mixer->outFormat = outFormat;
|
|
142 mixer->outFreq = outFreq;
|
|
143 mixer->outChannels = outChannels;
|
|
144
|
|
145 mixer->jvmMixChannel_FW = jvmMixRoutines[mixerIdx].jvmMixChannel_FW;
|
|
146 mixer->jvmMixChannel_BW = jvmMixRoutines[mixerIdx].jvmMixChannel_BW;
|
|
147 mixer->jvmPostProcess = jvmMixRoutines[mixerIdx].jvmPostProcess;
|
|
148
|
|
149 // Allocate addBuffer
|
|
150 mixer->addBufSize = outChannels * outFreq;
|
|
151 mixer->addBuffer = dmCalloc(mixer->addBufSize, sizeof(Sint32));
|
|
152 if (mixer->addBuffer == NULL)
|
|
153 {
|
|
154 JSSERROR(DMERR_MALLOC, NULL,
|
|
155 "Could not allocate mixing addition buffer.\n");
|
|
156 }
|
|
157
|
|
158 // Initialize 8-bit volume table
|
|
159 for (v = jsetMinVol; v < jsetMaxVol; v++)
|
|
160 {
|
|
161 for (i = 0; i < 256; i++)
|
|
162 {
|
|
163 mixer->volTab8[v][i] = (v * (i - 128));
|
|
164 }
|
|
165 }
|
|
166
|
|
167 return mixer;
|
|
168 }
|
|
169
|
|
170
|
|
171 int jvmClose(JSSMixer * mixer)
|
|
172 {
|
|
173 if (mixer == NULL)
|
|
174 return DMERR_NULLPTR;
|
|
175
|
|
176 // Deallocate resources
|
|
177 #ifdef JSS_SUP_THREADS
|
|
178 dmDestroyMutex(mixer->mutex);
|
|
179 #endif
|
|
180 dmFree(mixer->addBuffer);
|
|
181
|
|
182 memset(mixer, 0, sizeof(JSSMixer));
|
|
183 dmFree(mixer);
|
|
184
|
|
185 return DMERR_OK;
|
|
186 }
|
|
187
|
|
188
|
|
189 int jvmGetSampleSize(JSSMixer *mixer)
|
|
190 {
|
|
191 int sampSize = 1;
|
|
192 assert(mixer);
|
|
193
|
|
194 switch (mixer->outChannels)
|
|
195 {
|
|
196 case JSS_AUDIO_STEREO:
|
|
197 case JSS_AUDIO_MONO:
|
|
198 sampSize = mixer->outChannels;
|
|
199 break;
|
|
200 default:
|
|
201 JSSERROR(DMERR_INVALID_ARGS, -1,
|
|
202 "outChannels=%d not stereo or mono!\n", mixer->outChannels);
|
|
203 break;
|
|
204 }
|
|
205
|
|
206 switch (mixer->outFormat)
|
|
207 {
|
|
208 case JSS_AUDIO_U16: sampSize *= sizeof(Uint16); break;
|
|
209 case JSS_AUDIO_S16: sampSize *= sizeof(Sint16); break;
|
|
210 case JSS_AUDIO_U8: sampSize *= sizeof(Uint8); break;
|
|
211 case JSS_AUDIO_S8: sampSize *= sizeof(Sint8); break;
|
|
212 default:
|
|
213 JSSERROR(DMERR_INVALID_ARGS, -1,
|
|
214 "outFormat=%d is not supported!\n", mixer->outFormat);
|
|
215 }
|
|
216
|
|
217 return sampSize;
|
|
218 }
|
|
219
|
|
220
|
|
221 int jvmGetSampleRes(JSSMixer *mixer)
|
|
222 {
|
|
223 int sampRes = 1;
|
|
224
|
|
225 assert(mixer);
|
|
226
|
|
227 switch (mixer->outFormat)
|
|
228 {
|
|
229 case JSS_AUDIO_U16: case JSS_AUDIO_S16: sampRes = 16; break;
|
|
230 case JSS_AUDIO_U8: case JSS_AUDIO_S8: sampRes = 8; break;
|
|
231 default:
|
|
232 JSSERROR(DMERR_INVALID_ARGS, -1,
|
|
233 "outFormat=%d is not supported!\n", mixer->outFormat);
|
|
234 }
|
|
235
|
|
236 return sampRes;
|
|
237 }
|
|
238
|
|
239
|
|
240 static void jvmMixChannel(JSSMixer *mixer, JSSChannel *chn, Sint32 *addBuffer, const int mixLength)
|
|
241 {
|
|
242 int mixDone = mixLength, mixResult;
|
|
243 Sint32 *ab = addBuffer;
|
|
244
|
|
245 if (!chn->chPlaying || chn->chMute)
|
|
246 return;
|
|
247
|
|
248 DBG("%s(%p, %d)\n", __FUNCTION__, chn, mixLength);
|
|
249
|
|
250 while (mixDone > 0)
|
|
251 {
|
|
252 if (chn->chDirection)
|
|
253 {
|
|
254 // Channel is playing FORWARDS
|
|
255 if (chn->chFlags & jsfLooped)
|
|
256 {
|
|
257 // Sample is looped
|
|
258 if (chn->chFlags & jsfBiDi)
|
|
259 {
|
|
260 // Bi-directional loop
|
|
261 if (FP_GETH(chn->chPos) >= chn->chLoopE)
|
|
262 {
|
|
263 FP_SETH(chn->chPos, chn->chLoopE - 1);
|
|
264 FP_SETL(chn->chPos, 0);
|
|
265 chn->chDirection = FALSE;
|
|
266 }
|
|
267 }
|
|
268 else
|
|
269 {
|
|
270 // Normal forward loop
|
|
271 if (FP_GETH(chn->chPos) >= chn->chLoopE)
|
|
272 {
|
|
273 FP_SETH(chn->chPos, chn->chLoopS /* + (FP_GETH(chn->chPos) - chn->chLoopE) */);
|
|
274 FP_SETL(chn->chPos, 0);
|
|
275 }
|
|
276 }
|
|
277 }
|
|
278 else
|
|
279 {
|
|
280 // Normal (non-looped) sample
|
|
281 if (FP_GETH(chn->chPos) >= chn->chSize)
|
|
282 {
|
|
283 chn->chPlaying = FALSE;
|
|
284 return;
|
|
285 }
|
|
286 }
|
|
287 }
|
|
288 else
|
|
289 {
|
|
290 // Channel is playing BACKWARDS
|
|
291 if (chn->chFlags & jsfLooped)
|
|
292 {
|
|
293 // Sample is looped
|
|
294 if (chn->chFlags & jsfBiDi)
|
|
295 {
|
|
296 // Bi-directional loop
|
|
297 if (FP_GETH(chn->chPos) <= chn->chLoopS)
|
|
298 {
|
|
299 FP_SETH(chn->chPos, chn->chLoopS);
|
|
300 FP_SETL(chn->chPos, 0);
|
|
301 chn->chDirection = TRUE;
|
|
302 }
|
|
303 }
|
|
304 else
|
|
305 {
|
|
306 // Normal forward loop
|
|
307 if (FP_GETH(chn->chPos) <= chn->chLoopS)
|
|
308 {
|
|
309 FP_SETH(chn->chPos, chn->chLoopE - 1);
|
|
310 FP_SETL(chn->chPos, 0);
|
|
311 }
|
|
312 }
|
|
313 }
|
|
314 else
|
|
315 {
|
|
316 // Normal (non-looped) sample
|
|
317 if (FP_GETH(chn->chPos) <= 0)
|
|
318 {
|
|
319 chn->chPlaying = FALSE;
|
|
320 return;
|
|
321 }
|
|
322 }
|
|
323 }
|
|
324
|
|
325 // Call the mixing innerloop functions
|
|
326 if (chn->chDirection)
|
|
327 {
|
|
328 DBG("MIX_FW[%p : %d : ", ab, mixDone);
|
|
329 if (chn->chFlags & jsfLooped)
|
|
330 {
|
|
331 DBG("%d (%x)] {loop}\n", chn->chLoopE, chn->chLoopE);
|
|
332 mixResult = mixer->jvmMixChannel_FW((void *) mixer, chn,
|
|
333 ab, mixDone, chn->chLoopE);
|
|
334 }
|
|
335 else
|
|
336 {
|
|
337 DBG("%d (%x)]\n", chn->chSize, chn->chSize);
|
|
338 mixResult = mixer->jvmMixChannel_FW((void *) mixer, chn,
|
|
339 ab, mixDone, chn->chSize);
|
|
340 }
|
|
341 }
|
|
342 else
|
|
343 {
|
|
344 DBG("MIX_BW[%p : %d : ", ab, mixDone);
|
|
345 if (chn->chFlags & jsfLooped)
|
|
346 {
|
|
347 DBG("%d (%x)] {loop}\n", chn->chLoopS, chn->chLoopS);
|
|
348 mixResult = mixer->jvmMixChannel_BW(mixer, chn,
|
|
349 ab, mixDone, chn->chLoopS);
|
|
350 }
|
|
351 else
|
|
352 {
|
|
353 DBG("%d (%x)]\n", 0, 0);
|
|
354 mixResult = mixer->jvmMixChannel_BW(mixer, chn,
|
|
355 ab, mixDone, 0);
|
|
356 }
|
|
357 }
|
|
358
|
|
359 mixDone -= mixResult;
|
|
360 ab += mixResult * mixer->outChannels;
|
|
361 }
|
|
362
|
|
363 #ifdef JSS_DEBUG
|
|
364 if (mixDone < 0)
|
|
365 JSSWARNING(DMERR_BOUNDS,, "mixDone < 0 in mixing logic loop.\n");
|
|
366 #endif
|
|
367 }
|
|
368
|
|
369
|
|
370 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength)
|
|
371 {
|
|
372 int i, blockLength, mixLeft;
|
|
373 Sint32 *ab;
|
|
374
|
|
375 JSS_LOCK(mixer);
|
|
376
|
|
377 assert(mixer != NULL);
|
|
378 assert(mixBuffer != NULL);
|
|
379 assert(mixLength > 0);
|
|
380 assert(mixLength * mixer->outChannels < mixer->addBufSize);
|
|
381
|
|
382 // Clear mixer->addBuffer
|
|
383 memset(mixer->addBuffer, 0, mixLength * mixer->outChannels * sizeof(Sint32));
|
|
384
|
|
385 ab = mixer->addBuffer;
|
|
386 mixLeft = mixLength;
|
|
387 while (mixLeft > 0)
|
|
388 {
|
|
389 // Check for callbacks
|
|
390 blockLength = mixLeft;
|
|
391
|
|
392 if (mixer->cbFunction)
|
|
393 {
|
|
394 if (mixer->cbCounter <= 0)
|
|
395 {
|
|
396 mixer->cbFunction(mixer, mixer->cbData);
|
|
397 mixer->cbCounter = mixer->cbFreq;
|
|
398 }
|
|
399
|
|
400 if (mixer->cbCounter < blockLength)
|
|
401 blockLength = mixer->cbCounter;
|
|
402 }
|
|
403
|
|
404 // Do mixing
|
|
405 for (i = 0; i < jsetNChannels; i++)
|
|
406 {
|
|
407 JSSChannel *chn = &(mixer->channels[i]);
|
|
408 if (chn->chPlaying && !chn->chMute)
|
|
409 jvmMixChannel(mixer, chn, ab, blockLength);
|
|
410 }
|
|
411
|
|
412 /*
|
|
413 if (chn->chPlaying)
|
|
414 {
|
|
415 if (!chn->chMute)
|
|
416 jvmMixChannel(mixer, chn, ab, blockLength);
|
|
417 else
|
|
418 jvmAdvanceChannel(mixer, chn, blockLength);
|
|
419 }
|
|
420 */
|
|
421
|
|
422 ab += blockLength * mixer->outChannels;
|
|
423 mixLeft -= blockLength;
|
|
424 mixer->cbCounter -= blockLength;
|
|
425 }
|
|
426
|
|
427 // Post-process
|
|
428 mixer->jvmPostProcess(mixer->addBuffer, mixBuffer, mixLength * mixer->outChannels);
|
|
429
|
|
430 JSS_UNLOCK(mixer);
|
|
431 }
|
|
432
|
|
433
|
|
434 int jvmSetCallback(JSSMixer * mixer, void (*cbFunction) (void *, void *), void *cbData)
|
|
435 {
|
|
436 assert(mixer);
|
|
437
|
|
438 if (cbFunction == NULL)
|
|
439 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, "NULL pointer given as cbFunction");
|
|
440
|
|
441 JSS_LOCK(mixer);
|
|
442
|
|
443 mixer->cbFunction = cbFunction;
|
|
444 mixer->cbData = cbData;
|
|
445
|
|
446 JSS_UNLOCK(mixer);
|
|
447
|
|
448 return DMERR_OK;
|
|
449 }
|
|
450
|
|
451
|
|
452 void jvmRemoveCallback(JSSMixer * mixer)
|
|
453 {
|
|
454 assert(mixer);
|
|
455
|
|
456 JSS_LOCK(mixer);
|
|
457
|
|
458 mixer->cbFunction = NULL;
|
|
459 mixer->cbData = NULL;
|
|
460 mixer->cbFreq = mixer->cbCounter = 0;
|
|
461
|
|
462 JSS_UNLOCK(mixer);
|
|
463 }
|
|
464
|
|
465
|
|
466 int jvmSetCallbackFreq(JSSMixer * mixer, const int cbFreq)
|
|
467 {
|
|
468 assert(mixer);
|
|
469
|
|
470 if ((cbFreq < 1) || (cbFreq >= mixer->outFreq))
|
|
471 JSSERROR(DMERR_INVALID_ARGS, DMERR_INVALID_ARGS,
|
|
472 "Invalid callback frequency given (%i / %i)\n", cbFreq, mixer->outFreq);
|
|
473
|
|
474 JSS_LOCK(mixer);
|
|
475
|
|
476 mixer->cbFreq = (mixer->outFreq / cbFreq);
|
|
477 mixer->cbCounter = 0;
|
|
478
|
|
479 //fprintf(stderr, "set(outFreq = %d, cbFreq = %d) = %d\n", mixer->outFreq, cbFreq, mixer->cbFreq);
|
|
480
|
|
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
|
|
504 void jvmSetSample(JSSMixer * mixer, const int channel,
|
|
505 void *data, const Uint32 size, const Uint32 loopS,
|
|
506 const Uint32 loopE, const int flags)
|
|
507 {
|
|
508 JSSChannel *c;
|
|
509
|
|
510 JSS_LOCK(mixer);
|
|
511 c = &mixer->channels[channel];
|
|
512
|
|
513 c->chData = data;
|
|
514 c->chSize = size;
|
|
515 c->chLoopS = loopS;
|
|
516 c->chLoopE = loopE;
|
|
517 c->chFlags = flags;
|
|
518 c->chDirection = TRUE;
|
|
519 c->chPrevL = c->chPrevR = 0;
|
|
520 c->chPos.dw = c->chDeltaO.dw = 0;
|
|
521
|
|
522 JSS_UNLOCK(mixer);
|
|
523 }
|
|
524
|
|
525
|
|
526 void jvmSetFreq(JSSMixer * mixer, const int channel, const int freq)
|
|
527 {
|
|
528 JSS_LOCK(mixer);
|
|
529
|
|
530 mixer->channels[channel].chFreq = freq;
|
|
531
|
|
532 if (mixer->outFreq > 0)
|
|
533 {
|
|
534 DMFixedPoint a, b;
|
|
535 FP_SETHL(a, freq, 0);
|
|
536 FP_CONV(b, mixer->outFreq);
|
|
537 FP_DIV_R(mixer->channels[channel].chDeltaO, a, b);
|
|
538 }
|
|
539 else
|
|
540 {
|
|
541 FP_SET(mixer->channels[channel].chDeltaO, 0);
|
|
542 }
|
|
543
|
|
544 JSS_UNLOCK(mixer);
|
|
545 }
|
|
546
|
|
547
|
|
548 int jvmGetFreq(JSSMixer * mixer, const int channel)
|
|
549 {
|
|
550 int tmp;
|
|
551
|
|
552 JSS_LOCK(mixer);
|
|
553 tmp = mixer->channels[channel].chFreq;
|
|
554 JSS_UNLOCK(mixer);
|
|
555
|
|
556 return tmp;
|
|
557 }
|
|
558
|
|
559
|
|
560 void jvmSetVolume(JSSMixer * mixer, const int channel, const int volume)
|
|
561 {
|
|
562 JSS_LOCK(mixer);
|
|
563 mixer->channels[channel].chVolume = volume;
|
|
564 JSS_UNLOCK(mixer);
|
|
565 }
|
|
566
|
|
567
|
|
568 int jvmGetVolume(JSSMixer * mixer, const int channel)
|
|
569 {
|
|
570 int tmp;
|
|
571
|
|
572 JSS_LOCK(mixer);
|
|
573 tmp = mixer->channels[channel].chVolume;
|
|
574 JSS_UNLOCK(mixer);
|
|
575
|
|
576 return tmp;
|
|
577 }
|
|
578
|
|
579
|
|
580 void jvmSetPos(JSSMixer * mixer, const int channel, const Uint32 pos)
|
|
581 {
|
|
582 JSS_LOCK(mixer);
|
|
583 FP_SETH(mixer->channels[channel].chPos, pos);
|
|
584 FP_SETL(mixer->channels[channel].chPos, 0);
|
|
585 JSS_UNLOCK(mixer);
|
|
586 }
|
|
587
|
|
588
|
|
589 Uint32 jvmGetPos(JSSMixer * mixer, const int channel)
|
|
590 {
|
|
591 Uint32 tmp;
|
|
592
|
|
593 JSS_LOCK(mixer);
|
|
594 tmp = FP_GETH(mixer->channels[channel].chPos);
|
|
595 JSS_UNLOCK(mixer);
|
|
596
|
|
597 return tmp;
|
|
598 }
|
|
599
|
|
600
|
|
601 void jvmSetPan(JSSMixer * mixer, const int channel, const int panning)
|
|
602 {
|
|
603 JSS_LOCK(mixer);
|
|
604 mixer->channels[channel].chPanning = panning;
|
|
605 JSS_UNLOCK(mixer);
|
|
606 }
|
|
607
|
|
608
|
|
609 int jvmGetPan(JSSMixer * mixer, const int channel)
|
|
610 {
|
|
611 int tmp;
|
|
612
|
|
613 JSS_LOCK(mixer);
|
|
614 tmp = mixer->channels[channel].chPanning;
|
|
615 JSS_UNLOCK(mixer);
|
|
616
|
|
617 return tmp;
|
|
618 }
|
|
619
|
|
620
|
|
621 void jvmMute(JSSMixer * mixer, const int channel, const BOOL mute)
|
|
622 {
|
|
623 JSS_LOCK(mixer);
|
|
624 mixer->channels[channel].chMute = mute;
|
|
625 JSS_UNLOCK(mixer);
|
|
626 }
|
|
627
|
|
628
|
|
629 void jvmClear(JSSMixer * mixer, const int channel)
|
|
630 {
|
|
631 JSS_LOCK(mixer);
|
|
632 memset(&mixer->channels[channel], 0, sizeof(JSSChannel));
|
|
633 JSS_UNLOCK(mixer);
|
|
634 }
|
|
635
|
|
636
|
|
637 void jvmSetGlobalVol(JSSMixer * mixer, const int volume)
|
|
638 {
|
|
639 JSS_LOCK(mixer);
|
|
640 mixer->globalVol = volume;
|
|
641 JSS_UNLOCK(mixer);
|
|
642 }
|
|
643
|
|
644
|
|
645 int jvmGetGlobalVol(JSSMixer * mixer)
|
|
646 {
|
|
647 int tmp;
|
|
648
|
|
649 JSS_LOCK(mixer);
|
|
650 tmp = mixer->globalVol;
|
|
651 JSS_UNLOCK(mixer);
|
|
652
|
|
653 return tmp;
|
|
654 }
|