raylib-cpp
C++ object-oriented wrapper library for raylib.
AudioStream.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_AUDIOSTREAM_HPP_
26 #define RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
27 
28 #include "./raylib.hpp"
29 #include "./raylib-cpp-utils.hpp"
30 
31 namespace raylib {
35 class AudioStream : public ::AudioStream {
36  public:
37  AudioStream(const ::AudioStream& music) {
38  set(music);
39  }
40 
44  AudioStream(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels) {
45  set(InitAudioStream(SampleRate, SampleSize, Channels));
46  }
47 
49  Close();
50  }
51 
52  GETTERSETTER(rAudioBuffer *, Buffer, buffer)
53  GETTERSETTER(unsigned int, SampleRate, sampleRate)
54  GETTERSETTER(unsigned int, SampleSize, sampleSize)
55  GETTERSETTER(unsigned int, Channels, channels)
56 
57  AudioStream& operator=(const ::AudioStream& stream) {
58  set(stream);
59  return *this;
60  }
61 
65  inline AudioStream& Update(const void *data, int samplesCount) {
66  ::UpdateAudioStream(*this, data, samplesCount);
67  return *this;
68  }
69 
73  inline void Close() {
74  ::CloseAudioStream(*this);
75  }
76 
80  inline bool IsProcessed() const {
81  return ::IsAudioStreamProcessed(*this);
82  }
83 
87  inline AudioStream& Play() {
88  ::PlayAudioStream(*this);
89  return *this;
90  }
91 
95  inline AudioStream& Pause() {
96  ::PauseAudioStream(*this);
97  return *this;
98  }
99 
103  inline AudioStream& Resume() {
104  ::ResumeAudioStream(*this);
105  return *this;
106  }
107 
111  inline bool IsPlaying() const {
112  return ::IsAudioStreamPlaying(*this);
113  }
114 
118  inline AudioStream& Stop() {
119  ::StopAudioStream(*this);
120  return *this;
121  }
122 
126  inline AudioStream& SetVolume(float volume) {
127  ::SetAudioStreamVolume(*this, volume);
128  return *this;
129  }
130 
134  inline AudioStream& SetPitch(float pitch) {
135  ::SetAudioStreamPitch(*this, pitch);
136  return *this;
137  }
138 
142  inline static void SetBufferSizeDefault(int size) {
143  ::SetAudioStreamBufferSizeDefault(size);
144  }
145 
146  protected:
147  inline void set(const ::AudioStream& stream) {
148  buffer = stream.buffer;
149  sampleRate = stream.sampleRate;
150  sampleSize = stream.sampleSize;
151  channels = stream.channels;
152  }
153 };
154 } // namespace raylib
155 
156 #endif // RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::AudioStream::IsPlaying
bool IsPlaying() const
Check if audio stream is playing.
Definition: AudioStream.hpp:111
raylib::AudioStream::Stop
AudioStream & Stop()
Stop audio stream.
Definition: AudioStream.hpp:118
raylib::AudioStream::Update
AudioStream & Update(const void *data, int samplesCount)
Update audio stream buffers with data.
Definition: AudioStream.hpp:65
raylib::AudioStream::Close
void Close()
Close audio stream and free memory.
Definition: AudioStream.hpp:73
raylib::AudioStream::~AudioStream
~AudioStream()
Definition: AudioStream.hpp:48
raylib::AudioStream::Resume
AudioStream & Resume()
Resume audio stream.
Definition: AudioStream.hpp:103
raylib::AudioStream::SetBufferSizeDefault
static void SetBufferSizeDefault(int size)
Default size for new audio streams.
Definition: AudioStream.hpp:142
raylib::AudioStream::AudioStream
AudioStream(const ::AudioStream &music)
Definition: AudioStream.hpp:37
raylib::AudioStream::Play
AudioStream & Play()
Play audio stream.
Definition: AudioStream.hpp:87
raylib::AudioStream::IsProcessed
bool IsProcessed() const
Check if any audio stream buffers requires refill.
Definition: AudioStream.hpp:80
raylib::AudioStream::Pause
AudioStream & Pause()
Pause audio stream.
Definition: AudioStream.hpp:95
raylib::AudioStream::SetPitch
AudioStream & SetPitch(float pitch)
Set pitch for audio stream (1.0 is base level)
Definition: AudioStream.hpp:134
raylib::AudioStream::set
void set(const ::AudioStream &stream)
Definition: AudioStream.hpp:147
raylib::AudioStream
AudioStream management functions.
Definition: AudioStream.hpp:35
raylib::AudioStream::SetVolume
AudioStream & SetVolume(float volume)
Set volume for audio stream (1.0 is max level)
Definition: AudioStream.hpp:126
raylib::AudioStream::AudioStream
AudioStream(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels)
Init audio stream (to stream raw audio pcm data)
Definition: AudioStream.hpp:44