comparison jssmix.c @ 51:36e2f910219c

A non-working implementation of floating point audio mixing.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 03:48:21 +0300
parents 033c660c25f5
children 1d17ecc5486c
comparison
equal deleted inserted replaced
50:4cbdaa3f5d74 51:36e2f910219c
25 typedef struct 25 typedef struct
26 { 26 {
27 int mixerID; 27 int mixerID;
28 int outFormat; 28 int outFormat;
29 int outChannels; 29 int outChannels;
30 int (*jvmMixChannel_FW)(JSSMixer *, JSSChannel *, Sint32 *, const int, const Sint32); 30
31 int (*jvmMixChannel_BW)(JSSMixer *, JSSChannel *, Sint32 *, const int, const Sint32); 31 int (*jvmMixChannel_FW)(JSSMixer *, JSSChannel *, JMIXER_ADDBUF_TYPE *, const int, const Sint32);
32 void (*jvmPostProcess)(Sint32 *, void *, const int); 32 int (*jvmMixChannel_BW)(JSSMixer *, JSSChannel *, JMIXER_ADDBUF_TYPE *, const int, const Sint32);
33 void (*jvmPostProcess)(JMIXER_ADDBUF_TYPE *, void *, const int);
33 } JSSMixingRoutine; 34 } JSSMixingRoutine;
34 35
35 36
36 /* This table should be sorted from fastest to slowest, e.g. MMX/x86 37 /* This table should be sorted from fastest to slowest, e.g. MMX/x86
37 * optimized routines first, pure C versions last. 38 * optimized routines first, pure C versions last.
146 mixer->jvmMixChannel_BW = jvmMixRoutines[mixerIdx].jvmMixChannel_BW; 147 mixer->jvmMixChannel_BW = jvmMixRoutines[mixerIdx].jvmMixChannel_BW;
147 mixer->jvmPostProcess = jvmMixRoutines[mixerIdx].jvmPostProcess; 148 mixer->jvmPostProcess = jvmMixRoutines[mixerIdx].jvmPostProcess;
148 149
149 // Allocate addBuffer 150 // Allocate addBuffer
150 mixer->addBufSize = outChannels * outFreq; 151 mixer->addBufSize = outChannels * outFreq;
151 mixer->addBuffer = dmCalloc(mixer->addBufSize, sizeof(Sint32)); 152 mixer->addBuffer = dmCalloc(mixer->addBufSize, sizeof(JMIXER_ADDBUF_TYPE));
152 if (mixer->addBuffer == NULL) 153 if (mixer->addBuffer == NULL)
153 { 154 {
154 JSSERROR(DMERR_MALLOC, NULL, 155 JSSERROR(DMERR_MALLOC, NULL,
155 "Could not allocate mixing addition buffer.\n"); 156 "Could not allocate mixing addition buffer.\n");
156 } 157 }
226 227
227 return sampRes; 228 return sampRes;
228 } 229 }
229 230
230 231
231 static void jvmMixChannel(JSSMixer *mixer, JSSChannel *chn, Sint32 *addBuffer, const int mixLength) 232 static void jvmMixChannel(JSSMixer *mixer, JSSChannel *chn, JMIXER_ADDBUF_TYPE *addBuffer, const int mixLength)
232 { 233 {
233 int mixDone = mixLength, mixResult; 234 int mixDone = mixLength, mixResult;
234 Sint32 *ab = addBuffer; 235 JMIXER_ADDBUF_TYPE *ab = addBuffer;
235 236
236 if (!chn->chPlaying || chn->chMute) 237 if (!chn->chPlaying || chn->chMute)
237 return; 238 return;
238 239
239 DBG("%s(%p, %d)\n", __FUNCTION__, chn, mixLength); 240 DBG("%s(%p, %d)\n", __FUNCTION__, chn, mixLength);
359 360
360 361
361 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength) 362 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength)
362 { 363 {
363 int i, blockLength, mixLeft; 364 int i, blockLength, mixLeft;
364 Sint32 *ab; 365 JMIXER_ADDBUF_TYPE *ab;
365 366
366 JSS_LOCK(mixer); 367 JSS_LOCK(mixer);
367 368
368 assert(mixer != NULL); 369 assert(mixer != NULL);
369 assert(mixBuffer != NULL); 370 assert(mixBuffer != NULL);
370 assert(mixLength > 0); 371 assert(mixLength > 0);
371 assert(mixLength * mixer->outChannels < mixer->addBufSize); 372 assert(mixLength * mixer->outChannels < mixer->addBufSize);
372 373
373 // Clear mixer->addBuffer 374 // Clear mixer->addBuffer
374 memset(mixer->addBuffer, 0, mixLength * mixer->outChannels * sizeof(Sint32)); 375 memset(mixer->addBuffer, 0, mixLength * mixer->outChannels * sizeof(JMIXER_ADDBUF_TYPE));
375 376
376 ab = mixer->addBuffer; 377 ab = mixer->addBuffer;
377 mixLeft = mixLength; 378 mixLeft = mixLength;
378 while (mixLeft > 0) 379 while (mixLeft > 0)
379 { 380 {