1
+ #include " Audio/EffectProcessor.hpp"
2
+ #include " Audio/SoundSourceCone.hpp"
3
+ #include " Audio/SoundStatus.hpp"
4
+ #include " SFML/Audio/SoundChannel.hpp"
1
5
#include " System/Vector3.hpp"
2
6
#include < SFML/Audio/SoundStream.hpp>
3
- #include < cstdint>
7
+ #include < map>
8
+ #include < mutex>
4
9
5
10
typedef bool (*sfCustomSoundStreamGetDataCb)(sf::SoundStream::Chunk *, void *);
6
11
typedef void (*sfCustomSoundStreamSeekCb)(int64_t , void *);
@@ -11,10 +16,11 @@ class sfCustomSoundStream final : public sf::SoundStream {
11
16
sfCustomSoundStreamSeekCb onSeek,
12
17
unsigned int channelCount,
13
18
unsigned int sampleRate,
19
+ const std::vector<sf::SoundChannel> *channel,
14
20
void *userData) : myGetDataCb(onGetData),
15
21
mySeekCallCb (onSeek),
16
22
myUserData(userData) {
17
- initialize (channelCount, sampleRate);
23
+ initialize (channelCount, sampleRate, *channel );
18
24
}
19
25
20
26
private:
@@ -35,12 +41,9 @@ extern "C" sfCustomSoundStream *sfCustomSoundStream_new(sfCustomSoundStreamGetDa
35
41
sfCustomSoundStreamSeekCb onSeek,
36
42
unsigned int channelCount,
37
43
unsigned int sampleRate,
44
+ const std::vector<sf::SoundChannel> *channel,
38
45
void *userData) {
39
- return new sfCustomSoundStream (onGetData, onSeek, channelCount, sampleRate, userData);
40
- }
41
-
42
- extern " C" void sfCustomSoundStream_del (sfCustomSoundStream *soundStream) {
43
- delete soundStream;
46
+ return new sfCustomSoundStream (onGetData, onSeek, channelCount, sampleRate, channel, userData);
44
47
}
45
48
46
49
extern " C" void sfCustomSoundStream_play (sfCustomSoundStream *soundStream) {
@@ -55,9 +58,8 @@ extern "C" void sfCustomSoundStream_stop(sfCustomSoundStream *soundStream) {
55
58
soundStream->stop ();
56
59
}
57
60
58
- extern " C" sf::SoundStream::Status sfCustomSoundStream_getStatus (const sfCustomSoundStream *soundStream) {
59
-
60
- return soundStream->getStatus ();
61
+ extern " C" sfSoundStatus sfCustomSoundStream_getStatus (const sfCustomSoundStream *soundStream) {
62
+ return static_cast <sfSoundStatus>(soundStream->getStatus ());
61
63
}
62
64
63
65
extern " C" unsigned int sfCustomSoundStream_getChannelCount (const sfCustomSoundStream *soundStream) {
@@ -68,16 +70,48 @@ extern "C" unsigned int sfCustomSoundStream_getSampleRate(const sfCustomSoundStr
68
70
return soundStream->getSampleRate ();
69
71
}
70
72
73
+ extern " C" const std::vector<sf::SoundChannel> *sfCustomSoundStream_getChannelMap (const sfCustomSoundStream *soundStream) {
74
+ return new std::vector (soundStream->getChannelMap ());
75
+ }
76
+
71
77
extern " C" void sfCustomSoundStream_setPitch (sfCustomSoundStream *soundStream, float pitch) {
72
78
soundStream->setPitch (pitch);
73
79
}
74
80
81
+ extern " C" void sfCustomSoundStream_setPan (sfCustomSoundStream *soundStream, float pan) {
82
+ soundStream->setPan (pan);
83
+ }
84
+
75
85
extern " C" void sfCustomSoundStream_setVolume (sfCustomSoundStream *soundStream, float volume) {
76
86
soundStream->setVolume (volume);
77
87
}
78
88
79
- extern " C" void sfCustomSoundStream_setPosition (sfCustomSoundStream *soundStream, sfVector3f position) {
80
- soundStream->setPosition (position.x , position.y , position.z );
89
+ extern " C" void sfCustomSoundStream_setSpatializationEnabled (sfCustomSoundStream *soundStream, bool enabled) {
90
+ soundStream->setSpatializationEnabled (enabled);
91
+ }
92
+
93
+ extern " C" void sfCustomSoundStream_setPosition (sfCustomSoundStream *soundStream, sf::Vector3f position) {
94
+ soundStream->setPosition (position);
95
+ }
96
+
97
+ extern " C" void sfCustomSoundStream_setDirection (sfCustomSoundStream *soundStream, sfVector3f position) {
98
+ soundStream->setDirection (convertVector3 (position));
99
+ }
100
+
101
+ extern " C" void sfCustomSoundStream_setCone (sfCustomSoundStream *soundStream, sfSoundSourceCone cone) {
102
+ soundStream->setCone (convertCone (cone));
103
+ }
104
+
105
+ extern " C" void sfCustomSoundStream_setVelocity (sfCustomSoundStream *soundStream, sfVector3f velocity) {
106
+ soundStream->setVelocity (convertVector3 (velocity));
107
+ }
108
+
109
+ extern " C" void sfCustomSoundStream_setDopplerFactor (sfCustomSoundStream *soundStream, float factor) {
110
+ soundStream->setDopplerFactor (factor);
111
+ }
112
+
113
+ extern " C" void sfCustomSoundStream_setDirectionalAttenuationFactor (sfCustomSoundStream *soundStream, float factor) {
114
+ soundStream->setDirectionalAttenuationFactor (factor);
81
115
}
82
116
83
117
extern " C" void sfCustomSoundStream_setRelativeToListener (sfCustomSoundStream *soundStream, bool relative) {
@@ -88,6 +122,18 @@ extern "C" void sfCustomSoundStream_setMinDistance(sfCustomSoundStream *soundStr
88
122
soundStream->setMinDistance (distance);
89
123
}
90
124
125
+ extern " C" void sfCustomSoundStream_setMaxDistance (sfCustomSoundStream *soundStream, float distance) {
126
+ soundStream->setMaxDistance (distance);
127
+ }
128
+
129
+ extern " C" void sfCustomSoundStream_setMinGain (sfCustomSoundStream *soundStream, float gain) {
130
+ soundStream->setMinGain (gain);
131
+ }
132
+
133
+ extern " C" void sfCustomSoundStream_setMaxGain (sfCustomSoundStream *soundStream, float gain) {
134
+ soundStream->setMaxGain (gain);
135
+ }
136
+
91
137
extern " C" void sfCustomSoundStream_setAttenuation (sfCustomSoundStream *soundStream, float attenuation) {
92
138
soundStream->setAttenuation (attenuation);
93
139
}
@@ -96,21 +142,48 @@ extern "C" void sfCustomSoundStream_setPlayingOffset(sfCustomSoundStream *soundS
96
142
soundStream->setPlayingOffset (sf::microseconds (timeOffset));
97
143
}
98
144
99
- extern " C" void sfCustomSoundStream_setLoop (sfCustomSoundStream *soundStream, bool loop) {
100
- soundStream->setLoop (loop);
145
+ extern " C" void sfCustomSoundStream_setLooping (sfCustomSoundStream *soundStream, bool loop) {
146
+ soundStream->setLooping (loop);
101
147
}
102
148
103
149
extern " C" float sfCustomSoundStream_getPitch (const sfCustomSoundStream *soundStream) {
104
150
return soundStream->getPitch ();
105
151
}
106
152
153
+ extern " C" float sfCustomSoundStream_getPan (const sfCustomSoundStream *soundStream) {
154
+ return soundStream->getPan ();
155
+ }
156
+
107
157
extern " C" float sfCustomSoundStream_getVolume (const sfCustomSoundStream *soundStream) {
108
158
return soundStream->getVolume ();
109
159
}
110
160
161
+ extern " C" bool sfCustomSoundStream_isSpatializationEnabled (const sfCustomSoundStream *soundStream) {
162
+ return soundStream->isSpatializationEnabled ();
163
+ }
164
+
111
165
extern " C" sfVector3f sfCustomSoundStream_getPosition (const sfCustomSoundStream *soundStream) {
112
- sf::Vector3f pos = soundStream->getPosition ();
113
- return {pos.x , pos.y , pos.z };
166
+ return convertVector3 (soundStream->getPosition ());
167
+ }
168
+
169
+ extern " C" sfVector3f sfCustomSoundStream_getDirection (const sfCustomSoundStream *soundStream) {
170
+ return convertVector3 (soundStream->getDirection ());
171
+ }
172
+
173
+ extern " C" sfSoundSourceCone sfCustomSoundStream_getCone (const sfCustomSoundStream *soundStream) {
174
+ return convertCone (soundStream->getCone ());
175
+ }
176
+
177
+ extern " C" sfVector3f sfCustomSoundStream_getVelocity (const sfCustomSoundStream *soundStream) {
178
+ return convertVector3 (soundStream->getVelocity ());
179
+ }
180
+
181
+ extern " C" float sfCustomSoundStream_getDopplerFactor (const sfCustomSoundStream *soundStream) {
182
+ return soundStream->getDopplerFactor ();
183
+ }
184
+
185
+ extern " C" float sfCustomSoundStream_getDirectionalAttenuationFactor (const sfCustomSoundStream *soundStream) {
186
+ return soundStream->getDirectionalAttenuationFactor ();
114
187
}
115
188
116
189
extern " C" bool sfCustomSoundStream_isRelativeToListener (const sfCustomSoundStream *soundStream) {
@@ -121,14 +194,56 @@ extern "C" float sfCustomSoundStream_getMinDistance(const sfCustomSoundStream *s
121
194
return soundStream->getMinDistance ();
122
195
}
123
196
197
+ extern " C" float sfCustomSoundStream_getMaxDistance (const sfCustomSoundStream *soundStream) {
198
+ return soundStream->getMaxDistance ();
199
+ }
200
+
201
+ extern " C" float sfCustomSoundStream_getMinGain (const sfCustomSoundStream *soundStream) {
202
+ return soundStream->getMinGain ();
203
+ }
204
+
205
+ extern " C" float sfCustomSoundStream_getMaxGain (const sfCustomSoundStream *soundStream) {
206
+ return soundStream->getMaxGain ();
207
+ }
208
+
124
209
extern " C" float sfCustomSoundStream_getAttenuation (const sfCustomSoundStream *soundStream) {
125
210
return soundStream->getAttenuation ();
126
211
}
127
212
128
- extern " C" bool sfCustomSoundStream_getLoop (const sfCustomSoundStream *soundStream) {
129
- return soundStream->getLoop ();
213
+ extern " C" bool sfCustomSoundStream_isLooping (const sfCustomSoundStream *soundStream) {
214
+ return soundStream->isLooping ();
130
215
}
131
216
132
217
extern " C" int64_t sfCustomSoundStream_getPlayingOffset (const sfCustomSoundStream *soundStream) {
133
218
return soundStream->getPlayingOffset ().asMicroseconds ();
134
219
}
220
+
221
+ static std::map<sfCustomSoundStream *, std::pair<sfEffectProcessor, void *>> processors;
222
+ static std::mutex processorMutex;
223
+
224
+ extern " C" void sfCustomSoundStream_setEffectProcessor (sfCustomSoundStream *soundStream, sfEffectProcessor effectProcessor, void *userData) {
225
+ std::unique_lock<std::mutex> lock (processorMutex);
226
+ if (!effectProcessor) {
227
+ processors.erase (soundStream);
228
+ soundStream->setEffectProcessor (nullptr );
229
+ } else {
230
+ processors[soundStream] = {effectProcessor, userData};
231
+ soundStream->setEffectProcessor (
232
+ [soundStream](const float *inputFrames,
233
+ unsigned int &inputFrameCount,
234
+ float *outputFrames,
235
+ unsigned int &outputFrameCount,
236
+ unsigned int frameChannelCount) {
237
+ std::unique_lock<std::mutex> lock (processorMutex);
238
+ auto it = processors.find (soundStream);
239
+ if (it != processors.end ()) {
240
+ it->second .first (inputFrames, &inputFrameCount, outputFrames, &outputFrameCount, frameChannelCount, it->second .second );
241
+ }
242
+ });
243
+ }
244
+ }
245
+
246
+ extern " C" void sfCustomSoundStream_del (sfCustomSoundStream *music) {
247
+ sfCustomSoundStream_setEffectProcessor (music, nullptr , nullptr );
248
+ delete music;
249
+ }
0 commit comments