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
|
|
28 Uint32
|
|
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 typedef Sint32 JSSVolumeTable[256][256];
|
|
51
|
|
52
|
|
53 // Virtual software mixer "device" structure
|
|
54 typedef struct _JSSMixer JSSMixer;
|
|
55
|
|
56 struct _JSSMixer
|
|
57 {
|
|
58 int outFormat,
|
|
59 outChannels,
|
|
60 outFreq,
|
|
61 globalVol;
|
|
62 JSSChannel channels[jsetNChannels];
|
|
63 JSSVolumeTable volTab8;
|
|
64
|
|
65 int addBufSize;
|
|
66 Sint32 *addBuffer;
|
|
67
|
|
68 // Callback handling
|
|
69 int cbFreq, cbCounter;
|
|
70 void *cbData;
|
|
71 void (*cbFunction)(void *, void *);
|
|
72
|
|
73 // Mixing routine pointers
|
|
74 int (*jvmMixChannel_FW)(JSSMixer *, JSSChannel *, Sint32 *, const int, const Uint32);
|
|
75 int (*jvmMixChannel_BW)(JSSMixer *, JSSChannel *, Sint32 *, const int, const Uint32);
|
|
76 void (*jvmPostProcess)(Sint32 *, void *mixBuffer, int);
|
|
77
|
|
78 // Device locking
|
|
79 #ifdef JSS_SUP_THREADS
|
|
80 DMMutex *mutex;
|
|
81 #endif
|
|
82 };
|
|
83
|
|
84
|
|
85 /* Enums
|
|
86 */
|
|
87 enum {
|
|
88 JMIX_AUTO = 0,
|
|
89 JMIX_C,
|
|
90 JMIX_MMX,
|
|
91 JMIX_SSE
|
|
92 };
|
|
93
|
|
94
|
|
95 /* Main routines
|
|
96 */
|
|
97 JSSMixer * jvmInit(const int outFormat, const int nChannels, const int outFreq, const int mixerID);
|
|
98 int jvmClose(JSSMixer *mixer);
|
|
99
|
|
100 int jvmSetCallback(JSSMixer *mixer, void (*cbFunction)(void *, void *), void *cbData);
|
|
101 void jvmRemoveCallback(JSSMixer *mixer);
|
|
102 int jvmSetCallbackFreq(JSSMixer *mixer, const int cbFreq);
|
|
103 Uint32 jvmGetLastCBBufPos(JSSMixer *mixer, const int cbHandle);
|
|
104 Uint32 jvmGetNextCBBufPos(JSSMixer *mixer, const int cbHandle);
|
|
105
|
|
106 int jvmGetSampleSize(JSSMixer *mixer);
|
|
107 int jvmGetSampleRes(JSSMixer *mixer);
|
|
108
|
|
109 void jvmRenderAudio(JSSMixer *mixer, void *mixBuffer, const int mixLength);
|
|
110
|
|
111
|
|
112 /*
|
|
113 int jvmAddCallback(JSSMixer *mixer, void (*cbFunction)(JSSMixer *, void *));
|
|
114 int jvmRemoveCallback(JSSMixer *mixer, int cbHandle);
|
|
115 int jvmSetCallbackFreq(JSSMixer *mixer, int cbHandle, int cbFreq);
|
|
116
|
|
117 int jvmAllocChannels(JSSMixer *mixer, int nChannels);
|
|
118 int jvmFreeChannels(JSSMixer *mixer, int iHandle);
|
|
119 int jvmGetChannelTable(JSSMixer *mixer, int iHandle, JSSChannelTable *pTable);
|
|
120 */
|
|
121
|
|
122
|
|
123 /* Channel manipulation routines
|
|
124 */
|
|
125 void jvmPlay(JSSMixer *mixer, const int channel);
|
|
126 void jvmStop(JSSMixer *mixer, const int channel);
|
|
127
|
|
128 void jvmSetSample(JSSMixer *mixer, const int channel,
|
|
129 void *data, const Uint32 size, const Uint32 loopS,
|
|
130 const Uint32 loopE, const int flags);
|
|
131
|
|
132 void jvmSetFreq(JSSMixer *mixer, const int channel, const int freq);
|
|
133 int jvmGetFreq(JSSMixer *mixer, const int channel);
|
|
134 void jvmSetVolume(JSSMixer *mixer, const int channel, const int volume);
|
|
135 int jvmGetVolume(JSSMixer *mixer, const int channel);
|
|
136 void jvmSetPos(JSSMixer *mixer, const int channel, const Uint32 pos);
|
|
137 Uint32 jvmGetPos(JSSMixer *mixer, const int channel);
|
|
138
|
|
139 void jvmSetPan(JSSMixer *mixer, const int channel, const int panning);
|
|
140 int jvmGetPan(JSSMixer *mixer, const int channel);
|
|
141
|
|
142 void jvmMute(JSSMixer *mixer, const int channel, const BOOL mute);
|
|
143
|
|
144 void jvmClear(JSSMixer *mixer, const int channel);
|
|
145 void jvmClearChannels(JSSMixer *mixer);
|
|
146
|
|
147 void jvmSetGlobalVol(JSSMixer *mixer, const int volume);
|
|
148 int jvmGetGlobalVol(JSSMixer *mixer);
|
|
149
|
|
150
|
|
151 #endif // JSSMIX_H
|