Mercurial > hg > dmlib
annotate minijss/jssmix.c @ 1163:aa3738b121d1
Bump copyright years.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Mar 2015 07:19:05 +0200 |
parents | e22d4ceb6414 |
children | 848a88ce7a57 |
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 #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 |
287
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_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
|
32 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
|
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; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
73 |
0 | 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 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
81 |
0 | 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 |
843
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
91 // Sanity check |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
92 if (jvmNMixRoutines == 0) |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
93 { |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
94 JSSERROR(DMERR_INTERNAL, NULL, |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
95 "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
|
96 return NULL; |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
97 } |
68453f04964d
Add a better error for no mixing routines compiled in.
Matti Hamalainen <ccr@tnsp.org>
parents:
809
diff
changeset
|
98 |
0 | 99 // Check settings |
100 if (outChannels < 1) | |
101 { | |
102 JSSERROR(DMERR_INVALID_ARGS, NULL, | |
103 "Invalid number of channels %d\n", outChannels); | |
104 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
105 |
0 | 106 if (outFreq < 4000) |
107 { | |
108 JSSERROR(DMERR_INVALID_ARGS, NULL, | |
109 "Invalid mixing frequency %d\n", outFreq); | |
110 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
111 |
0 | 112 /* Select mixing routines: |
113 * Here we try to choose the most fitting mixing routines | |
114 * from the compiled in routines, unless caller is forcing | |
115 * us to select specific ones. | |
116 */ | |
117 if (mixerID == JMIX_AUTO) | |
118 { | |
119 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_SSE); | |
120 if (mixerIdx < 0) | |
121 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_MMX); | |
122 if (mixerIdx < 0) | |
123 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, JMIX_AUTO); | |
124 } | |
125 else | |
126 { | |
127 mixerIdx = jvmFindMixRoutine(outFormat, outChannels, mixerID); | |
128 } | |
129 | |
130 if (mixerIdx < 0) | |
131 { | |
132 JSSERROR(DMERR_INVALID_ARGS, NULL, | |
133 "Could not find mixing routine for outFormat=%d, outChannels=%d, outFreq=%d.\n", | |
134 outFormat, outChannels, outFreq); | |
135 return NULL; | |
136 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
137 |
0 | 138 // Allocate a mixer device structure |
139 mixer = dmMalloc0(sizeof(JSSMixer)); | |
140 if (mixer == NULL) | |
141 { | |
142 JSSERROR(DMERR_MALLOC, NULL, | |
143 "Could not allocate mixing device structure.\n"); | |
144 } | |
145 | |
146 // Initialize variables | |
147 #ifdef JSS_SUP_THREADS | |
148 mixer->mutex = dmCreateMutex(); | |
149 #endif | |
150 mixer->outFormat = outFormat; | |
151 mixer->outFreq = outFreq; | |
152 mixer->outChannels = outChannels; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
153 |
0 | 154 mixer->jvmMixChannel_FW = jvmMixRoutines[mixerIdx].jvmMixChannel_FW; |
155 mixer->jvmMixChannel_BW = jvmMixRoutines[mixerIdx].jvmMixChannel_BW; | |
156 mixer->jvmPostProcess = jvmMixRoutines[mixerIdx].jvmPostProcess; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
157 |
0 | 158 // Allocate addBuffer |
291 | 159 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
|
160 mixer->addBuffer = dmMalloc(mixer->addBufSize * sizeof(JMIXER_ADDBUF_TYPE)); |
0 | 161 if (mixer->addBuffer == NULL) |
162 { | |
163 JSSERROR(DMERR_MALLOC, NULL, | |
164 "Could not allocate mixing addition buffer.\n"); | |
165 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
166 |
0 | 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); | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
193 |
0 | 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 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
205 |
0 | 206 switch (mixer->outFormat) |
207 { | |
208 case JSS_AUDIO_U16: sampSize *= sizeof(Uint16); break; | |
209 case JSS_AUDIO_S16: sampSize *= sizeof(Sint16); break; | |
54 | 210 case JSS_AUDIO_U8: sampSize *= sizeof(Uint8); break; |
211 case JSS_AUDIO_S8: sampSize *= sizeof(Sint8); break; | |
0 | 212 default: |
213 JSSERROR(DMERR_INVALID_ARGS, -1, | |
214 "outFormat=%d is not supported!\n", mixer->outFormat); | |
215 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
216 |
0 | 217 return sampSize; |
218 } | |
219 | |
220 | |
221 int jvmGetSampleRes(JSSMixer *mixer) | |
222 { | |
54 | 223 int sampRes = 0; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
224 |
0 | 225 assert(mixer); |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
226 |
0 | 227 switch (mixer->outFormat) |
228 { | |
229 case JSS_AUDIO_U16: case JSS_AUDIO_S16: sampRes = 16; break; | |
54 | 230 case JSS_AUDIO_U8: case JSS_AUDIO_S8: sampRes = 8; break; |
0 | 231 default: |
232 JSSERROR(DMERR_INVALID_ARGS, -1, | |
233 "outFormat=%d is not supported!\n", mixer->outFormat); | |
234 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
235 |
0 | 236 return sampRes; |
237 } | |
238 | |
239 | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
240 static void jvmMixChannel(JSSMixer *mixer, JSSChannel *chn, JMIXER_ADDBUF_TYPE *addBuffer, const int mixLength) |
0 | 241 { |
242 int mixDone = mixLength, mixResult; | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
243 JMIXER_ADDBUF_TYPE *ab = addBuffer; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
244 |
0 | 245 if (!chn->chPlaying || chn->chMute) |
246 return; | |
247 | |
248 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
|
249 |
0 | 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 | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
261 if (chn->chPos.dw >= chn->chLoopE.dw) |
0 | 262 { |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
263 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
|
264 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
|
265 FP_SUB_R(chn->chPos, end, chn->chPos); |
0 | 266 chn->chDirection = FALSE; |
267 } | |
268 } | |
269 else | |
270 { | |
271 // 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
|
272 if (chn->chPos.dw >= chn->chLoopE.dw) |
0 | 273 { |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
274 DMFixedPoint diff; |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
275 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
|
276 FP_ADD_R(chn->chPos, chn->chLoopS, diff); |
0 | 277 } |
278 } | |
279 } | |
280 else | |
281 { | |
282 // 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
|
283 if (chn->chPos.dw >= chn->chSize.dw) |
0 | 284 { |
285 chn->chPlaying = FALSE; | |
286 return; | |
287 } | |
288 } | |
289 } | |
290 else | |
291 { | |
292 // Channel is playing BACKWARDS | |
293 if (chn->chFlags & jsfLooped) | |
294 { | |
295 // Sample is looped | |
296 if (chn->chFlags & jsfBiDi) | |
297 { | |
298 // 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
|
299 if (chn->chPos.dw <= chn->chLoopS.dw) |
0 | 300 { |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
301 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
|
302 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
|
303 FP_SUB_R(chn->chPos, start, chn->chPos); |
0 | 304 chn->chDirection = TRUE; |
305 } | |
306 } | |
307 else | |
308 { | |
309 // 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
|
310 if (chn->chPos.dw <= chn->chLoopS.dw) |
0 | 311 { |
158
255da2a698fe
Improve loop handling in the mixer.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
312 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
|
313 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
|
314 FP_ADD(chn->chPos, diff); |
0 | 315 } |
316 } | |
317 } | |
318 else | |
319 { | |
320 // 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
|
321 if (chn->chPos.dw <= 0) |
0 | 322 { |
323 chn->chPlaying = FALSE; | |
324 return; | |
325 } | |
326 } | |
327 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
328 |
0 | 329 // Call the mixing innerloop functions |
330 if (chn->chDirection) | |
331 { | |
332 DBG("MIX_FW[%p : %d : ", ab, mixDone); | |
333 if (chn->chFlags & jsfLooped) | |
334 { | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
335 DBG("%d (%x)] {loop}\n", FP_GETH32(chn->chLoopE), FP_GETH32(chn->chLoopE)); |
0 | 336 mixResult = mixer->jvmMixChannel_FW((void *) mixer, chn, |
337 ab, mixDone, chn->chLoopE); | |
338 } | |
339 else | |
340 { | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
341 DBG("%d (%x)]\n", FP_GETH32(chn->chSize), FP_GETH32(chn->chSize)); |
0 | 342 mixResult = mixer->jvmMixChannel_FW((void *) mixer, chn, |
343 ab, mixDone, chn->chSize); | |
344 } | |
345 } | |
346 else | |
347 { | |
348 DBG("MIX_BW[%p : %d : ", ab, mixDone); | |
349 if (chn->chFlags & jsfLooped) | |
350 { | |
351 DBG("%d (%x)] {loop}\n", chn->chLoopS, chn->chLoopS); | |
352 mixResult = mixer->jvmMixChannel_BW(mixer, chn, | |
353 ab, mixDone, chn->chLoopS); | |
354 } | |
355 else | |
356 { | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
357 static const DMFixedPoint zero = { 0 }; |
0 | 358 DBG("%d (%x)]\n", 0, 0); |
359 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
|
360 ab, mixDone, zero); |
0 | 361 } |
362 } | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
363 |
0 | 364 mixDone -= mixResult; |
365 ab += mixResult * mixer->outChannels; | |
366 } | |
367 | |
368 #ifdef JSS_DEBUG | |
369 if (mixDone < 0) | |
370 JSSWARNING(DMERR_BOUNDS,, "mixDone < 0 in mixing logic loop.\n"); | |
371 #endif | |
372 } | |
373 | |
374 | |
375 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength) | |
376 { | |
377 int i, blockLength, mixLeft; | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
378 JMIXER_ADDBUF_TYPE *ab; |
0 | 379 |
380 JSS_LOCK(mixer); | |
381 | |
382 assert(mixer != NULL); | |
383 assert(mixBuffer != NULL); | |
384 assert(mixLength > 0); | |
52 | 385 assert(mixLength * mixer->outChannels <= mixer->addBufSize); |
0 | 386 |
387 // Clear mixer->addBuffer | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
388 memset(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
|
389 |
0 | 390 ab = mixer->addBuffer; |
391 mixLeft = mixLength; | |
392 while (mixLeft > 0) | |
393 { | |
394 // Check for callbacks | |
395 blockLength = mixLeft; | |
396 | |
397 if (mixer->cbFunction) | |
398 { | |
399 if (mixer->cbCounter <= 0) | |
400 { | |
401 mixer->cbFunction(mixer, mixer->cbData); | |
402 mixer->cbCounter = mixer->cbFreq; | |
403 } | |
404 | |
405 if (mixer->cbCounter < blockLength) | |
406 blockLength = mixer->cbCounter; | |
407 } | |
408 | |
409 // Do mixing | |
410 for (i = 0; i < jsetNChannels; i++) | |
411 { | |
412 JSSChannel *chn = &(mixer->channels[i]); | |
413 if (chn->chPlaying && !chn->chMute) | |
414 jvmMixChannel(mixer, chn, ab, blockLength); | |
415 } | |
416 | |
417 /* | |
418 if (chn->chPlaying) | |
419 { | |
420 if (!chn->chMute) | |
421 jvmMixChannel(mixer, chn, ab, blockLength); | |
422 else | |
423 jvmAdvanceChannel(mixer, chn, blockLength); | |
424 } | |
425 */ | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
426 |
0 | 427 ab += blockLength * mixer->outChannels; |
428 mixLeft -= blockLength; | |
429 mixer->cbCounter -= blockLength; | |
430 } | |
431 | |
432 // Post-process | |
433 mixer->jvmPostProcess(mixer->addBuffer, mixBuffer, mixLength * mixer->outChannels); | |
434 | |
435 JSS_UNLOCK(mixer); | |
436 } | |
437 | |
438 | |
439 int jvmSetCallback(JSSMixer * mixer, void (*cbFunction) (void *, void *), void *cbData) | |
440 { | |
441 assert(mixer); | |
442 | |
443 if (cbFunction == NULL) | |
444 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, "NULL pointer given as cbFunction"); | |
445 | |
446 JSS_LOCK(mixer); | |
447 | |
448 mixer->cbFunction = cbFunction; | |
449 mixer->cbData = cbData; | |
450 | |
451 JSS_UNLOCK(mixer); | |
452 | |
453 return DMERR_OK; | |
454 } | |
455 | |
456 | |
457 void jvmRemoveCallback(JSSMixer * mixer) | |
458 { | |
459 assert(mixer); | |
460 | |
461 JSS_LOCK(mixer); | |
462 | |
463 mixer->cbFunction = NULL; | |
464 mixer->cbData = NULL; | |
465 mixer->cbFreq = mixer->cbCounter = 0; | |
466 | |
467 JSS_UNLOCK(mixer); | |
468 } | |
469 | |
470 | |
471 int jvmSetCallbackFreq(JSSMixer * mixer, const int cbFreq) | |
472 { | |
473 assert(mixer); | |
474 | |
475 JSS_LOCK(mixer); | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
476 |
186
dc22e3f77c9a
Fix tempo (callback frequency) calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
477 mixer->cbFreq = cbFreq; |
0 | 478 mixer->cbCounter = 0; |
479 | |
480 //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
|
481 |
0 | 482 JSS_UNLOCK(mixer); |
483 return DMERR_OK; | |
484 } | |
485 | |
486 | |
487 /* Channel manipulation routines | |
488 */ | |
489 void jvmPlay(JSSMixer * mixer, const int channel) | |
490 { | |
491 JSS_LOCK(mixer); | |
492 mixer->channels[channel].chPlaying = TRUE; | |
493 JSS_UNLOCK(mixer); | |
494 } | |
495 | |
496 | |
497 void jvmStop(JSSMixer * mixer, const int channel) | |
498 { | |
499 JSS_LOCK(mixer); | |
500 mixer->channels[channel].chPlaying = FALSE; | |
501 JSS_UNLOCK(mixer); | |
502 } | |
503 | |
504 | |
227
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
505 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
|
506 { |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
507 JSSChannel *c; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
508 |
227
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
509 JSS_LOCK(mixer); |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
510 c = &mixer->channels[channel]; |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
511 |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
512 c->chDirection = TRUE; |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
513 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
|
514 |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
515 JSS_UNLOCK(mixer); |
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 |
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
518 |
0 | 519 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
|
520 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
|
521 const Sint32 loopE, const int flags) |
0 | 522 { |
523 JSSChannel *c; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
524 |
0 | 525 JSS_LOCK(mixer); |
526 c = &mixer->channels[channel]; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
527 |
287
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->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
|
529 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
|
530 FP_SETHL(c->chLoopE, loopE, 0); |
54 | 531 c->chData = data; |
532 c->chFlags = flags; | |
0 | 533 c->chDirection = TRUE; |
54 | 534 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
|
535 |
0 | 536 JSS_UNLOCK(mixer); |
537 } | |
538 | |
539 | |
540 void jvmSetFreq(JSSMixer * mixer, const int channel, const int freq) | |
541 { | |
542 JSS_LOCK(mixer); | |
543 | |
544 mixer->channels[channel].chFreq = freq; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
545 |
0 | 546 if (mixer->outFreq > 0) |
547 { | |
548 DMFixedPoint a, b; | |
549 FP_SETHL(a, freq, 0); | |
550 FP_CONV(b, mixer->outFreq); | |
551 FP_DIV_R(mixer->channels[channel].chDeltaO, a, b); | |
552 } | |
553 else | |
554 { | |
555 FP_SET(mixer->channels[channel].chDeltaO, 0); | |
556 } | |
557 | |
558 JSS_UNLOCK(mixer); | |
559 } | |
560 | |
561 | |
562 int jvmGetFreq(JSSMixer * mixer, const int channel) | |
563 { | |
564 int tmp; | |
565 | |
566 JSS_LOCK(mixer); | |
567 tmp = mixer->channels[channel].chFreq; | |
568 JSS_UNLOCK(mixer); | |
569 | |
570 return tmp; | |
571 } | |
572 | |
573 | |
574 void jvmSetVolume(JSSMixer * mixer, const int channel, const int volume) | |
575 { | |
576 JSS_LOCK(mixer); | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
577 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
|
578 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
|
579 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
|
580 JSS_UNLOCK(mixer); |
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 |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
583 |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
584 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
|
585 { |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
586 int tmp; |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
587 DMFixedPoint a, b; |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
588 JSS_LOCK(mixer); |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
589 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
|
590 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
591 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
|
592 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
|
593 |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
594 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
|
595 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
|
596 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
|
597 |
0 | 598 JSS_UNLOCK(mixer); |
599 } | |
600 | |
601 | |
602 int jvmGetVolume(JSSMixer * mixer, const int channel) | |
603 { | |
604 int tmp; | |
605 | |
606 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
|
607 tmp = FP_GETH32(mixer->channels[channel].chVolume); |
0 | 608 JSS_UNLOCK(mixer); |
609 | |
610 return tmp; | |
611 } | |
612 | |
613 | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
614 void jvmSetPos(JSSMixer * mixer, const int channel, const Sint32 pos) |
0 | 615 { |
616 JSS_LOCK(mixer); | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
617 FP_SETHL(mixer->channels[channel].chPos, pos, 0); |
0 | 618 JSS_UNLOCK(mixer); |
619 } | |
620 | |
621 | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
622 Sint32 jvmGetPos(JSSMixer * mixer, const int channel) |
0 | 623 { |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
624 Sint32 tmp; |
0 | 625 |
626 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
|
627 tmp = FP_GETH32(mixer->channels[channel].chPos); |
0 | 628 JSS_UNLOCK(mixer); |
629 | |
630 return tmp; | |
631 } | |
632 | |
633 | |
634 void jvmSetPan(JSSMixer * mixer, const int channel, const int panning) | |
635 { | |
636 JSS_LOCK(mixer); | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
637 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
|
638 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
|
639 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
|
640 JSS_UNLOCK(mixer); |
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 |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
643 |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
644 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
|
645 { |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
646 int tmp; |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
647 DMFixedPoint a, b; |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
648 JSS_LOCK(mixer); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
649 |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
650 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
|
651 |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
843
diff
changeset
|
652 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
|
653 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
|
654 |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
655 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
|
656 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
|
657 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
|
658 |
0 | 659 JSS_UNLOCK(mixer); |
660 } | |
661 | |
662 | |
663 int jvmGetPan(JSSMixer * mixer, const int channel) | |
664 { | |
665 int tmp; | |
666 | |
667 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
|
668 tmp = FP_GETH32(mixer->channels[channel].chPanning); |
0 | 669 JSS_UNLOCK(mixer); |
670 | |
671 return tmp; | |
672 } | |
673 | |
674 | |
675 void jvmMute(JSSMixer * mixer, const int channel, const BOOL mute) | |
676 { | |
677 JSS_LOCK(mixer); | |
678 mixer->channels[channel].chMute = mute; | |
679 JSS_UNLOCK(mixer); | |
680 } | |
681 | |
682 | |
141
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
683 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
|
684 { |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
685 BOOL tmp; |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
686 |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
687 JSS_LOCK(mixer); |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
688 tmp = mixer->channels[channel].chMute; |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
689 JSS_UNLOCK(mixer); |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
690 |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
691 return tmp; |
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 |
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
694 |
0 | 695 void jvmClear(JSSMixer * mixer, const int channel) |
696 { | |
697 JSS_LOCK(mixer); | |
698 memset(&mixer->channels[channel], 0, sizeof(JSSChannel)); | |
699 JSS_UNLOCK(mixer); | |
700 } | |
701 | |
702 | |
703 void jvmSetGlobalVol(JSSMixer * mixer, const int volume) | |
704 { | |
705 JSS_LOCK(mixer); | |
706 mixer->globalVol = volume; | |
707 JSS_UNLOCK(mixer); | |
708 } | |
709 | |
710 | |
711 int jvmGetGlobalVol(JSSMixer * mixer) | |
712 { | |
713 int tmp; | |
714 | |
715 JSS_LOCK(mixer); | |
716 tmp = mixer->globalVol; | |
717 JSS_UNLOCK(mixer); | |
718 | |
719 return tmp; | |
720 } |