raylib-cpp
C++ object-oriented wrapper library for raylib.
AudioStream.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
2 #define RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
3 
4 #include "./raylib.hpp"
5 #include "./raylib-cpp-utils.hpp"
6 
7 namespace raylib {
11 class AudioStream : public ::AudioStream {
12  public:
13  AudioStream(const ::AudioStream& music) {
14  set(music);
15  }
16 
20  AudioStream(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) {
21  set(LoadAudioStream(SampleRate, SampleSize, Channels));
22  }
23 
24  AudioStream(const AudioStream&) = delete;
25 
26  AudioStream(AudioStream&& other) {
27  set(other);
28 
29  other.buffer = nullptr;
30  other.sampleRate = 0;
31  other.sampleSize = 0;
32  other.channels = 0;
33  }
34 
35  ~AudioStream() {
36  Unload();
37  }
38 
39  GETTERSETTER(rAudioBuffer *, Buffer, buffer)
40  GETTERSETTER(unsigned int, SampleRate, sampleRate)
41  GETTERSETTER(unsigned int, SampleSize, sampleSize)
42  GETTERSETTER(unsigned int, Channels, channels)
43 
44  AudioStream& operator=(const ::AudioStream& stream) {
45  set(stream);
46  return *this;
47  }
48 
49  AudioStream& operator=(const AudioStream&) = delete;
50 
51  AudioStream& operator=(AudioStream&& other) {
52  if (this == &other) {
53  return *this;
54  }
55 
56  Unload();
57  set(other);
58 
59  other.buffer = nullptr;
60  other.sampleRate = 0;
61  other.sampleSize = 0;
62  other.channels = 0;
63 
64  return *this;
65  }
66 
70  inline AudioStream& Update(const void *data, int samplesCount) {
71  ::UpdateAudioStream(*this, data, samplesCount);
72  return *this;
73  }
74 
78  inline void Unload() {
79  ::UnloadAudioStream(*this);
80  }
81 
85  inline bool IsProcessed() const {
86  return ::IsAudioStreamProcessed(*this);
87  }
88 
92  inline AudioStream& Play() {
93  ::PlayAudioStream(*this);
94  return *this;
95  }
96 
100  inline AudioStream& Pause() {
101  ::PauseAudioStream(*this);
102  return *this;
103  }
104 
108  inline AudioStream& Resume() {
109  ::ResumeAudioStream(*this);
110  return *this;
111  }
112 
116  inline bool IsPlaying() const {
117  return ::IsAudioStreamPlaying(*this);
118  }
119 
123  inline AudioStream& Stop() {
124  ::StopAudioStream(*this);
125  return *this;
126  }
127 
131  inline AudioStream& SetVolume(float volume) {
132  ::SetAudioStreamVolume(*this, volume);
133  return *this;
134  }
135 
139  inline AudioStream& SetPitch(float pitch) {
140  ::SetAudioStreamPitch(*this, pitch);
141  return *this;
142  }
143 
147  inline static void SetBufferSizeDefault(int size) {
148  ::SetAudioStreamBufferSizeDefault(size);
149  }
150 
151  private:
152  inline void set(const ::AudioStream& stream) {
153  buffer = stream.buffer;
154  sampleRate = stream.sampleRate;
155  sampleSize = stream.sampleSize;
156  channels = stream.channels;
157  }
158 };
159 } // namespace raylib
160 
161 #endif // RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::AudioStream::IsPlaying
bool IsPlaying() const
Check if audio stream is playing.
Definition: AudioStream.hpp:116
raylib::AudioStream::Stop
AudioStream & Stop()
Stop audio stream.
Definition: AudioStream.hpp:123
raylib::AudioStream::Update
AudioStream & Update(const void *data, int samplesCount)
Update audio stream buffers with data.
Definition: AudioStream.hpp:70
raylib::AudioStream::Resume
AudioStream & Resume()
Resume audio stream.
Definition: AudioStream.hpp:108
raylib::AudioStream::SetBufferSizeDefault
static void SetBufferSizeDefault(int size)
Default size for new audio streams.
Definition: AudioStream.hpp:147
raylib::AudioStream::AudioStream
AudioStream(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels=2)
Init audio stream (to stream raw audio pcm data)
Definition: AudioStream.hpp:20
raylib::AudioStream::Play
AudioStream & Play()
Play audio stream.
Definition: AudioStream.hpp:92
raylib::AudioStream::IsProcessed
bool IsProcessed() const
Check if any audio stream buffers requires refill.
Definition: AudioStream.hpp:85
raylib::AudioStream::Pause
AudioStream & Pause()
Pause audio stream.
Definition: AudioStream.hpp:100
raylib::AudioStream::SetPitch
AudioStream & SetPitch(float pitch)
Set pitch for audio stream (1.0 is base level)
Definition: AudioStream.hpp:139
raylib::AudioStream
AudioStream management functions.
Definition: AudioStream.hpp:11
raylib::AudioStream::SetVolume
AudioStream & SetVolume(float volume)
Set volume for audio stream (1.0 is max level)
Definition: AudioStream.hpp:131
raylib::AudioStream::Unload
void Unload()
Unload audio stream and free memory.
Definition: AudioStream.hpp:78