Mercurial > hg > dmlib
annotate jssmix.h @ 139:111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 05 Oct 2012 09:25:59 +0300 |
parents | 8ac24d753304 |
children | 0c9438a2c72a |
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 |
139
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
34 int chVolumeD, |
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
35 chPanningD; |
111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
36 |
0 | 37 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
|
38 Sint32 |
0 | 39 chSize, // Length of sample in UNITS |
40 chLoopS, // Loop start in UNITS | |
41 chLoopE; // Loop end in UNITS | |
42 | |
43 void *chData; // Pointer to data | |
44 | |
45 BOOL chPlaying, // TRUE = playing | |
46 chMute, // TRUE = muted | |
47 chDirection; // TRUE = playing forwards, FALSE = backwards | |
48 | |
49 int chFlags; // Flags | |
50 | |
57
2edda27f951c
Silly interpolation in mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
51 JMIXER_ADDBUF_TYPE chPrevR[5], chPrevL[5]; |
0 | 52 } JSSChannel; |
53 | |
54 | |
55 // Channel table | |
56 typedef int JSSChannelTable[jsetNChannels]; | |
57 | |
58 | |
59 // Virtual software mixer "device" structure | |
60 typedef struct _JSSMixer JSSMixer; | |
61 | |
62 struct _JSSMixer | |
63 { | |
64 int outFormat, | |
65 outChannels, | |
66 outFreq, | |
67 globalVol; | |
68 JSSChannel channels[jsetNChannels]; | |
69 | |
70 int addBufSize; | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
71 JMIXER_ADDBUF_TYPE *addBuffer; |
0 | 72 |
73 // Callback handling | |
74 int cbFreq, cbCounter; | |
75 void *cbData; | |
76 void (*cbFunction)(void *, void *); | |
77 | |
78 // Mixing routine pointers | |
51
36e2f910219c
A non-working implementation of floating point audio mixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
79 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
|
80 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
|
81 void (*jvmPostProcess)(JMIXER_ADDBUF_TYPE *, void *, const int); |
0 | 82 |
83 // Device locking | |
84 #ifdef JSS_SUP_THREADS | |
85 DMMutex *mutex; | |
86 #endif | |
87 }; | |
88 | |
89 | |
90 /* Enums | |
91 */ | |
92 enum { | |
93 JMIX_AUTO = 0, | |
94 JMIX_C, | |
95 JMIX_MMX, | |
96 JMIX_SSE | |
97 }; | |
98 | |
99 | |
100 /* Main routines | |
101 */ | |
136 | 102 JSSMixer * jvmInit(const int outFormat, const int outChannels, const int outFreq, const int mixerID); |
0 | 103 int jvmClose(JSSMixer *mixer); |
104 | |
105 int jvmSetCallback(JSSMixer *mixer, void (*cbFunction)(void *, void *), void *cbData); | |
106 void jvmRemoveCallback(JSSMixer *mixer); | |
107 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
|
108 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
|
109 Sint32 jvmGetNextCBBufPos(JSSMixer *mixer, const int cbHandle); |
0 | 110 |
111 int jvmGetSampleSize(JSSMixer *mixer); | |
112 int jvmGetSampleRes(JSSMixer *mixer); | |
113 | |
114 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength); | |
115 | |
116 | |
117 /* | |
118 int jvmAddCallback(JSSMixer *mixer, void (*cbFunction)(JSSMixer *, void *)); | |
119 int jvmRemoveCallback(JSSMixer *mixer, int cbHandle); | |
120 int jvmSetCallbackFreq(JSSMixer *mixer, int cbHandle, int cbFreq); | |
121 | |
122 int jvmAllocChannels(JSSMixer *mixer, int nChannels); | |
123 int jvmFreeChannels(JSSMixer *mixer, int iHandle); | |
124 int jvmGetChannelTable(JSSMixer *mixer, int iHandle, JSSChannelTable *pTable); | |
125 */ | |
126 | |
127 | |
128 /* Channel manipulation routines | |
129 */ | |
130 void jvmPlay(JSSMixer *mixer, const int channel); | |
131 void jvmStop(JSSMixer *mixer, const int channel); | |
132 | |
133 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
|
134 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
|
135 const Sint32 loopE, const int flags); |
0 | 136 |
137 void jvmSetFreq(JSSMixer *mixer, const int channel, const int freq); | |
138 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
|
139 |
0 | 140 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
|
141 void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len); |
0 | 142 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
|
143 |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
144 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
|
145 Sint32 jvmGetPos(JSSMixer *mixer, const int channel); |
0 | 146 |
147 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
|
148 void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len); |
0 | 149 int jvmGetPan(JSSMixer *mixer, const int channel); |
150 | |
151 void jvmMute(JSSMixer *mixer, const int channel, const BOOL mute); | |
152 | |
153 void jvmClear(JSSMixer *mixer, const int channel); | |
154 void jvmClearChannels(JSSMixer *mixer); | |
155 | |
156 void jvmSetGlobalVol(JSSMixer *mixer, const int volume); | |
157 int jvmGetGlobalVol(JSSMixer *mixer); | |
158 | |
159 | |
160 #endif // JSSMIX_H |