diff --git a/include/Sound.hpp b/include/Sound.hpp index cbc19da..ab03208 100644 --- a/include/Sound.hpp +++ b/include/Sound.hpp @@ -17,9 +17,15 @@ namespace raylib { */ class Sound : public ::Sound { public: - Sound(const ::Sound& vec) { - set(vec); - } + Sound(const Sound&) = delete; + Sound& operator=(const Sound&) = delete; + + Sound(Sound&& other) { + set(other); + + other.sampleCount = 0; + other.stream = { 0, 0, 0, 0 }; + }; Sound(const std::string& fileName) { set(LoadSound(fileName.c_str())); @@ -36,10 +42,18 @@ class Sound : public ::Sound { GETTERSETTER(unsigned int, SampleCount, sampleCount) GETTERSETTER(::AudioStream, Stream, stream) - Sound& operator=(const ::Sound& sound) { - set(sound); + Sound& operator=(Sound&& other) { + if (this == &other) { + return *this; + } + + Unload(); + set(other); + other.sampleCount = 0; + other.stream = { 0, 0, 0, 0 }; + return *this; - } + }; /** * Update sound buffer with new data diff --git a/include/Wave.hpp b/include/Wave.hpp index f8816d4..871143c 100644 --- a/include/Wave.hpp +++ b/include/Wave.hpp @@ -20,8 +20,9 @@ class Wave : public ::Wave { unsigned int sampleCount = 0, unsigned int sampleRate = 0, unsigned int sampleSize = 0, - unsigned int channels = 0 - ) : ::Wave{sampleCount, sampleRate, sampleSize, channels} { } + unsigned int channels = 0, + void *data = NULL + ) : ::Wave{sampleCount, sampleRate, sampleSize, channels, data} { } /** * Load wave data from file @@ -132,13 +133,6 @@ class Wave : public ::Wave { return LoadSound(); } - /** - * Load sound from wave data - */ - inline operator Sound() { - return LoadSound(); - } - private: inline void set(const ::Wave& wave) { sampleCount = wave.sampleCount; diff --git a/tests/raylib_test.cpp b/tests/raylib_test.cpp index a7e1c3d..228fc41 100644 --- a/tests/raylib_test.cpp +++ b/tests/raylib_test.cpp @@ -32,6 +32,12 @@ int main() { std::vector files = raylib::GetDirectoryFiles(::GetWorkingDirectory()); assert(files.size() > 3); + // Sound + { + raylib::Sound sound("resources/weird.wav"); + sound.Play(); + } + std::cout << "Tests complete" << std::endl; return 0; } diff --git a/tests/resources/weird.wav b/tests/resources/weird.wav new file mode 100644 index 0000000..101029c Binary files /dev/null and b/tests/resources/weird.wav differ