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