1+ #include " Audio/EffectProcessor.hpp"
2+ #include " Audio/SoundSourceCone.hpp"
3+ #include " Audio/SoundStatus.hpp"
4+ #include " SFML/Audio/SoundChannel.hpp"
15#include " System/Vector3.hpp"
26#include < SFML/Audio/SoundStream.hpp>
3- #include < cstdint>
7+ #include < map>
8+ #include < mutex>
49
510typedef bool (*sfCustomSoundStreamGetDataCb)(sf::SoundStream::Chunk *, void *);
611typedef void (*sfCustomSoundStreamSeekCb)(int64_t , void *);
@@ -11,10 +16,11 @@ class sfCustomSoundStream final : public sf::SoundStream {
1116 sfCustomSoundStreamSeekCb onSeek,
1217 unsigned int channelCount,
1318 unsigned int sampleRate,
19+ const std::vector<sf::SoundChannel> *channel,
1420 void *userData) : myGetDataCb(onGetData),
1521 mySeekCallCb (onSeek),
1622 myUserData(userData) {
17- initialize (channelCount, sampleRate);
23+ initialize (channelCount, sampleRate, *channel );
1824 }
1925
2026 private:
@@ -35,12 +41,9 @@ extern "C" sfCustomSoundStream *sfCustomSoundStream_new(sfCustomSoundStreamGetDa
3541 sfCustomSoundStreamSeekCb onSeek,
3642 unsigned int channelCount,
3743 unsigned int sampleRate,
44+ const std::vector<sf::SoundChannel> *channel,
3845 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);
4447}
4548
4649extern " C" void sfCustomSoundStream_play (sfCustomSoundStream *soundStream) {
@@ -55,9 +58,8 @@ extern "C" void sfCustomSoundStream_stop(sfCustomSoundStream *soundStream) {
5558 soundStream->stop ();
5659}
5760
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 ());
6163}
6264
6365extern " C" unsigned int sfCustomSoundStream_getChannelCount (const sfCustomSoundStream *soundStream) {
@@ -68,16 +70,48 @@ extern "C" unsigned int sfCustomSoundStream_getSampleRate(const sfCustomSoundStr
6870 return soundStream->getSampleRate ();
6971}
7072
73+ extern " C" const std::vector<sf::SoundChannel> *sfCustomSoundStream_getChannelMap (const sfCustomSoundStream *soundStream) {
74+ return new std::vector (soundStream->getChannelMap ());
75+ }
76+
7177extern " C" void sfCustomSoundStream_setPitch (sfCustomSoundStream *soundStream, float pitch) {
7278 soundStream->setPitch (pitch);
7379}
7480
81+ extern " C" void sfCustomSoundStream_setPan (sfCustomSoundStream *soundStream, float pan) {
82+ soundStream->setPan (pan);
83+ }
84+
7585extern " C" void sfCustomSoundStream_setVolume (sfCustomSoundStream *soundStream, float volume) {
7686 soundStream->setVolume (volume);
7787}
7888
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);
81115}
82116
83117extern " C" void sfCustomSoundStream_setRelativeToListener (sfCustomSoundStream *soundStream, bool relative) {
@@ -88,6 +122,18 @@ extern "C" void sfCustomSoundStream_setMinDistance(sfCustomSoundStream *soundStr
88122 soundStream->setMinDistance (distance);
89123}
90124
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+
91137extern " C" void sfCustomSoundStream_setAttenuation (sfCustomSoundStream *soundStream, float attenuation) {
92138 soundStream->setAttenuation (attenuation);
93139}
@@ -96,21 +142,48 @@ extern "C" void sfCustomSoundStream_setPlayingOffset(sfCustomSoundStream *soundS
96142 soundStream->setPlayingOffset (sf::microseconds (timeOffset));
97143}
98144
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);
101147}
102148
103149extern " C" float sfCustomSoundStream_getPitch (const sfCustomSoundStream *soundStream) {
104150 return soundStream->getPitch ();
105151}
106152
153+ extern " C" float sfCustomSoundStream_getPan (const sfCustomSoundStream *soundStream) {
154+ return soundStream->getPan ();
155+ }
156+
107157extern " C" float sfCustomSoundStream_getVolume (const sfCustomSoundStream *soundStream) {
108158 return soundStream->getVolume ();
109159}
110160
161+ extern " C" bool sfCustomSoundStream_isSpatializationEnabled (const sfCustomSoundStream *soundStream) {
162+ return soundStream->isSpatializationEnabled ();
163+ }
164+
111165extern " 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 ();
114187}
115188
116189extern " C" bool sfCustomSoundStream_isRelativeToListener (const sfCustomSoundStream *soundStream) {
@@ -121,14 +194,56 @@ extern "C" float sfCustomSoundStream_getMinDistance(const sfCustomSoundStream *s
121194 return soundStream->getMinDistance ();
122195}
123196
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+
124209extern " C" float sfCustomSoundStream_getAttenuation (const sfCustomSoundStream *soundStream) {
125210 return soundStream->getAttenuation ();
126211}
127212
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 ();
130215}
131216
132217extern " C" int64_t sfCustomSoundStream_getPlayingOffset (const sfCustomSoundStream *soundStream) {
133218 return soundStream->getPlayingOffset ().asMicroseconds ();
134219}
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