Remove UnknownTypeBuffer in favour of specifying sample type.
This is an implementation of the planned changes described in #119. For a quick overview of how the API has changed, check out the updated examples. **TODO:** - [x] Update API. - [x] Update examples. - [ ] Remove `data_type` field from `Format` (see [here](https://github.com/RustAudio/cpal/issues/119#issuecomment-573788380)). - Update backends: - [x] null - [x] ALSA - [ ] ASIO - [ ] WASAPI - [ ] CoreAudio - [ ] Emscripten Closes #119 Closes #260
This commit is contained in:
parent
c4ef3ac14c
commit
05b62bb1c0
9 changed files with 543 additions and 420 deletions
|
|
@ -21,20 +21,12 @@ impl SampleFormat {
|
|||
&SampleFormat::F32 => mem::size_of::<f32>(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Deprecated. Use `sample_size` instead.
|
||||
#[inline]
|
||||
#[deprecated]
|
||||
pub fn get_sample_size(&self) -> usize {
|
||||
self.sample_size()
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for containers that contain PCM data.
|
||||
pub unsafe trait Sample: Copy + Clone {
|
||||
/// Returns the `SampleFormat` corresponding to this data type.
|
||||
// TODO: rename to `format()`. Requires a breaking change.
|
||||
fn get_format() -> SampleFormat;
|
||||
/// The `SampleFormat` corresponding to this data type.
|
||||
const FORMAT: SampleFormat;
|
||||
|
||||
/// Turns the sample into its equivalent as a floating-point.
|
||||
fn to_f32(&self) -> f32;
|
||||
|
|
@ -49,10 +41,7 @@ pub unsafe trait Sample: Copy + Clone {
|
|||
}
|
||||
|
||||
unsafe impl Sample for u16 {
|
||||
#[inline]
|
||||
fn get_format() -> SampleFormat {
|
||||
SampleFormat::U16
|
||||
}
|
||||
const FORMAT: SampleFormat = SampleFormat::U16;
|
||||
|
||||
#[inline]
|
||||
fn to_f32(&self) -> f32 {
|
||||
|
|
@ -82,10 +71,7 @@ unsafe impl Sample for u16 {
|
|||
}
|
||||
|
||||
unsafe impl Sample for i16 {
|
||||
#[inline]
|
||||
fn get_format() -> SampleFormat {
|
||||
SampleFormat::I16
|
||||
}
|
||||
const FORMAT: SampleFormat = SampleFormat::I16;
|
||||
|
||||
#[inline]
|
||||
fn to_f32(&self) -> f32 {
|
||||
|
|
@ -119,10 +105,7 @@ unsafe impl Sample for i16 {
|
|||
}
|
||||
|
||||
unsafe impl Sample for f32 {
|
||||
#[inline]
|
||||
fn get_format() -> SampleFormat {
|
||||
SampleFormat::F32
|
||||
}
|
||||
const FORMAT: SampleFormat = SampleFormat::F32;
|
||||
|
||||
#[inline]
|
||||
fn to_f32(&self) -> f32 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue