RFC: Rework the API [WIP] (#165)
* Rework the API to not use futures anymore * Add some comments * Update the MacOS backend * Restore the null implementation * Add an emscripten backend * Remove erroneously added feature * Fix to_f32 formula * [WIP] Alsa backend * Alsa backend compiling * Working ALSA backend * Fix tests * Move WASAPI endpoint to endpoint module * Fix WASAPI warnings * Rework the WASAPI backend * Check overflows for voice ID * Add comments and minor fixes to WASAPI backend * Add a changelog
This commit is contained in:
parent
4b019243c2
commit
6ae01f437c
13 changed files with 1472 additions and 1447 deletions
|
|
@ -35,6 +35,9 @@ 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;
|
||||
|
||||
/// Turns the sample into its equivalent as a floating-point.
|
||||
fn to_f32(&self) -> f32;
|
||||
}
|
||||
|
||||
unsafe impl Sample for u16 {
|
||||
|
|
@ -42,6 +45,11 @@ unsafe impl Sample for u16 {
|
|||
fn get_format() -> SampleFormat {
|
||||
SampleFormat::U16
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn to_f32(&self) -> f32 {
|
||||
((*self as f32 / u16::max_value() as f32) - 0.5) * 2.0 // TODO: maybe wrong
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for i16 {
|
||||
|
|
@ -49,6 +57,15 @@ unsafe impl Sample for i16 {
|
|||
fn get_format() -> SampleFormat {
|
||||
SampleFormat::I16
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn to_f32(&self) -> f32 {
|
||||
if *self < 0 {
|
||||
*self as f32 / -(::std::i16::MIN as f32)
|
||||
} else {
|
||||
*self as f32 / ::std::i16::MAX as f32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sample for f32 {
|
||||
|
|
@ -56,4 +73,9 @@ unsafe impl Sample for f32 {
|
|||
fn get_format() -> SampleFormat {
|
||||
SampleFormat::F32
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn to_f32(&self) -> f32 {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue