raylib-cpp
C++ object-oriented wrapper library for raylib.
Sound.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_SOUND_HPP_
2 #define RAYLIB_CPP_INCLUDE_SOUND_HPP_
3 
4 #include <string>
5 
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 
9 namespace raylib {
18 class Sound : public ::Sound {
19  public:
20  Sound(const ::Sound& vec) {
21  set(vec);
22  }
23 
24  Sound(const std::string& fileName) {
25  set(LoadSound(fileName.c_str()));
26  }
27 
28  Sound(const ::Wave& wave) {
29  set(LoadSoundFromWave(wave));
30  }
31 
32  ~Sound() {
33  Unload();
34  }
35 
36  GETTERSETTER(unsigned int, SampleCount, sampleCount)
37  GETTERSETTER(::AudioStream, Stream, stream)
38 
39  Sound& operator=(const ::Sound& sound) {
40  set(sound);
41  return *this;
42  }
43 
47  inline Sound& Update(const void *data, int sampleCount) {
48  ::UpdateSound(*this, data, sampleCount);
49  return *this;
50  }
51 
55  inline Sound& Update(const void *data) {
56  ::UpdateSound(*this, data, sampleCount);
57  return *this;
58  }
59 
63  inline void Unload() {
64  ::UnloadSound(*this);
65  }
66 
70  inline Sound& Play() {
71  ::PlaySound(*this);
72  return *this;
73  }
74 
78  inline Sound& Stop() {
79  ::StopSound(*this);
80  return *this;
81  }
82 
86  inline Sound& Pause() {
87  ::PauseSound(*this);
88  return *this;
89  }
90 
94  inline Sound& Resume() {
95  ::ResumeSound(*this);
96  return *this;
97  }
98 
102  inline Sound& PlayMulti() {
103  ::PlaySoundMulti(*this);
104  return *this;
105  }
106 
110  inline Sound& StopMulti() {
111  ::StopSoundMulti();
112  return *this;
113  }
114 
118  inline bool IsPlaying() const {
119  return ::IsSoundPlaying(*this);
120  }
121 
125  inline Sound& SetVolume(float volume) {
126  ::SetSoundVolume(*this, volume);
127  return *this;
128  }
129 
133  inline Sound& SetPitch(float pitch) {
134  ::SetSoundPitch(*this, pitch);
135  return *this;
136  }
137 
138  private:
139  inline void set(const ::Sound& sound) {
140  sampleCount = sound.sampleCount;
141  stream = sound.stream;
142  }
143 };
144 } // namespace raylib
145 
146 #endif // RAYLIB_CPP_INCLUDE_SOUND_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::Sound::Update
Sound & Update(const void *data, int sampleCount)
Update sound buffer with new data.
Definition: Sound.hpp:47
raylib::Sound::StopMulti
Sound & StopMulti()
Stop any sound playing (using multichannel buffer pool)
Definition: Sound.hpp:110
raylib::Sound::SetVolume
Sound & SetVolume(float volume)
Set volume for a sound (1.0 is max level)
Definition: Sound.hpp:125
raylib::Sound
Wave/Sound management functions.
Definition: Sound.hpp:18
raylib::Sound::Pause
Sound & Pause()
Pause a sound.
Definition: Sound.hpp:86
raylib::Sound::Resume
Sound & Resume()
Resume a paused sound.
Definition: Sound.hpp:94
raylib::Sound::Stop
Sound & Stop()
Stop playing a sound.
Definition: Sound.hpp:78
raylib::Sound::IsPlaying
bool IsPlaying() const
Check if a sound is currently playing.
Definition: Sound.hpp:118
raylib::Sound::Unload
void Unload()
Unload sound.
Definition: Sound.hpp:63
raylib::AudioStream
AudioStream management functions.
Definition: AudioStream.hpp:11
raylib::Sound::Update
Sound & Update(const void *data)
Update sound buffer with new data, assuming it's the same sample count.
Definition: Sound.hpp:55
raylib::Sound::SetPitch
Sound & SetPitch(float pitch)
Set pitch for a sound (1.0 is base level)
Definition: Sound.hpp:133
raylib::Sound::Play
Sound & Play()
Play a sound.
Definition: Sound.hpp:70
raylib::Sound::PlayMulti
Sound & PlayMulti()
Play a sound (using multichannel buffer pool)
Definition: Sound.hpp:102