raylib-cpp
C++ object-oriented wrapper library for raylib.
Sound.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_SOUND_HPP_
26 #define RAYLIB_CPP_INCLUDE_SOUND_HPP_
27 
28 #include <string>
29 
30 #include "./raylib.hpp"
31 #include "./raylib-cpp-utils.hpp"
32 
33 namespace raylib {
37 class Sound : public ::Sound {
38  public:
39  Sound(const ::Sound& vec) {
40  set(vec);
41  }
42 
43  Sound(const std::string& fileName) {
44  set(LoadSound(fileName.c_str()));
45  }
46 
47  Sound(const ::Wave& wave) {
48  set(LoadSoundFromWave(wave));
49  }
50 
51  ~Sound() {
52  Unload();
53  }
54 
55  GETTERSETTER(unsigned int, SampleCount, sampleCount)
56  GETTERSETTER(::AudioStream, Stream, stream)
57 
58  Sound& operator=(const ::Sound& sound) {
59  set(sound);
60  return *this;
61  }
62 
63  Sound& operator=(const Sound& sound) {
64  set(sound);
65  return *this;
66  }
67 
71  inline Sound& Update(const void *data, int sampleCount) {
72  ::UpdateSound(*this, data, sampleCount);
73  return *this;
74  }
75 
79  inline void Unload() {
80  ::UnloadSound(*this);
81  }
82 
86  inline Sound& Play() {
87  ::PlaySound(*this);
88  return *this;
89  }
90 
94  inline Sound& Stop() {
95  ::StopSound(*this);
96  return *this;
97  }
98 
102  inline Sound& Pause() {
103  ::PauseSound(*this);
104  return *this;
105  }
106 
110  inline Sound& Resume() {
111  ::ResumeSound(*this);
112  return *this;
113  }
114 
118  inline Sound& PlayMulti() {
119  ::PlaySoundMulti(*this);
120  return *this;
121  }
122 
126  inline Sound& StopMulti() {
127  ::StopSoundMulti();
128  return *this;
129  }
130 
134  inline bool IsPlaying() const {
135  return ::IsSoundPlaying(*this);
136  }
137 
141  inline Sound& SetVolume(float volume) {
142  ::SetSoundVolume(*this, volume);
143  return *this;
144  }
145 
149  inline Sound& SetPitch(float pitch) {
150  ::SetSoundPitch(*this, pitch);
151  return *this;
152  }
153 
154  protected:
155  inline void set(const ::Sound& sound) {
156  sampleCount = sound.sampleCount;
157  stream = sound.stream;
158  }
159 };
160 } // namespace raylib
161 
162 #endif // RAYLIB_CPP_INCLUDE_SOUND_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Sound::~Sound
~Sound()
Definition: Sound.hpp:51
raylib::Sound::Update
Sound & Update(const void *data, int sampleCount)
Update sound buffer with new data.
Definition: Sound.hpp:71
raylib::Sound::set
void set(const ::Sound &sound)
Definition: Sound.hpp:155
raylib::Sound::StopMulti
Sound & StopMulti()
Stop any sound playing (using multichannel buffer pool)
Definition: Sound.hpp:126
raylib::Sound::SetVolume
Sound & SetVolume(float volume)
Set volume for a sound (1.0 is max level)
Definition: Sound.hpp:141
raylib::Sound
Wave/Sound management functions.
Definition: Sound.hpp:37
raylib::Sound::Pause
Sound & Pause()
Pause a sound.
Definition: Sound.hpp:102
raylib::Sound::operator=
Sound & operator=(const Sound &sound)
Definition: Sound.hpp:63
raylib::Sound::Resume
Sound & Resume()
Resume a paused sound.
Definition: Sound.hpp:110
raylib::Sound::Sound
Sound(const ::Sound &vec)
Definition: Sound.hpp:39
raylib::Sound::Stop
Sound & Stop()
Stop playing a sound.
Definition: Sound.hpp:94
raylib::Sound::IsPlaying
bool IsPlaying() const
Check if a sound is currently playing.
Definition: Sound.hpp:134
raylib::Sound::Unload
void Unload()
Unload sound.
Definition: Sound.hpp:79
raylib::AudioStream
AudioStream management functions.
Definition: AudioStream.hpp:35
raylib::Sound::Sound
Sound(const ::Wave &wave)
Definition: Sound.hpp:47
raylib::Sound::SetPitch
Sound & SetPitch(float pitch)
Set pitch for a sound (1.0 is base level)
Definition: Sound.hpp:149
raylib::Sound::Play
Sound & Play()
Play a sound.
Definition: Sound.hpp:86
raylib::Sound::PlayMulti
Sound & PlayMulti()
Play a sound (using multichannel buffer pool)
Definition: Sound.hpp:118
raylib::Sound::Sound
Sound(const std::string &fileName)
Definition: Sound.hpp:43