annotate minijss/jmix_c_in.c @ 2298:b5abfff07ca9

Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and dmGrowBufConstCopyOffsSize().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Jul 2019 10:54:16 +0300
parents 95eb6285f45c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * miniJSS - Mixing routines in C
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
1193
b52905e2788e Bump copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 1189
diff changeset
4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
7 //#define JMIXER_DEBUG fprintf(stderr, "[%.8x:%.8x / %.8x]: %d\n", FP_GETH32(tmpPos), FP_GETL32(tmpPos), endPos, sp[FP_GETH32(tmpPos)]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define JMIXER_DEBUG
57
2edda27f951c Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
9 #define JMIXER_ADDBUF_TYPE Sint32
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
51
36e2f910219c A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
11
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 /* Mono / Linear Interpolation
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 */
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
14 #define JMIXER_SAMPLE_TYPE Sint16
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 809
diff changeset
15 #define JMIXER_INIT
57
2edda27f951c Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
16 #define JMIXER_FUNC \
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
17 const Sint32 vol = (FP_GETH32(tmpVolume) * mixer->globalVol) / 256; \
57
2edda27f951c Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
18 memmove(&tl[0], &tl[1], 4 * sizeof(tl[0])); \
1355
95eb6285f45c Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1193
diff changeset
19 tl[4] = (((Sint32) sp[FP_GETH32(tmpPos)]) * vol * 3 + tl[3] * 2 + tl[2] + tl[1] + tl[0]) / (256 * 8); \
95eb6285f45c Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1193
diff changeset
20 *(ap++) += tl[4];
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
21
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
22 #define JMIXER_NAME jvmMix_Mono_C_FW
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
23 #define JMIXER_NEXT FP_ADD(tmpPos, tmpDelta);
1189
bd2615822bbf Adjust mixing macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
24 #define JMIXER_NEXT_RAMP FP_ADD(tmpPos, tmpDelta); FP_ADD(tmpVolume, tmpDeltaV);
287
1e89cd081956 Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
25 #define JMIXER_ENDCOND (tmpPos.dw < endPos.dw)
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
26 #include "jmixtmpl_c.h"
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
28 #define JMIXER_NAME jvmMix_Mono_C_BW
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
29 #define JMIXER_NEXT FP_SUB(tmpPos, tmpDelta);
1189
bd2615822bbf Adjust mixing macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
30 #define JMIXER_NEXT_RAMP FP_SUB(tmpPos, tmpDelta); FP_ADD(tmpVolume, tmpDeltaV);
287
1e89cd081956 Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
31 #define JMIXER_ENDCOND (tmpPos.dw > endPos.dw)
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
32 #include "jmixtmpl_c.h"
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
57
2edda27f951c Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
34
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
35 #undef JMIXER_SAMPLE_TYPE
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 #undef JMIXER_INIT
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
37 #undef JMIXER_FUNC
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
56
8725853609db Remove the floating point mixing .. it wasn't so good idea after all.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
39
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 /* Stereo / Linear Interpolation
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 */
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
42 #define JMIXER_SAMPLE_TYPE Sint16
134
1ba202b448e0 Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
43 #define JMIXER_INIT
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
44
57
2edda27f951c Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
45 #define JMIXER_FUNC \
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
46 const Sint32 vol_l = (FP_GETH32(tmpVolume) * mixer->globalVol) / 256, \
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
47 vol_r = (FP_GETH32(tmpVolume) * mixer->globalVol) / 256; \
57
2edda27f951c Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
48 memmove(&tl[0], &tl[1], 4 * sizeof(tl[0])); \
2edda27f951c Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
49 memmove(&tr[0], &tr[1], 4 * sizeof(tr[0])); \
1355
95eb6285f45c Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1193
diff changeset
50 tl[4] = (((Sint32) sp[FP_GETH32(tmpPos)]) * vol_l * 3 + tl[3] * 2 + tl[2] + tl[1] + tl[0]) / (256 * 8); \
95eb6285f45c Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1193
diff changeset
51 *(ap++) += tl[4]; \
95eb6285f45c Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1193
diff changeset
52 tr[4] = (((Sint32) sp[FP_GETH32(tmpPos)]) * vol_r * 3 + tr[3] * 2 + tr[2] + tr[1] + tr[0]) / (256 * 8); \
95eb6285f45c Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1193
diff changeset
53 *(ap++) += tr[4];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
55 #define JMIXER_NAME jvmMix_Stereo_C_FW
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
56 #define JMIXER_NEXT FP_ADD(tmpPos, tmpDelta);
1189
bd2615822bbf Adjust mixing macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
57 #define JMIXER_NEXT_RAMP FP_ADD(tmpPos, tmpDelta); FP_ADD(tmpVolume, tmpDeltaV);
287
1e89cd081956 Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
58 #define JMIXER_ENDCOND (tmpPos.dw < endPos.dw)
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
59 #include "jmixtmpl_c.h"
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
61 #define JMIXER_NAME jvmMix_Stereo_C_BW
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
62 #define JMIXER_NEXT FP_SUB(tmpPos, tmpDelta);
1189
bd2615822bbf Adjust mixing macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
63 #define JMIXER_NEXT_RAMP FP_SUB(tmpPos, tmpDelta); FP_ADD(tmpVolume, tmpDeltaV);
287
1e89cd081956 Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
64 #define JMIXER_ENDCOND (tmpPos.dw > endPos.dw)
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
65 #include "jmixtmpl_c.h"
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
66
57
2edda27f951c Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
67
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
68 #undef JMIXER_SAMPLE_TYPE
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 #undef JMIXER_INIT
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
70 #undef JMIXER_FUNC
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 /* Post processing functions
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 */
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
75 #define JMIXER_CLAMP \
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 if (t < JVM_LIMIT_16_NEG) t = JVM_LIMIT_16_NEG; else \
51
36e2f910219c A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
77 if (t > JVM_LIMIT_16_POS) t = JVM_LIMIT_16_POS;
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
78
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
79 #define JMIXER_NAME jvmPostProcess_U8_C
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
80 #define JMIXER_TYPE Uint8
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
81 #define JMIXER_FUNCTION *(sp++) = (t + JVM_ADD_16) >> 8;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
82 #include "jmix_post_c.h"
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
83
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
84
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
85 #define JMIXER_NAME jvmPostProcess_S8_C
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
86 #define JMIXER_TYPE Sint8
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
87 #define JMIXER_FUNCTION *(sp++) = t >> 8;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
88 #include "jmix_post_c.h"
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
89
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
90
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
91 #define JMIXER_NAME jvmPostProcess_U16_C
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
92 #define JMIXER_TYPE Uint16
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
93 #define JMIXER_FUNCTION *(sp++) = t + JVM_ADD_16;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
94 #include "jmix_post_c.h"
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
95
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
96
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
97 #define JMIXER_NAME jvmPostProcess_S16_C
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
98 #define JMIXER_TYPE Sint16
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
99 #define JMIXER_FUNCTION *(sp++) = t;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
100 #include "jmix_post_c.h"