Skip to content

Commit

Permalink
Avoid using std::cyl_bessel_i
Browse files Browse the repository at this point in the history
We can't rely on it because it's "optional", and some systems report it at
compile time but then fail to load at runtime.
  • Loading branch information
kcat committed Aug 27, 2024
1 parent adc4574 commit 3261333
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
11 changes: 3 additions & 8 deletions common/polyphase_resampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ namespace {

constexpr double Epsilon{1e-9};

#if __cpp_lib_math_special_functions >= 201603L
using std::cyl_bessel_i;

#else

/* The zero-order modified Bessel function of the first kind, used for the
* Kaiser window.
Expand All @@ -33,7 +29,7 @@ using std::cyl_bessel_i;
* compounding the rounding and precision error), but it's good enough.
*/
template<typename T, typename U>
U cyl_bessel_i(T nu, U x)
constexpr auto cyl_bessel_i(T nu, U x) -> U
{
if(nu != T{0})
throw std::runtime_error{"cyl_bessel_i: nu != 0"};
Expand All @@ -57,7 +53,6 @@ U cyl_bessel_i(T nu, U x)
} while(sum != last_sum);
return static_cast<U>(sum);
}
#endif

/* This is the normalized cardinal sine (sinc) function.
*
Expand Down Expand Up @@ -89,7 +84,7 @@ double Kaiser(const double beta, const double k, const double besseli_0_beta)
{
if(!(k >= -1.0 && k <= 1.0))
return 0.0;
return cyl_bessel_i(0, beta * std::sqrt(1.0 - k*k)) / besseli_0_beta;
return ::cyl_bessel_i(0, beta * std::sqrt(1.0 - k*k)) / besseli_0_beta;
}

/* Calculates the size (order) of the Kaiser window. Rejection is in dB and
Expand Down Expand Up @@ -158,7 +153,7 @@ void PPhaseResampler::init(const uint srcRate, const uint dstRate)
// calculating the left offset to avoid increasing the transition width.
const uint l{(CalcKaiserOrder(180.0, width)+1) / 2};
const double beta{CalcKaiserBeta(180.0)};
const double besseli_0_beta{cyl_bessel_i(0, beta)};
const double besseli_0_beta{::cyl_bessel_i(0, beta)};
mM = l*2 + 1;
mL = l;
mF.resize(mM);
Expand Down
11 changes: 3 additions & 8 deletions core/bsinc_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ namespace {

using uint = unsigned int;

#if __cpp_lib_math_special_functions >= 201603L
using std::cyl_bessel_i;

#else

/* The zero-order modified Bessel function of the first kind, used for the
* Kaiser window.
Expand All @@ -38,7 +34,7 @@ using std::cyl_bessel_i;
* compounding the rounding and precision error), but it's good enough.
*/
template<typename T, typename U>
U cyl_bessel_i(T nu, U x)
constexpr auto cyl_bessel_i(T nu, U x) -> U
{
if(nu != T{0})
throw std::runtime_error{"cyl_bessel_i: nu != 0"};
Expand All @@ -62,7 +58,6 @@ U cyl_bessel_i(T nu, U x)
} while(sum != last_sum);
return static_cast<U>(sum);
}
#endif

/* This is the normalized cardinal sine (sinc) function.
*
Expand Down Expand Up @@ -95,7 +90,7 @@ constexpr double Kaiser(const double beta, const double k, const double besseli_
{
if(!(k >= -1.0 && k <= 1.0))
return 0.0;
return cyl_bessel_i(0, beta * std::sqrt(1.0 - k*k)) / besseli_0_beta;
return ::cyl_bessel_i(0, beta * std::sqrt(1.0 - k*k)) / besseli_0_beta;
}

/* Calculates the (normalized frequency) transition width of the Kaiser window.
Expand Down Expand Up @@ -165,7 +160,7 @@ struct SIMDALIGN BSincFilterArray {
using filter_type = std::array<std::array<double,BSincPointsMax>,BSincPhaseCount>;
auto filter = std::vector<filter_type>(BSincScaleCount);

const double besseli_0_beta{cyl_bessel_i(0, hdr.beta)};
const double besseli_0_beta{::cyl_bessel_i(0, hdr.beta)};

/* Calculate the Kaiser-windowed Sinc filter coefficients for each
* scale and phase index.
Expand Down

0 comments on commit 3261333

Please sign in to comment.