diff jmix_c_in.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 8725853609db
line wrap: on
line diff
--- a/jmix_c_in.c	Mon Oct 01 03:46:10 2012 +0300
+++ b/jmix_c_in.c	Mon Oct 01 03:48:21 2012 +0300
@@ -7,10 +7,17 @@
 //#define JMIXER_DEBUG fprintf(stderr, "[%.8x:%.8x / %.8x]: %d\n", FP_GETH(tmpPos), FP_GETL(tmpPos), endPos, sp[FP_GETH(tmpPos)]);
 #define JMIXER_DEBUG
 
+#ifndef JMIXER_ADDBUF_TYPE
+#ifdef JSS_MIX_FP
+#define JMIXER_ADDBUF_TYPE double
+#else
+#define JMIXER_ADDBUF_TYPE Sint32
+#endif
+#endif
+
 /* Mono / Linear Interpolation
  */
 #ifdef JSS_MIX_FP
-#define JMIXER_ADDBUF_TYPE float
 #define JMIXER_SAMPLE_TYPE float
 #define JMIXER_INIT        const float vol = (float) (chn->chVolume * mixer->globalVol) / (256.0f * 64.0f);
 #define JMIXER_FUNC        tr = (sp[FP_GETH(tmpPos)] * vol + tr) / 2.0f; *(ap++) += tr;
@@ -27,11 +34,6 @@
 #define JMIXER_ENDCOND     (FP_GETH(tmpPos) > endPos)
 #include "jmixtmpl_c.h"
 
-#undef JMIXER_ADDBUF_TYPE
-#undef JMIXER_SAMPLE_TYPE
-#undef JMIXER_INIT
-#undef JMIXER_FUNC
-
 #else
 
 #define JMIXER_ADDBUF_TYPE Sint32
@@ -49,23 +51,21 @@
 #define JMIXER_ENDCOND     (FP_GETH(tmpPos) > endPos)
 #include "jmixtmpl_c.h"
 
-#undef JMIXER_ADDBUF_TYPE
+#endif
+
 #undef JMIXER_SAMPLE_TYPE
 #undef JMIXER_INIT
 #undef JMIXER_FUNC
 
-#endif
-
 /* Stereo / Linear Interpolation
  */
 #ifdef JSS_MIX_FP
-#define JMIXER_ADDBUF_TYPE float
 #define JMIXER_SAMPLE_TYPE float
-#define JMIXER_INIT        const float vol_l = (chn->chVolume * mixer->globalVol) / (256.0f * 64.0f), \
-                                       vol_r = (chn->chVolume * mixer->globalVol) / (256.0f * 64.0f);
+#define JMIXER_INIT        const double vol_l = (chn->chVolume * mixer->globalVol) / 256.0f, \
+                                       vol_r = (chn->chVolume * mixer->globalVol) / 256.0f;
 
-#define JMIXER_FUNC        tl = (sp[FP_GETH(tmpPos)] * vol_l + tl) / 2.0f; *(ap++) += tl; \
-                           tr = (sp[FP_GETH(tmpPos)] * vol_r + tr) / 2.0f; *(ap++) += tr;
+#define JMIXER_FUNC        tl = ((double)sp[FP_GETH(tmpPos)] * vol_l + tl) / (2.0f * 256.0f); *(ap++) += tl; \
+                           tr = ((double)sp[FP_GETH(tmpPos)] * vol_r + tr) / (2.0f * 256.0f); *(ap++) += tr;
 
 #define JMIXER_NAME        jvmMix_Stereo_C_FW
 #define JMIXER_NEXT        FP_ADD(tmpPos, tmpDelta);
@@ -77,14 +77,8 @@
 #define JMIXER_ENDCOND     (FP_GETH(tmpPos) > endPos)
 #include "jmixtmpl_c.h"
 
-#undef JMIXER_ADDBUF_TYPE
-#undef JMIXER_SAMPLE_TYPE
-#undef JMIXER_INIT
-#undef JMIXER_FUNC
-
 #else
 
-#define JMIXER_ADDBUF_TYPE Sint32
 #define JMIXER_SAMPLE_TYPE Sint16
 #define JMIXER_INIT        const Sint32 vol_l = (chn->chVolume * mixer->globalVol) / 256, \
                                         vol_r = (chn->chVolume * mixer->globalVol) / 256;
@@ -102,22 +96,20 @@
 #define JMIXER_ENDCOND     (FP_GETH(tmpPos) > endPos)
 #include "jmixtmpl_c.h"
 
-#undef JMIXER_ADDBUF_TYPE
+#endif
+
 #undef JMIXER_SAMPLE_TYPE
 #undef JMIXER_INIT
 #undef JMIXER_FUNC
 
-#endif
 
 /* Post processing functions
  */
 #ifdef JSS_MIX_FP
 
-#define JMIXER_ADDBUF_TYPE float
-
 #define JMIXER_CLAMP                  \
     if (t < -1.0f) t = -1.0f; else    \
-    if (t >  1.0f) t =  1.0f;         \
+    if (t >  1.0f) t =  1.0f;
 
 #define JMIXER_NAME jvmPostProcess_U8_C
 #define JMIXER_TYPE Uint8
@@ -145,11 +137,9 @@
 
 #else
 
-#define JMIXER_ADDBUF_TYPE Sint32
-
 #define JMIXER_CLAMP \
     if (t < JVM_LIMIT_16_NEG) t = JVM_LIMIT_16_NEG; else    \
-    if (t > JVM_LIMIT_16_POS) t = JVM_LIMIT_16_POS;         \
+    if (t > JVM_LIMIT_16_POS) t = JVM_LIMIT_16_POS;
 
 #define JMIXER_NAME jvmPostProcess_U8_C
 #define JMIXER_TYPE Uint8