pub struct Data { /* private fields */ }Expand description
A buffer of dynamically typed audio data, passed to raw stream callbacks.
Raw input stream callbacks receive &Data, while raw output stream callbacks expect &mut Data.
Implementations§
Source§impl Data
impl Data
Sourcepub unsafe fn from_parts(
data: *mut (),
len: usize,
sample_format: SampleFormat,
) -> Self
pub unsafe fn from_parts( data: *mut (), len: usize, sample_format: SampleFormat, ) -> Self
Constructor for host implementations to use.
§Safety
The following requirements must be met in order for the safety of Data’s API.
- The
datapointer must point to the first sample in the slice containing all samples. - The
lenmust describe the length of the buffer as a number of samples in the expected format specified via thesample_formatargument. - The
sample_formatmust correctly represent the underlying sample data delivered/expected by the stream.
Sourcepub fn sample_format(&self) -> SampleFormat
pub fn sample_format(&self) -> SampleFormat
The sample format of the internal audio data.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The full length of the buffer in samples.
The returned length is the same length as the slice of type T that would be returned via
as_slice given a sample type that matches the inner sample format.
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
The raw slice of memory representing the underlying audio data as a slice of bytes.
It is up to the user to interpret the slice of memory based on Data::sample_format.
Sourcepub fn bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn bytes_mut(&mut self) -> &mut [u8] ⓘ
The raw slice of memory representing the underlying audio data as a slice of bytes.
It is up to the user to interpret the slice of memory based on Data::sample_format.
Sourcepub fn as_slice<T>(&self) -> Option<&[T]>where
T: SizedSample,
pub fn as_slice<T>(&self) -> Option<&[T]>where
T: SizedSample,
Access the data as a slice of sample type T.
Returns None if the sample type does not match the expected sample format.
Sourcepub fn as_slice_mut<T>(&mut self) -> Option<&mut [T]>where
T: SizedSample,
pub fn as_slice_mut<T>(&mut self) -> Option<&mut [T]>where
T: SizedSample,
Access the data as a slice of sample type T.
Returns None if the sample type does not match the expected sample format.