mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 05:32:32 +00:00
conversions::Sample: Fix bug in linear interpolation for u16
The previous implementation panicked if first > second.
This commit is contained in:
parent
96e743746c
commit
42e2e53f66
1 changed files with 5 additions and 1 deletions
|
@ -84,7 +84,11 @@ pub trait Sample: CpalSample {
|
|||
impl Sample for u16 {
|
||||
#[inline]
|
||||
fn lerp(first: u16, second: u16, numerator: u32, denominator: u32) -> u16 {
|
||||
(first as u32 + (second as u32 - first as u32) * numerator / denominator) as u16
|
||||
let a = first as i32;
|
||||
let b = second as i32;
|
||||
let n = numerator as i32;
|
||||
let d = denominator as i32;
|
||||
(a + (b - a) * n / d) as u16
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in a new issue