Struct spectrusty_audio::host::sdl2::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>
impl<T: AudioFormatNum + AudioSample> AudioHandle<T>
sourcepub fn status(&self) -> AudioStatus
pub fn status(&self) -> AudioStatus
Returns the status of the audio device playback.
sourcepub fn close(self) -> AudioFrameConsumer<T>
pub fn close(self) -> AudioFrameConsumer<T>
Closes audio playback and frees underlying resources. Returns the unwrapped frame consumer.
sourcepub fn create(
sdl_context: &Sdl,
frame_duration_nanos: u32,
latency: usize
) -> Result<Self, AudioHandleError>
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 actuallatency
argument passed to the create_carousel may be larger but never smaller than the provided one.
sourcepub fn create_with_specs(
sdl_context: &Sdl,
desired_spec: AudioSpecDesired,
frame_duration_nanos: u32,
latency: usize
) -> Result<Self, AudioHandleError>
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 actuallatency
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.
Examples found in repository?
101 102 103 104 105 106 107 108 109 110 111 112 113
pub fn create(
sdl_context: &Sdl,
frame_duration_nanos: u32,
latency: usize
) -> Result<Self, AudioHandleError>
{
Self::create_with_specs(
sdl_context,
AudioSpecDesired { freq: None, channels: None, samples: None },
frame_duration_nanos,
latency
)
}
Auto Trait Implementations§
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<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
source§fn into_sample(self) -> S
fn into_sample(self) -> S
S
a sample type from self
.