Mercurial > hg > dmlib
annotate jssmix.h @ 526:f7df57cafdd9
Add support for Interpaint (unpacked) and Doodle (unpacked) hires formats.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 22 Nov 2012 01:07:45 +0200 |
parents | 3bdc776a4b33 |
children |
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 | |
358 | 10 |
11 #ifdef __cplusplus | |
12 extern "C" { | |
13 #endif | |
14 | |
0 | 15 //#define DBG(...) do { fprintf(stderr, __VA_ARGS__); } while (0) |
16 #define DBG(...) do { /* stub */ } while (0) | |
17 | |
18 | |
19 // Mixing limits | |
20 #define JVM_LIMIT_16_POS (32767) | |
21 #define JVM_LIMIT_16_NEG (-32767) | |
22 #define JVM_ADD_16 (32768) | |
23 | |
57
2edda27f951c
Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
24 |
56
8725853609db
Remove the floating point mixing .. it wasn't so good idea after all.
Matti Hamalainen <ccr@tnsp.org>
parents:
51
diff
changeset
|
25 #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
|
26 |
0 | 27 |
28 // A channel data structure | |
29 typedef struct | |
30 { | |
31 DMFixedPoint | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
32 chSize, // Length of sample in UNITS |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
33 chLoopS, // Loop start in UNITS |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
34 chLoopE, // Loop end in UNITS |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
35 |
0 | 36 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
|
37 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
|
38 chVolume, // Volume |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
39 chDeltaV, |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
40 chPanning, // Panning |
1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
41 chDeltaP; |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
42 int chVolumeD, |
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
43 chPanningD; |
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
44 |
0 | 45 int chFreq; // Frequency of sampel in Hz |
46 | |
47 void *chData; // Pointer to data | |
48 | |
49 BOOL chPlaying, // TRUE = playing | |
50 chMute, // TRUE = muted | |
51 chDirection; // TRUE = playing forwards, FALSE = backwards | |
52 | |
53 int chFlags; // Flags | |
54 | |
57
2edda27f951c
Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
55 JMIXER_ADDBUF_TYPE chPrevR[5], chPrevL[5]; |
0 | 56 } JSSChannel; |
57 | |
58 | |
59 // Channel table | |
60 typedef int JSSChannelTable[jsetNChannels]; | |
61 | |
62 | |
63 // Virtual software mixer "device" structure | |
64 typedef struct _JSSMixer JSSMixer; | |
65 | |
66 struct _JSSMixer | |
67 { | |
68 int outFormat, | |
69 outChannels, | |
70 outFreq, | |
71 globalVol; | |
72 JSSChannel channels[jsetNChannels]; | |
73 | |
74 int addBufSize; | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
75 JMIXER_ADDBUF_TYPE *addBuffer; |
0 | 76 |
77 // Callback handling | |
78 int cbFreq, cbCounter; | |
79 void *cbData; | |
80 void (*cbFunction)(void *, void *); | |
81 | |
82 // Mixing routine pointers | |
287
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
83 int (*jvmMixChannel_FW)(JSSMixer *, JSSChannel *, JMIXER_ADDBUF_TYPE *, const int, const DMFixedPoint); |
1e89cd081956
Use fixed point everywhere in the mixing internals, to avoid going over
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
84 int (*jvmMixChannel_BW)(JSSMixer *, JSSChannel *, JMIXER_ADDBUF_TYPE *, const int, const DMFixedPoint); |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
85 void (*jvmPostProcess)(JMIXER_ADDBUF_TYPE *, void *, const int); |
0 | 86 |
87 // Device locking | |
88 #ifdef JSS_SUP_THREADS | |
89 DMMutex *mutex; | |
90 #endif | |
91 }; | |
92 | |
93 | |
94 /* Enums | |
95 */ | |
96 enum { | |
97 JMIX_AUTO = 0, | |
98 JMIX_C, | |
99 JMIX_MMX, | |
100 JMIX_SSE | |
101 }; | |
102 | |
103 | |
104 /* Main routines | |
105 */ | |
136 | 106 JSSMixer * jvmInit(const int outFormat, const int outChannels, const int outFreq, const int mixerID); |
0 | 107 int jvmClose(JSSMixer *mixer); |
108 | |
109 int jvmSetCallback(JSSMixer *mixer, void (*cbFunction)(void *, void *), void *cbData); | |
110 void jvmRemoveCallback(JSSMixer *mixer); | |
111 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
|
112 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
|
113 Sint32 jvmGetNextCBBufPos(JSSMixer *mixer, const int cbHandle); |
0 | 114 |
115 int jvmGetSampleSize(JSSMixer *mixer); | |
116 int jvmGetSampleRes(JSSMixer *mixer); | |
117 | |
118 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength); | |
119 | |
120 | |
121 /* | |
122 int jvmAddCallback(JSSMixer *mixer, void (*cbFunction)(JSSMixer *, void *)); | |
123 int jvmRemoveCallback(JSSMixer *mixer, int cbHandle); | |
124 int jvmSetCallbackFreq(JSSMixer *mixer, int cbHandle, int cbFreq); | |
125 | |
126 int jvmAllocChannels(JSSMixer *mixer, int nChannels); | |
127 int jvmFreeChannels(JSSMixer *mixer, int iHandle); | |
128 int jvmGetChannelTable(JSSMixer *mixer, int iHandle, JSSChannelTable *pTable); | |
129 */ | |
130 | |
131 | |
132 /* Channel manipulation routines | |
133 */ | |
134 void jvmPlay(JSSMixer *mixer, const int channel); | |
135 void jvmStop(JSSMixer *mixer, const int channel); | |
227
b7e23d91a8c2
Add jvmReset() function for reseting channel's position and pitch.
Matti Hamalainen <ccr@tnsp.org>
parents:
141
diff
changeset
|
136 void jvmReset(JSSMixer * mixer, const int channel); |
0 | 137 |
138 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
|
139 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
|
140 const Sint32 loopE, const int flags); |
0 | 141 |
142 void jvmSetFreq(JSSMixer *mixer, const int channel, const int freq); | |
143 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
|
144 |
0 | 145 void jvmSetVolume(JSSMixer *mixer, const int channel, const int volume); |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
146 void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len); |
0 | 147 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
|
148 |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
149 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
|
150 Sint32 jvmGetPos(JSSMixer *mixer, const int channel); |
0 | 151 |
152 void jvmSetPan(JSSMixer *mixer, const int channel, const int panning); | |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
153 void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len); |
0 | 154 int jvmGetPan(JSSMixer *mixer, const int channel); |
155 | |
156 void jvmMute(JSSMixer *mixer, const int channel, const BOOL mute); | |
141
0c9438a2c72a
Add function jvmGetMute() to get status of channel mute.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
157 BOOL jvmGetMute(JSSMixer *mixer, const int channel); |
0 | 158 |
159 void jvmClear(JSSMixer *mixer, const int channel); | |
160 void jvmClearChannels(JSSMixer *mixer); | |
161 | |
162 void jvmSetGlobalVol(JSSMixer *mixer, const int volume); | |
163 int jvmGetGlobalVol(JSSMixer *mixer); | |
164 | |
165 | |
358 | 166 #ifdef __cplusplus |
167 } | |
168 #endif | |
169 | |
0 | 170 #endif // JSSMIX_H |