Skip to content

Commit

Permalink
Rename sfSoundStream to sfCustomSoundStream
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 17, 2024
1 parent 4ce68a4 commit 6657568
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 210 deletions.
150 changes: 150 additions & 0 deletions CSFML/src/Audio/CustomSoundStream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#include "System/Vector3.h"
#include <SFML/Audio/SoundStream.hpp>
#include <cstddef>
#include <cstdint>

typedef struct
{
int16_t const *samples; ///< Pointer to the audio samples
unsigned int sampleCount; ///< Number of samples pointed by Samples
} sfCustomSoundStreamChunk;

typedef bool (*sfCustomSoundStreamGetDataCallback)(sfCustomSoundStreamChunk *, void *);
typedef void (*sfCustomSoundStreamSeekCallback)(int64_t, void *);

class sfCustomSoundStream : public sf::SoundStream {
public:
sfCustomSoundStream(sfCustomSoundStreamGetDataCallback onGetData,
sfCustomSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
void *userData) : myGetDataCallback(onGetData),
mySeekCallback(onSeek),
myUserData(userData) {
initialize(channelCount, sampleRate);
}

private:
virtual bool onGetData(Chunk &data) {
sfCustomSoundStreamChunk chunk = {NULL, 0};
bool ok = (myGetDataCallback(&chunk, myUserData));

data.samples = chunk.samples;
data.sampleCount = chunk.sampleCount;

return ok;
}

virtual void onSeek(sf::Time timeOffset) {
if (mySeekCallback) {
int64_t time = {timeOffset.asMicroseconds()};
mySeekCallback(time, myUserData);
}
}

sfCustomSoundStreamGetDataCallback myGetDataCallback;
sfCustomSoundStreamSeekCallback mySeekCallback;
void *myUserData;
};

extern "C" sfCustomSoundStream *sfCustomSoundStream_create(sfCustomSoundStreamGetDataCallback onGetData,
sfCustomSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
void *userData) {
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, userData);
}

extern "C" void sfCustomSoundStream_destroy(sfCustomSoundStream *soundStream) {
delete soundStream;
}

extern "C" void sfCustomSoundStream_play(sfCustomSoundStream *soundStream) {
soundStream->play();
}

extern "C" void sfCustomSoundStream_pause(sfCustomSoundStream *soundStream) {
soundStream->pause();
}

extern "C" void sfCustomSoundStream_stop(sfCustomSoundStream *soundStream) {
soundStream->stop();
}

extern "C" sf::SoundStream::Status sfCustomSoundStream_getStatus(const sfCustomSoundStream *soundStream) {

return soundStream->getStatus();
}

extern "C" unsigned int sfCustomSoundStream_getChannelCount(const sfCustomSoundStream *soundStream) {
return soundStream->getChannelCount();
}

extern "C" unsigned int sfCustomSoundStream_getSampleRate(const sfCustomSoundStream *soundStream) {
return soundStream->getSampleRate();
}

extern "C" void sfCustomSoundStream_setPitch(sfCustomSoundStream *soundStream, float pitch) {
soundStream->setPitch(pitch);
}

extern "C" void sfCustomSoundStream_setVolume(sfCustomSoundStream *soundStream, float volume) {
soundStream->setVolume(volume);
}

extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sfVector3f position) {
soundStream->setPosition(position.x, position.y, position.z);
}

extern "C" void sfCustomSoundStream_setRelativeToListener(sfCustomSoundStream *soundStream, bool relative) {
soundStream->setRelativeToListener(relative);
}

extern "C" void sfCustomSoundStream_setMinDistance(sfCustomSoundStream *soundStream, float distance) {
soundStream->setMinDistance(distance);
}

extern "C" void sfCustomSoundStream_setAttenuation(sfCustomSoundStream *soundStream, float attenuation) {
soundStream->setAttenuation(attenuation);
}

extern "C" void sfCustomSoundStream_setPlayingOffset(sfCustomSoundStream *soundStream, int64_t timeOffset) {
soundStream->setPlayingOffset(sf::microseconds(timeOffset));
}

extern "C" void sfCustomSoundStream_setLoop(sfCustomSoundStream *soundStream, bool loop) {
soundStream->setLoop(loop);
}

extern "C" float sfCustomSoundStream_getPitch(const sfCustomSoundStream *soundStream) {
return soundStream->getPitch();
}

extern "C" float sfCustomSoundStream_getVolume(const sfCustomSoundStream *soundStream) {
return soundStream->getVolume();
}

extern "C" sfVector3f sfCustomSoundStream_getPosition(const sfCustomSoundStream *soundStream) {
sf::Vector3f pos = soundStream->getPosition();
return {pos.x, pos.y, pos.z};
}

extern "C" bool sfCustomSoundStream_isRelativeToListener(const sfCustomSoundStream *soundStream) {
return soundStream->isRelativeToListener();
}

extern "C" float sfCustomSoundStream_getMinDistance(const sfCustomSoundStream *soundStream) {
return soundStream->getMinDistance();
}

extern "C" float sfCustomSoundStream_getAttenuation(const sfCustomSoundStream *soundStream) {
return soundStream->getAttenuation();
}

extern "C" bool sfCustomSoundStream_getLoop(const sfCustomSoundStream *soundStream) {
return soundStream->getLoop();
}

extern "C" int64_t sfCustomSoundStream_getPlayingOffset(const sfCustomSoundStream *soundStream) {
return soundStream->getPlayingOffset().asMicroseconds();
}
152 changes: 0 additions & 152 deletions CSFML/src/Audio/SoundStream.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn main() {
"CSFML/src/Audio/SoundBuffer.cpp",
"CSFML/src/Audio/SoundBufferRecorder.cpp",
"CSFML/src/Audio/SoundRecorder.cpp",
"CSFML/src/Audio/SoundStream.cpp",
"CSFML/src/Audio/CustomSoundStream.cpp",
]
.iter(),
);
Expand Down
Loading

0 comments on commit 6657568

Please sign in to comment.