Skip to content

Commit 8a5c2f7

Browse files
committed
diff by zero
1 parent 23035e2 commit 8a5c2f7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/rvoice/fluid_iir_filter.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ extern "C" void fluid_iir_filter_init_table(fluid_real_t sample_rate)
6060
template<typename R>
6161
static R interp_lin(R y0, R y1, R x0, R x1, R x)
6262
{
63-
return (y0 * (x1 - x) + y1 * (x - x0)) / (x1 - x0);
63+
return std::fabs(x1 - x0 < 1) // do not interpolate, if difference is less than a single cent
64+
? y0
65+
: (y0 * (x1 - x) + y1 * (x - x0)) / (x1 - x0);
6466
}
6567

6668
template<typename R>
@@ -112,7 +114,7 @@ static inline void fluid_iir_filter_calculate_coefficients(R fres,
112114
R omega = (R)(2.0 * M_PI) * (fres_hz / output_rate);
113115
coeff_accurate.sin = std::sin(omega);
114116
coeff_accurate.cos = std::cos(omega);
115-
117+
116118
std::cerr << "fres: " << std::fixed << std::setprecision(2) << fres_hz << " Hz | "
117119
<< "fres: " << std::fixed << std::setprecision(2) << fres << " Cents | "
118120
<< "sin: " << std::fixed << std::setprecision(6) << coeff.sin << " | "

0 commit comments

Comments
 (0)