AudioHandle

Struct AudioHandle 

Source
pub struct AudioHandle<T: AudioFormatNum + AudioSample> {
    pub sample_rate: u32,
    pub channels: u8,
    pub samples: u16,
    pub producer: AudioFrameProducer<T>,
    /* private fields */
}
Expand description

The struct for producing and controlling the audio playback.

It embeds the interconnected pair of carousel’s AudioFrameProducer with the AudioFrameConsumer directly exposing the producer to the user. The consumer lives in the SDL2 audio thread and is responsible for filling up the audio output buffer with sample data sent from the producer.

The T parameter should be one of the sample primitives.

Fields§

§sample_rate: u32

The audio sample frequency of the output stream.

§channels: u8

The number of audio channels in the output stream.

§samples: u16

The number of samples in the output audio buffer.

§producer: AudioFrameProducer<T>

The audio sample producer, interconnected with an audio consumer living in the audio thread.

Implementations§

Source§

impl<T: AudioFormatNum + AudioSample> AudioHandle<T>

Source

pub fn status(&self) -> AudioStatus

Returns the status of the audio device playback.

Source

pub fn play(&self)

Starts playback of the audio device.

Source

pub fn pause(&self)

Pauses playback of the audio device.

Source

pub fn close(self) -> AudioFrameConsumer<T>

Closes audio playback and frees underlying resources. Returns the unwrapped frame consumer.

Source

pub fn create( sdl_context: &Sdl, frame_duration_nanos: u32, latency: usize, ) -> Result<Self, AudioHandleError>

Creates an instance of the AudioHandle from the provided SDL2 context.

The audio parameters used by default are the sample rate of 44100, 2 channels, and the output buffer size adjusted to the requested latency.

  • frame_duration_nanos is the duration in nanoseconds of the standard emulation frame.
  • latency is the requested audio latency; the actual latency argument passed to the create_carousel may be larger but never smaller than the provided one.
Source

pub fn create_with_specs( sdl_context: &Sdl, desired_spec: AudioSpecDesired, frame_duration_nanos: u32, latency: usize, ) -> Result<Self, AudioHandleError>

Creates an instance of the AudioHandle from the provided SDL2 context with the desired audio parameters.

The audio parameters used by default are the sample rate of 44100, 2 channels, and the output buffer size adjusted to the requested latency.

  • frame_duration_nanos is the duration in nanoseconds of the standard emulation frame.
  • latency is the requested audio latency; the actual latency argument passed to the create_carousel may be larger but never smaller than the provided one.
  • desired_spec can be populated with the desired audio parameters.

Auto Trait Implementations§

§

impl<T> Freeze for AudioHandle<T>

§

impl<T> RefUnwindSafe for AudioHandle<T>
where T: RefUnwindSafe,

§

impl<T> !Send for AudioHandle<T>

§

impl<T> !Sync for AudioHandle<T>

§

impl<T> Unpin for AudioHandle<T>
where T: Unpin,

§

impl<T> UnwindSafe for AudioHandle<T>
where T: UnwindSafe,

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<S, T> IntoSample<S> for T
where S: FromSample<T>,

Source§

fn into_sample(self) -> S

Convert to S a sample type from self.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.