Skip to main content

AudioStream

Struct AudioStream 

Source
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>

Source

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<'_>

Source

pub fn is_audio_stream_valid(&self) -> bool

Checks if an audio stream is valid (buffers initialized)

Source

pub const fn sample_rate(&self) -> u32

Frequency (samples per second)

Source

pub const fn sample_size(&self) -> u32

Bit depth (bits per sample): 8, 16, 32 (24 not supported)

Source

pub const fn channels(&self) -> u32

Number of channels (1-mono, 2-stereo, …)

Source

pub unsafe fn inner(self) -> AudioStream

§Safety

Caller takes ownership of the raw audio stream and must free it via UnloadAudioStream.

Source

pub fn update<T: AudioSample>( &mut self, data: &[T], ) -> Result<(), UpdateAudioStreamError>

Updates audio stream buffers with data.

Source

pub fn play(&self)

Plays audio stream.

Source

pub fn pause(&self)

Pauses audio stream.

Source

pub fn resume(&self)

Resumes audio stream.

Source

pub fn is_playing(&self) -> bool

Checks if audio stream is currently playing.

Source

pub fn stop(&self)

Stops audio stream.

Source

pub fn set_volume(&self, volume: f32)

Sets volume for audio stream (1.0 is max level).

Source

pub fn set_pitch(&self, pitch: f32)

Sets pitch for audio stream (1.0 is base level).

Source

pub fn is_processed(&self) -> bool

Sets pitch for audio stream (1.0 is base level).

Source

pub fn set_pan(&self, pan: f32)

Set pan for audio stream (0.5 is centered)

Trait Implementations§

Source§

impl<'a> AsRawMut<AudioStream> for AudioStream<'a>

Source§

unsafe fn as_raw_mut(&mut self) -> &mut AudioStream

Mutable access to the wrapped raw FFI value. Read more
Source§

impl<'a> AsRef<AudioStream> for AudioStream<'a>

Source§

fn as_ref(&self) -> &AudioStream

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Debug for AudioStream<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Deref for AudioStream<'a>

Source§

type Target = AudioStream

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> Drop for AudioStream<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !Send for AudioStream<'a>

§

impl<'a> !Sync for AudioStream<'a>

§

impl<'a> Freeze for AudioStream<'a>

§

impl<'a> RefUnwindSafe for AudioStream<'a>

§

impl<'a> Unpin for AudioStream<'a>

§

impl<'a> UnsafeUnpin for AudioStream<'a>

§

impl<'a> UnwindSafe for AudioStream<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.