Mercurial > hg > dmlib
annotate jssmix.h @ 134:1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
in the mixer.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 05 Oct 2012 02:47:36 +0300 |
parents | 2edda27f951c |
children | 8ac24d753304 |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Mixing device and channel handling | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
4 * (C) Copyright 2006-2012 Tecnic Software productions (TNSP) | |
5 */ | |
6 #ifndef JSSMIX_H | |
7 #define JSSMIX_H | |
8 #include "jss.h" | |
9 | |
10 //#define DBG(...) do { fprintf(stderr, __VA_ARGS__); } while (0) | |
11 #define DBG(...) do { /* stub */ } while (0) | |
12 | |
13 | |
14 // Mixing limits | |
15 #define JVM_LIMIT_16_POS (32767) | |
16 #define JVM_LIMIT_16_NEG (-32767) | |
17 #define JVM_ADD_16 (32768) | |
18 | |
57
2edda27f951c
Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
19 |
56
8725853609db
Remove the floating point mixing .. it wasn't so good idea after all.
Matti Hamalainen <ccr@tnsp.org>
parents:
51
diff
changeset
|
20 #define JMIXER_ADDBUF_TYPE Sint32 |
8725853609db
Remove the floating point mixing .. it wasn't so good idea after all.
Matti Hamalainen <ccr@tnsp.org>
parents:
51
diff
changeset
|
21 |
0 | 22 |
23 // A channel data structure | |
24 typedef struct | |
25 { | |
26 DMFixedPoint | |
27 chPos, // Current position in sample, 32:32 fixpoint | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
28 chDeltaO, // Delta in 32:32 UNSIGNED! (chDirection) |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
29 chVolume, // Volume |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
30 chDeltaV, |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
31 chPanning, // Panning |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
32 chDeltaP; |
0 | 33 |
34 int chFreq; // Frequency of sampel in Hz | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
35 Sint32 |
0 | 36 chSize, // Length of sample in UNITS |
37 chLoopS, // Loop start in UNITS | |
38 chLoopE; // Loop end in UNITS | |
39 | |
40 void *chData; // Pointer to data | |
41 | |
42 BOOL chPlaying, // TRUE = playing | |
43 chMute, // TRUE = muted | |
44 chDirection; // TRUE = playing forwards, FALSE = backwards | |
45 | |
46 int chFlags; // Flags | |
47 | |
57
2edda27f951c
Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
48 JMIXER_ADDBUF_TYPE chPrevR[5], chPrevL[5]; |
0 | 49 } JSSChannel; |
50 | |
51 | |
52 // Channel table | |
53 typedef int JSSChannelTable[jsetNChannels]; | |
54 | |
55 | |
56 // Virtual software mixer "device" structure | |
57 typedef struct _JSSMixer JSSMixer; | |
58 | |
59 struct _JSSMixer | |
60 { | |
61 int outFormat, | |
62 outChannels, | |
63 outFreq, | |
64 globalVol; | |
65 JSSChannel channels[jsetNChannels]; | |
66 | |
67 int addBufSize; | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
68 JMIXER_ADDBUF_TYPE *addBuffer; |
0 | 69 |
70 // Callback handling | |
71 int cbFreq, cbCounter; | |
72 void *cbData; | |
73 void (*cbFunction)(void *, void *); | |
74 | |
75 // Mixing routine pointers | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
76 int (*jvmMixChannel_FW)(JSSMixer *, JSSChannel *, JMIXER_ADDBUF_TYPE *, const int, const Sint32); |
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
77 int (*jvmMixChannel_BW)(JSSMixer *, JSSChannel *, JMIXER_ADDBUF_TYPE *, const int, const Sint32); |
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
78 void (*jvmPostProcess)(JMIXER_ADDBUF_TYPE *, void *, const int); |
0 | 79 |
80 // Device locking | |
81 #ifdef JSS_SUP_THREADS | |
82 DMMutex *mutex; | |
83 #endif | |
84 }; | |
85 | |
86 | |
87 /* Enums | |
88 */ | |
89 enum { | |
90 JMIX_AUTO = 0, | |
91 JMIX_C, | |
92 JMIX_MMX, | |
93 JMIX_SSE | |
94 }; | |
95 | |
96 | |
97 /* Main routines | |
98 */ | |
99 JSSMixer * jvmInit(const int outFormat, const int nChannels, const int outFreq, const int mixerID); | |
100 int jvmClose(JSSMixer *mixer); | |
101 | |
102 int jvmSetCallback(JSSMixer *mixer, void (*cbFunction)(void *, void *), void *cbData); | |
103 void jvmRemoveCallback(JSSMixer *mixer); | |
104 int jvmSetCallbackFreq(JSSMixer *mixer, const int cbFreq); | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
105 Sint32 jvmGetLastCBBufPos(JSSMixer *mixer, const int cbHandle); |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
106 Sint32 jvmGetNextCBBufPos(JSSMixer *mixer, const int cbHandle); |
0 | 107 |
108 int jvmGetSampleSize(JSSMixer *mixer); | |
109 int jvmGetSampleRes(JSSMixer *mixer); | |
110 | |
111 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength); | |
112 | |
113 | |
114 /* | |
115 int jvmAddCallback(JSSMixer *mixer, void (*cbFunction)(JSSMixer *, void *)); | |
116 int jvmRemoveCallback(JSSMixer *mixer, int cbHandle); | |
117 int jvmSetCallbackFreq(JSSMixer *mixer, int cbHandle, int cbFreq); | |
118 | |
119 int jvmAllocChannels(JSSMixer *mixer, int nChannels); | |
120 int jvmFreeChannels(JSSMixer *mixer, int iHandle); | |
121 int jvmGetChannelTable(JSSMixer *mixer, int iHandle, JSSChannelTable *pTable); | |
122 */ | |
123 | |
124 | |
125 /* Channel manipulation routines | |
126 */ | |
127 void jvmPlay(JSSMixer *mixer, const int channel); | |
128 void jvmStop(JSSMixer *mixer, const int channel); | |
129 | |
130 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:
0
diff
changeset
|
131 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:
0
diff
changeset
|
132 const Sint32 loopE, const int flags); |
0 | 133 |
134 void jvmSetFreq(JSSMixer *mixer, const int channel, const int freq); | |
135 int jvmGetFreq(JSSMixer *mixer, const int channel); | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
136 |
0 | 137 void jvmSetVolume(JSSMixer *mixer, const int channel, const int volume); |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
138 void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end); |
0 | 139 int jvmGetVolume(JSSMixer *mixer, const int channel); |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
140 |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
141 void jvmSetPos(JSSMixer *mixer, const int channel, const Sint32 pos); |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
142 Sint32 jvmGetPos(JSSMixer *mixer, const int channel); |
0 | 143 |
144 void jvmSetPan(JSSMixer *mixer, const int channel, const int panning); | |
134
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
145 void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end); |
0 | 146 int jvmGetPan(JSSMixer *mixer, const int channel); |
147 | |
148 void jvmMute(JSSMixer *mixer, const int channel, const BOOL mute); | |
149 | |
150 void jvmClear(JSSMixer *mixer, const int channel); | |
151 void jvmClearChannels(JSSMixer *mixer); | |
152 | |
153 void jvmSetGlobalVol(JSSMixer *mixer, const int volume); | |
154 int jvmGetGlobalVol(JSSMixer *mixer); | |
155 | |
156 | |
157 #endif // JSSMIX_H |