pub struct AudioStream<'a>(/* private fields */);Expand description
Low-level raw PCM streaming primitive.
AudioStream lets you push arbitrary audio data to the audio device one
buffer at a time, giving full control over sample rate, bit depth, and channel
count. This is the replacement for the audio-callback API that was removed in
raylib 6.0 — instead of registering a callback you periodically check
IsAudioStreamProcessed and push the next buffer of samples.
Create via RaylibAudio::new_audio_stream. Freed via UnloadAudioStream on
drop. Lifetime is bound to the owning RaylibAudio.
§Examples
Create a stereo 44.1 kHz stream and push silence each frame:
use raylib::prelude::*;
let audio = RaylibAudio::init_audio_device().unwrap();
let stream = audio.new_audio_stream(44100, 16, 2);
// Push PCM data when the device is ready for more samples.
let silence: Vec<i16> = vec![0; 4096];
unsafe { raylib::ffi::UpdateAudioStream(*stream, silence.as_ptr() as *const _, silence.len() as i32) };Implementations§
Source§impl<'a> AudioStream<'a>
impl<'a> AudioStream<'a>
Sourcepub unsafe fn unwrap(self) -> AudioStream
pub unsafe fn unwrap(self) -> AudioStream
Take the raw ffi type. Must manually free memory by calling the proper unload function
§Safety
The caller is responsible for freeing the returned value by calling the appropriate raylib unload function. Failure to do so will leak resources.
Source§impl AudioStream<'_>
impl AudioStream<'_>
Sourcepub fn is_audio_stream_valid(&self) -> bool
pub fn is_audio_stream_valid(&self) -> bool
Checks if an audio stream is valid (buffers initialized)
Sourcepub const fn sample_rate(&self) -> u32
pub const fn sample_rate(&self) -> u32
Frequency (samples per second)
Sourcepub const fn sample_size(&self) -> u32
pub const fn sample_size(&self) -> u32
Bit depth (bits per sample): 8, 16, 32 (24 not supported)
Sourcepub unsafe fn inner(self) -> AudioStream
pub unsafe fn inner(self) -> AudioStream
§Safety
Caller takes ownership of the raw audio stream and must free it via UnloadAudioStream.
Sourcepub fn update<T: AudioSample>(
&mut self,
data: &[T],
) -> Result<(), UpdateAudioStreamError>
pub fn update<T: AudioSample>( &mut self, data: &[T], ) -> Result<(), UpdateAudioStreamError>
Updates audio stream buffers with data.
Sourcepub fn is_playing(&self) -> bool
pub fn is_playing(&self) -> bool
Checks if audio stream is currently playing.
Sourcepub fn set_volume(&self, volume: f32)
pub fn set_volume(&self, volume: f32)
Sets volume for audio stream (1.0 is max level).
Sourcepub fn is_processed(&self) -> bool
pub fn is_processed(&self) -> bool
Sets pitch for audio stream (1.0 is base level).