Skip to content

Commit 99b7e86

Browse files
Merge branch 'RobLoach:sound-constr' into sound-constr
2 parents c7c0b67 + 1e8c311 commit 99b7e86

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

include/Sound.hpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ namespace raylib {
1717
*/
1818
class Sound : public ::Sound {
1919
public:
20-
Sound(const ::Sound& vec) {
21-
set(vec);
22-
}
20+
Sound(const Sound&) = delete;
21+
Sound& operator=(const Sound&) = delete;
22+
23+
Sound(Sound&& other) {
24+
set(other);
25+
26+
other.sampleCount = 0;
27+
other.stream = { 0, 0, 0, 0 };
28+
};
2329

2430
Sound(const std::string& fileName) {
2531
set(LoadSound(fileName.c_str()));
@@ -36,10 +42,18 @@ class Sound : public ::Sound {
3642
GETTERSETTER(unsigned int, SampleCount, sampleCount)
3743
GETTERSETTER(::AudioStream, Stream, stream)
3844

39-
Sound& operator=(const ::Sound& sound) {
40-
set(sound);
45+
Sound& operator=(Sound&& other) {
46+
if (this == &other) {
47+
return *this;
48+
}
49+
50+
Unload();
51+
set(other);
52+
other.sampleCount = 0;
53+
other.stream = { 0, 0, 0, 0 };
54+
4155
return *this;
42-
}
56+
};
4357

4458
/**
4559
* Update sound buffer with new data

include/Wave.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class Wave : public ::Wave {
2020
unsigned int sampleCount = 0,
2121
unsigned int sampleRate = 0,
2222
unsigned int sampleSize = 0,
23-
unsigned int channels = 0
24-
) : ::Wave{sampleCount, sampleRate, sampleSize, channels} { }
23+
unsigned int channels = 0,
24+
void *data = NULL
25+
) : ::Wave{sampleCount, sampleRate, sampleSize, channels, data} { }
2526

2627
/**
2728
* Load wave data from file
@@ -132,13 +133,6 @@ class Wave : public ::Wave {
132133
return LoadSound();
133134
}
134135

135-
/**
136-
* Load sound from wave data
137-
*/
138-
inline operator Sound() {
139-
return LoadSound();
140-
}
141-
142136
private:
143137
inline void set(const ::Wave& wave) {
144138
sampleCount = wave.sampleCount;

tests/raylib_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ int main() {
3232
std::vector<std::string> files = raylib::GetDirectoryFiles(::GetWorkingDirectory());
3333
assert(files.size() > 3);
3434

35+
// Sound
36+
{
37+
raylib::Sound sound("resources/weird.wav");
38+
sound.Play();
39+
}
40+
3541
std::cout << "Tests complete" << std::endl;
3642
return 0;
3743
}

tests/resources/weird.wav

6.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)