conversions::Sample: Fix bug in linear interpolation for u16

The previous implementation panicked if first > second.
This commit is contained in:
Nicolas Braud-Santoni 2020-10-01 16:48:28 +02:00
parent 96e743746c
commit 42e2e53f66
No known key found for this signature in database
GPG key ID: E6F98EE292D5ECCB

View file

@ -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]