Mercurial > hg > dmlib
annotate jssmix.h @ 49:033c660c25f5
Restructure module playing, removing 8bit sample mixing (output can still be
8bit, but samples are internally upconverted to 16bit after module loading.)
Also prepare for floating point mixing support.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 01 Oct 2012 02:51:41 +0300 |
parents | f3407a58e01e |
children | 36e2f910219c |
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 | |
19 | |
20 // A channel data structure | |
21 typedef struct | |
22 { | |
23 DMFixedPoint | |
24 chPos, // Current position in sample, 32:32 fixpoint | |
25 chDeltaO; // Delta in 32:32 UNSIGNED! (chDirection) | |
26 | |
27 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
|
28 Sint32 |
0 | 29 chSize, // Length of sample in UNITS |
30 chLoopS, // Loop start in UNITS | |
31 chLoopE; // Loop end in UNITS | |
32 | |
33 void *chData; // Pointer to data | |
34 | |
35 BOOL chPlaying, // TRUE = playing | |
36 chMute, // TRUE = muted | |
37 chDirection; // TRUE = playing forwards, FALSE = backwards | |
38 | |
39 int chFlags; // Flags | |
40 int chVolume, // Volume | |
41 chPanning; // Panning | |
42 | |
43 Sint32 chPrevR, chPrevL; | |
44 } JSSChannel; | |
45 | |
46 | |
47 // Channel table | |
48 typedef int JSSChannelTable[jsetNChannels]; | |
49 | |
50 | |
51 // Virtual software mixer "device" structure | |
52 typedef struct _JSSMixer JSSMixer; | |
53 | |
54 struct _JSSMixer | |
55 { | |
56 int outFormat, | |
57 outChannels, | |
58 outFreq, | |
59 globalVol; | |
60 JSSChannel channels[jsetNChannels]; | |
61 | |
62 int addBufSize; | |
63 Sint32 *addBuffer; | |
64 | |
65 // Callback handling | |
66 int cbFreq, cbCounter; | |
67 void *cbData; | |
68 void (*cbFunction)(void *, void *); | |
69 | |
70 // Mixing routine pointers | |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
71 int (*jvmMixChannel_FW)(JSSMixer *, JSSChannel *, Sint32 *, const int, const Sint32); |
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
72 int (*jvmMixChannel_BW)(JSSMixer *, JSSChannel *, Sint32 *, const int, const Sint32); |
0 | 73 void (*jvmPostProcess)(Sint32 *, void *mixBuffer, int); |
74 | |
75 // Device locking | |
76 #ifdef JSS_SUP_THREADS | |
77 DMMutex *mutex; | |
78 #endif | |
79 }; | |
80 | |
81 | |
82 /* Enums | |
83 */ | |
84 enum { | |
85 JMIX_AUTO = 0, | |
86 JMIX_C, | |
87 JMIX_MMX, | |
88 JMIX_SSE | |
89 }; | |
90 | |
91 | |
92 /* Main routines | |
93 */ | |
94 JSSMixer * jvmInit(const int outFormat, const int nChannels, const int outFreq, const int mixerID); | |
95 int jvmClose(JSSMixer *mixer); | |
96 | |
97 int jvmSetCallback(JSSMixer *mixer, void (*cbFunction)(void *, void *), void *cbData); | |
98 void jvmRemoveCallback(JSSMixer *mixer); | |
99 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
|
100 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
|
101 Sint32 jvmGetNextCBBufPos(JSSMixer *mixer, const int cbHandle); |
0 | 102 |
103 int jvmGetSampleSize(JSSMixer *mixer); | |
104 int jvmGetSampleRes(JSSMixer *mixer); | |
105 | |
106 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength); | |
107 | |
108 | |
109 /* | |
110 int jvmAddCallback(JSSMixer *mixer, void (*cbFunction)(JSSMixer *, void *)); | |
111 int jvmRemoveCallback(JSSMixer *mixer, int cbHandle); | |
112 int jvmSetCallbackFreq(JSSMixer *mixer, int cbHandle, int cbFreq); | |
113 | |
114 int jvmAllocChannels(JSSMixer *mixer, int nChannels); | |
115 int jvmFreeChannels(JSSMixer *mixer, int iHandle); | |
116 int jvmGetChannelTable(JSSMixer *mixer, int iHandle, JSSChannelTable *pTable); | |
117 */ | |
118 | |
119 | |
120 /* Channel manipulation routines | |
121 */ | |
122 void jvmPlay(JSSMixer *mixer, const int channel); | |
123 void jvmStop(JSSMixer *mixer, const int channel); | |
124 | |
125 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
|
126 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
|
127 const Sint32 loopE, const int flags); |
0 | 128 |
129 void jvmSetFreq(JSSMixer *mixer, const int channel, const int freq); | |
130 int jvmGetFreq(JSSMixer *mixer, const int channel); | |
131 void jvmSetVolume(JSSMixer *mixer, const int channel, const int volume); | |
132 int jvmGetVolume(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
|
133 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
|
134 Sint32 jvmGetPos(JSSMixer *mixer, const int channel); |
0 | 135 |
136 void jvmSetPan(JSSMixer *mixer, const int channel, const int panning); | |
137 int jvmGetPan(JSSMixer *mixer, const int channel); | |
138 | |
139 void jvmMute(JSSMixer *mixer, const int channel, const BOOL mute); | |
140 | |
141 void jvmClear(JSSMixer *mixer, const int channel); | |
142 void jvmClearChannels(JSSMixer *mixer); | |
143 | |
144 void jvmSetGlobalVol(JSSMixer *mixer, const int volume); | |
145 int jvmGetGlobalVol(JSSMixer *mixer); | |
146 | |
147 | |
148 #endif // JSSMIX_H |