Struct AudioStream
pub struct AudioStream { /* private fields */ }
dep_sdl3
only.Implementations§
§impl AudioStream
impl AudioStream
pub fn stream(&mut self) -> *mut SDL_AudioStream
pub fn stream(&mut self) -> *mut SDL_AudioStream
Get the SDL_AudioStream pointer.
pub fn device_id(&self) -> Option<AudioDeviceID> ⓘ
pub fn device_id(&self) -> Option<AudioDeviceID> ⓘ
Get the device ID bound to the stream.
If the stream is not bound to a device, this will return None
.
pub fn device_name(&self) -> Option<String> ⓘ
pub fn new(
src_spec: Option<&AudioSpec>,
dst_spec: Option<&AudioSpec>,
audio_subsystem: &AudioSubsystem,
) -> Result<AudioStream, Error> ⓘ
👎Deprecated: use subsystem.new_stream(...)
(where subsystem is an AudioSubsystem
) instead
pub fn new( src_spec: Option<&AudioSpec>, dst_spec: Option<&AudioSpec>, audio_subsystem: &AudioSubsystem, ) -> Result<AudioStream, Error> ⓘ
subsystem.new_stream(...)
(where subsystem is an AudioSubsystem
) insteadCreates a new audio stream that converts audio data from the source format (src_spec
)
to the destination format (dst_spec
).
§Arguments
src_spec
- The format details of the input audio.dst_spec
- The format details of the output audio.
§Returns
Returns Ok(AudioStream)
on success or an error message on failure.
§Safety
This function is safe to call from any thread.
pub fn new_playback_stream(
app_spec: &AudioSpec,
device_spec: Option<&AudioSpec>,
audio_subsystem: &AudioSubsystem,
) -> Result<AudioStream, Error> ⓘ
👎Deprecated: use subsystem.new_playback_stream(...)
(where subsystem is an AudioSubsystem
) instead
pub fn new_playback_stream( app_spec: &AudioSpec, device_spec: Option<&AudioSpec>, audio_subsystem: &AudioSubsystem, ) -> Result<AudioStream, Error> ⓘ
subsystem.new_playback_stream(...)
(where subsystem is an AudioSubsystem
) insteadCreates a new audio stream for playback.
§Arguments
app_spec
- The format of audio data the application will provide.device_spec
- The format of audio data the audio device expects. IfNone
, SDL will choose an appropriate format.
pub fn new_recording_stream(
device_spec: Option<&AudioSpec>,
app_spec: &AudioSpec,
audio_subsystem: &AudioSubsystem,
) -> Result<AudioStream, Error> ⓘ
👎Deprecated: use subsystem.new_recording_stream(...)
(where subsystem is an AudioSubsystem
) instead
pub fn new_recording_stream( device_spec: Option<&AudioSpec>, app_spec: &AudioSpec, audio_subsystem: &AudioSubsystem, ) -> Result<AudioStream, Error> ⓘ
subsystem.new_recording_stream(...)
(where subsystem is an AudioSubsystem
) insteadCreates a new audio stream for recording.
§Arguments
device_spec
- The format of audio data the audio device provides. IfNone
, SDL will choose an appropriate format.app_spec
- The format of audio data the application wants to receive.
pub fn open_device_stream(
device_id: AudioDeviceID,
spec: Option<&AudioSpec>,
audio_subsystem: &AudioSubsystem,
) -> Result<AudioStream, Error> ⓘ
👎Deprecated: use device.open_device_stream(spec)
(where device is an AudioDevice
) instead
pub fn open_device_stream( device_id: AudioDeviceID, spec: Option<&AudioSpec>, audio_subsystem: &AudioSubsystem, ) -> Result<AudioStream, Error> ⓘ
device.open_device_stream(spec)
(where device is an AudioDevice
) insteadCreate an AudioStream
for this device with the specified spec.
This device will be closed when the stream is dropped.
The device begins paused, so you must call stream.resume()
to start playback.
pub fn get_format(
&self,
) -> Result<(Option<AudioSpec>, Option<AudioSpec>), Error> ⓘ
pub fn get_format( &self, ) -> Result<(Option<AudioSpec>, Option<AudioSpec>), Error> ⓘ
Retrieves the source and destination formats of the audio stream.
Returns a tuple (src_spec, dst_spec)
where each is an Option<AudioSpec>
.
pub fn get_gain(&self) -> Result<f32, Error> ⓘ
pub fn get_gain(&self) -> Result<f32, Error> ⓘ
Retrieves the gain of the audio stream.
Returns the gain as a f32
on success, or an error message on failure.
pub fn available_bytes(&self) -> Result<i32, Error> ⓘ
pub fn available_bytes(&self) -> Result<i32, Error> ⓘ
Gets the number of converted/resampled bytes available.
pub fn read_f32_samples(&mut self, buf: &mut [f32]) -> Result<usize, Error> ⓘ
pub fn read_f32_samples(&mut self, buf: &mut [f32]) -> Result<usize, Error> ⓘ
Reads samples as f32 into the provided buffer. Returns the number of samples read.
Trait Implementations§
§impl Debug for AudioStream
impl Debug for AudioStream
§impl Display for AudioStream
impl Display for AudioStream
§impl Drop for AudioStream
impl Drop for AudioStream
§impl Read for AudioStream
impl Read for AudioStream
§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> ⓘ
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> ⓘ
Reads audio data from the stream.
Note that this reads bytes from the stream, not samples.
You must convert the bytes to samples based on the format of the stream.
read_f32_samples
and read_i16_samples
are provided for convenience.
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error> ⓘ
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error> ⓘ
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error> ⓘ
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error> ⓘ
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error> ⓘ
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error> ⓘ
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error> ⓘ
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error> ⓘ
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error> ⓘ
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error> ⓘ
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error> ⓘ
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error> ⓘ
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreAuto Trait Implementations§
impl Freeze for AudioStream
impl RefUnwindSafe for AudioStream
impl !Send for AudioStream
impl !Sync for AudioStream
impl Unpin for AudioStream
impl UnwindSafe for AudioStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more