Skip to content

Commit f2f0197

Browse files
committed
fix: scale sinc kernel by bandwidth
1 parent 05cb4a9 commit f2f0197

File tree

1 file changed

+18
-6
lines changed
  • dasp_interpolate/src/sinc

1 file changed

+18
-6
lines changed

dasp_interpolate/src/sinc/mod.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,15 @@ where
9393

9494
(0..max_depth).fold(Self::Frame::EQUILIBRIUM, |mut v, n| {
9595
v = {
96-
let a = PI * bandwidth * (phil + n as f64);
97-
let first = if a == 0.0 { 1.0 } else { sin(a) / a };
98-
let second = 0.5 + 0.5 * cos(a / (depth as f64 * bandwidth));
96+
let t = phil + n as f64;
97+
let a = PI * bandwidth * t;
98+
let b = PI * t / depth as f64;
99+
let first = if a.abs() < f64::EPSILON {
100+
bandwidth
101+
} else {
102+
bandwidth * sin(a) / a
103+
};
104+
let second = 0.5 + 0.5 * cos(b);
99105
v.zip_map(self.frames[nl - n], |vs, r_lag| {
100106
vs.add_amp(
101107
(first * second * r_lag.to_sample::<f64>())
@@ -105,9 +111,15 @@ where
105111
})
106112
};
107113

108-
let a = PI * bandwidth * (phir + n as f64);
109-
let first = if a == 0.0 { 1.0 } else { sin(a) / a };
110-
let second = 0.5 + 0.5 * cos(a / (depth as f64 * bandwidth));
114+
let t = phir + n as f64;
115+
let a = PI * bandwidth * t;
116+
let b = PI * t / depth as f64;
117+
let first = if a.abs() < f64::EPSILON {
118+
bandwidth
119+
} else {
120+
bandwidth * sin(a) / a
121+
};
122+
let second = 0.5 + 0.5 * cos(b);
111123
v.zip_map(self.frames[nr + n], |vs, r_lag| {
112124
vs.add_amp(
113125
(first * second * r_lag.to_sample::<f64>())

0 commit comments

Comments
 (0)