1#ifndef RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
2#define RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
4#include "./RaylibException.hpp"
14 : ::AudioStream(music) {
19 rAudioBuffer* buffer =
nullptr,
20 rAudioProcessor* processor =
nullptr,
21 unsigned int sampleRate = 0,
22 unsigned int sampleSize = 0,
23 unsigned int channels = 0)
24 : ::AudioStream{buffer, processor, sampleRate, sampleSize, channels} {
33 AudioStream(
unsigned int sampleRate,
unsigned int sampleSize,
unsigned int channels = 2) {
34 Load(sampleRate, sampleSize, channels);
42 other.buffer =
nullptr;
43 other.processor =
nullptr;
49 ~AudioStream() {
Unload(); }
51 GETTER(rAudioBuffer*, Buffer, buffer)
52 GETTER(rAudioProcessor*, Processor, processor)
53 GETTER(
unsigned int, SampleRate, sampleRate)
54 GETTER(
unsigned int, SampleSize, sampleSize)
55 GETTER(
unsigned int, Channels, channels)
57 AudioStream& operator=(const ::AudioStream& stream) {
62 AudioStream& operator=(
const AudioStream&) =
delete;
64 AudioStream& operator=(AudioStream&& other)
noexcept {
72 other.buffer =
nullptr;
73 other.processor =
nullptr;
85 ::UpdateAudioStream(*
this, data, samplesCount);
93 ::UpdateAudioStream(*
this, data.data(),
static_cast<int>(data.size()));
102 ::UnloadAudioStream(*
this);
109 [[nodiscard]]
bool IsProcessed()
const { return ::IsAudioStreamProcessed(*
this); }
115 ::PlayAudioStream(*
this);
123 ::PauseAudioStream(*
this);
131 ::ResumeAudioStream(*
this);
138 [[nodiscard]]
bool IsPlaying()
const { return ::IsAudioStreamPlaying(*
this); }
144 ::StopAudioStream(*
this);
152 ::SetAudioStreamVolume(*
this, volume);
160 ::SetAudioStreamPitch(*
this, pitch);
168 ::SetAudioStreamPan(*
this, pan);
180 void SetCallback(::AudioCallback callback) { ::SetAudioStreamCallback(*
this, callback); }
185 void AttachProcessor(::AudioCallback processor) { ::AttachAudioStreamProcessor(*
this, processor); }
190 void DetachProcessor(::AudioCallback processor) { ::DetachAudioStreamProcessor(*
this, processor); }
195 [[nodiscard]]
bool IsValid()
const { return ::IsAudioStreamValid(*
this); }
202 void Load(
unsigned int SampleRate,
unsigned int SampleSize,
unsigned int Channels = 2) {
204 set(::LoadAudioStream(SampleRate, SampleSize, Channels));
210 void set(const ::AudioStream& stream) {
211 buffer = stream.buffer;
212 processor = stream.processor;
213 sampleRate = stream.sampleRate;
214 sampleSize = stream.sampleSize;
215 channels = stream.channels;
AudioStream management functions.
void SetCallback(::AudioCallback callback)
Audio thread callback to request new data.
AudioStream & Stop()
Stop audio stream.
bool IsValid() const
Retrieve whether or not the audio stream is ready.
AudioStream & SetPitch(float pitch)
Set pitch for audio stream (1.0 is base level)
AudioStream & SetVolume(float volume=1.0f)
Set volume for audio stream (1.0 is max level)
bool IsProcessed() const
Check if any audio stream buffers requires refill.
AudioStream & Play()
Play audio stream.
bool IsPlaying() const
Check if audio stream is playing.
void AttachProcessor(::AudioCallback processor)
Attach audio stream processor to stream.
void Load(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels=2)
Load audio stream (to stream raw audio pcm data)
void Unload()
Unload audio stream and free memory.
static void SetBufferSizeDefault(int size)
Default size for new audio streams.
AudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels=2)
Init audio stream (to stream raw audio pcm data)
AudioStream & Update(std::span< std::byte > data)
Update audio stream buffers with data.
AudioStream & Pause()
Pause audio stream.
void DetachProcessor(::AudioCallback processor)
Detach audio stream processor from stream.
AudioStream & Resume()
Resume audio stream.
AudioStream & Update(const void *data, int samplesCount)
Update audio stream buffers with data.
AudioStream & SetPan(float pan=0.5f)
Set pan for audio stream (0.5 is centered)
Exception used for most raylib-related exceptions.
All raylib-cpp classes and functions appear in the raylib namespace.