Skip to content

Commit 3dca0b4

Browse files
Merge pull request #107 from 0xcaff/fix/sinc-nan
Fix/sinc nan
2 parents dbf19c5 + 29d2c37 commit 3dca0b4

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/interpolate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ where
323323
(0..max_depth).fold(Self::Frame::equilibrium(), |mut v, n| {
324324
v = {
325325
let a = PI * (phil + n as f64);
326-
let first = sin(a) / a;
326+
let first = if a == 0.0 { 1.0 } else { sin(a) / a };
327327
let second = 0.5 + 0.5 * cos(a / (phil + max_depth as f64));
328328
v.zip_map(self.frames[nr - n], |vs, r_lag| {
329329
vs.add_amp(
@@ -335,7 +335,7 @@ where
335335
};
336336

337337
let a = PI * (phir + n as f64);
338-
let first = sin(a) / a;
338+
let first = if a == 0.0 { 1.0 } else { sin(a) / a };
339339
let second = 0.5 + 0.5 * cos(a / (phir + max_depth as f64));
340340
v.zip_map(self.frames[nl + n], |vs, r_lag| {
341341
vs.add_amp(

tests/interpolate.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
extern crate sample;
44

5-
use sample::interpolate::{Converter, Floor, Linear};
5+
use sample::interpolate::{Converter, Floor, Linear, Sinc};
6+
use sample::ring_buffer;
67
use sample::{signal, Signal};
78

89
#[test]
@@ -53,3 +54,18 @@ fn test_scale_playback_rate() {
5354
&[[0.0], [0.5], [1.0], [0.5], [0.0], [-0.5], [-1.0], [-0.5]][..]
5455
);
5556
}
57+
58+
#[test]
59+
fn test_sinc() {
60+
let foo = [[0.0f64], [1.0], [0.0], [-1.0]];
61+
let source = signal::from_iter(foo.iter().cloned());
62+
63+
let frames = ring_buffer::Fixed::from(vec![[0.0]; 50]);
64+
let interp = Sinc::new(frames);
65+
let resampled = source.from_hz_to_hz(interp, 44100.0, 11025.0);
66+
67+
assert_eq!(
68+
resampled.until_exhausted().find(|sample| sample[0].is_nan()),
69+
None
70+
);
71+
}

0 commit comments

Comments
 (0)