comparison jmix_c_in.c @ 56:8725853609db

Remove the floating point mixing .. it wasn't so good idea after all.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 06:59:00 +0300
parents 36e2f910219c
children 2edda27f951c
comparison
equal deleted inserted replaced
55:e0e470c3fc8e 56:8725853609db
5 */ 5 */
6 6
7 //#define JMIXER_DEBUG fprintf(stderr, "[%.8x:%.8x / %.8x]: %d\n", FP_GETH(tmpPos), FP_GETL(tmpPos), endPos, sp[FP_GETH(tmpPos)]); 7 //#define JMIXER_DEBUG fprintf(stderr, "[%.8x:%.8x / %.8x]: %d\n", FP_GETH(tmpPos), FP_GETL(tmpPos), endPos, sp[FP_GETH(tmpPos)]);
8 #define JMIXER_DEBUG 8 #define JMIXER_DEBUG
9 9
10 #ifndef JMIXER_ADDBUF_TYPE
11 #ifdef JSS_MIX_FP
12 #define JMIXER_ADDBUF_TYPE double
13 #else
14 #define JMIXER_ADDBUF_TYPE Sint32 10 #define JMIXER_ADDBUF_TYPE Sint32
15 #endif
16 #endif
17 11
18 /* Mono / Linear Interpolation 12 /* Mono / Linear Interpolation
19 */ 13 */
20 #ifdef JSS_MIX_FP
21 #define JMIXER_SAMPLE_TYPE float
22 #define JMIXER_INIT const float vol = (float) (chn->chVolume * mixer->globalVol) / (256.0f * 64.0f);
23 #define JMIXER_FUNC tr = (sp[FP_GETH(tmpPos)] * vol + tr) / 2.0f; *(ap++) += tr;
24
25
26 #define JMIXER_NAME jvmMix_Mono_C_FW
27 #define JMIXER_NEXT FP_ADD(tmpPos, tmpDelta);
28 #define JMIXER_ENDCOND (FP_GETH(tmpPos) < endPos)
29 #include "jmixtmpl_c.h"
30
31
32 #define JMIXER_NAME jvmMix_Mono_C_BW
33 #define JMIXER_NEXT FP_SUB(tmpPos, tmpDelta);
34 #define JMIXER_ENDCOND (FP_GETH(tmpPos) > endPos)
35 #include "jmixtmpl_c.h"
36
37 #else
38
39 #define JMIXER_ADDBUF_TYPE Sint32 14 #define JMIXER_ADDBUF_TYPE Sint32
40 #define JMIXER_SAMPLE_TYPE Sint16 15 #define JMIXER_SAMPLE_TYPE Sint16
41 #define JMIXER_INIT const Sint32 vol = (chn->chVolume * mixer->globalVol) / 256; 16 #define JMIXER_INIT const Sint32 vol = (chn->chVolume * mixer->globalVol) / 256;
42 #define JMIXER_FUNC tr = (((Sint32) sp[FP_GETH(tmpPos)]) * vol + tr) / (256 * 2); *(ap++) += tr; 17 #define JMIXER_FUNC tr = (((Sint32) sp[FP_GETH(tmpPos)]) * vol + tr) / (256 * 2); *(ap++) += tr;
43 18
49 #define JMIXER_NAME jvmMix_Mono_C_BW 24 #define JMIXER_NAME jvmMix_Mono_C_BW
50 #define JMIXER_NEXT FP_SUB(tmpPos, tmpDelta); 25 #define JMIXER_NEXT FP_SUB(tmpPos, tmpDelta);
51 #define JMIXER_ENDCOND (FP_GETH(tmpPos) > endPos) 26 #define JMIXER_ENDCOND (FP_GETH(tmpPos) > endPos)
52 #include "jmixtmpl_c.h" 27 #include "jmixtmpl_c.h"
53 28
54 #endif
55
56 #undef JMIXER_SAMPLE_TYPE 29 #undef JMIXER_SAMPLE_TYPE
57 #undef JMIXER_INIT 30 #undef JMIXER_INIT
58 #undef JMIXER_FUNC 31 #undef JMIXER_FUNC
59 32
33
60 /* Stereo / Linear Interpolation 34 /* Stereo / Linear Interpolation
61 */ 35 */
62 #ifdef JSS_MIX_FP
63 #define JMIXER_SAMPLE_TYPE float
64 #define JMIXER_INIT const double vol_l = (chn->chVolume * mixer->globalVol) / 256.0f, \
65 vol_r = (chn->chVolume * mixer->globalVol) / 256.0f;
66
67 #define JMIXER_FUNC tl = ((double)sp[FP_GETH(tmpPos)] * vol_l + tl) / (2.0f * 256.0f); *(ap++) += tl; \
68 tr = ((double)sp[FP_GETH(tmpPos)] * vol_r + tr) / (2.0f * 256.0f); *(ap++) += tr;
69
70 #define JMIXER_NAME jvmMix_Stereo_C_FW
71 #define JMIXER_NEXT FP_ADD(tmpPos, tmpDelta);
72 #define JMIXER_ENDCOND (FP_GETH(tmpPos) < endPos)
73 #include "jmixtmpl_c.h"
74
75 #define JMIXER_NAME jvmMix_Stereo_C_BW
76 #define JMIXER_NEXT FP_SUB(tmpPos, tmpDelta);
77 #define JMIXER_ENDCOND (FP_GETH(tmpPos) > endPos)
78 #include "jmixtmpl_c.h"
79
80 #else
81
82 #define JMIXER_SAMPLE_TYPE Sint16 36 #define JMIXER_SAMPLE_TYPE Sint16
83 #define JMIXER_INIT const Sint32 vol_l = (chn->chVolume * mixer->globalVol) / 256, \ 37 #define JMIXER_INIT const Sint32 vol_l = (chn->chVolume * mixer->globalVol) / 256, \
84 vol_r = (chn->chVolume * mixer->globalVol) / 256; 38 vol_r = (chn->chVolume * mixer->globalVol) / 256;
85 39
86 #define JMIXER_FUNC tl = (((Sint32) sp[FP_GETH(tmpPos)]) * vol_l + tl) / (256 * 2); *(ap++) += tl; \ 40 #define JMIXER_FUNC tl = (((Sint32) sp[FP_GETH(tmpPos)]) * vol_l + tl) / (256 * 2); *(ap++) += tl; \
94 #define JMIXER_NAME jvmMix_Stereo_C_BW 48 #define JMIXER_NAME jvmMix_Stereo_C_BW
95 #define JMIXER_NEXT FP_SUB(tmpPos, tmpDelta); 49 #define JMIXER_NEXT FP_SUB(tmpPos, tmpDelta);
96 #define JMIXER_ENDCOND (FP_GETH(tmpPos) > endPos) 50 #define JMIXER_ENDCOND (FP_GETH(tmpPos) > endPos)
97 #include "jmixtmpl_c.h" 51 #include "jmixtmpl_c.h"
98 52
99 #endif
100
101 #undef JMIXER_SAMPLE_TYPE 53 #undef JMIXER_SAMPLE_TYPE
102 #undef JMIXER_INIT 54 #undef JMIXER_INIT
103 #undef JMIXER_FUNC 55 #undef JMIXER_FUNC
104 56
105 57
106 /* Post processing functions 58 /* Post processing functions
107 */ 59 */
108 #ifdef JSS_MIX_FP
109
110 #define JMIXER_CLAMP \
111 if (t < -1.0f) t = -1.0f; else \
112 if (t > 1.0f) t = 1.0f;
113
114 #define JMIXER_NAME jvmPostProcess_U8_C
115 #define JMIXER_TYPE Uint8
116 #define JMIXER_FUNCTION *(sp++) = (t + 1.0f) * 127.0f;
117 #include "jmix_post_c.h"
118
119
120 #define JMIXER_NAME jvmPostProcess_S8_C
121 #define JMIXER_TYPE Sint8
122 #define JMIXER_FUNCTION *(sp++) = t * 127.0f;
123 #include "jmix_post_c.h"
124
125
126 #define JMIXER_NAME jvmPostProcess_U16_C
127 #define JMIXER_TYPE Uint16
128 #define JMIXER_FUNCTION *(sp++) = (t + 1.0f) * 32767.0f;
129 #include "jmix_post_c.h"
130
131
132 #define JMIXER_NAME jvmPostProcess_S16_C
133 #define JMIXER_TYPE Sint16
134 #define JMIXER_FUNCTION *(sp++) = t * 32767.0f;
135 #include "jmix_post_c.h"
136
137
138 #else
139
140 #define JMIXER_CLAMP \ 60 #define JMIXER_CLAMP \
141 if (t < JVM_LIMIT_16_NEG) t = JVM_LIMIT_16_NEG; else \ 61 if (t < JVM_LIMIT_16_NEG) t = JVM_LIMIT_16_NEG; else \
142 if (t > JVM_LIMIT_16_POS) t = JVM_LIMIT_16_POS; 62 if (t > JVM_LIMIT_16_POS) t = JVM_LIMIT_16_POS;
143 63
144 #define JMIXER_NAME jvmPostProcess_U8_C 64 #define JMIXER_NAME jvmPostProcess_U8_C
161 81
162 #define JMIXER_NAME jvmPostProcess_S16_C 82 #define JMIXER_NAME jvmPostProcess_S16_C
163 #define JMIXER_TYPE Sint16 83 #define JMIXER_TYPE Sint16
164 #define JMIXER_FUNCTION *(sp++) = t; 84 #define JMIXER_FUNCTION *(sp++) = t;
165 #include "jmix_post_c.h" 85 #include "jmix_post_c.h"
166
167 #endif