Skip to content

Instantly share code, notes, and snippets.

@geraintluff
Created June 15, 2026 07:26
Show Gist options
  • Select an option

  • Save geraintluff/3d289f7bdfb158562faf31300355341e to your computer and use it in GitHub Desktop.

Select an option

Save geraintluff/3d289f7bdfb158562faf31300355341e to your computer and use it in GitHub Desktop.
C++ Bark-scale approximation
template<typename Sample=double>
struct BarkScale {
Sample barkToHz(Sample bark) const {
return (a + b*bark)/(c + d*bark);
}
Sample hzToBark(Sample hz) const {
return (c*hz - a)/(b - d*hz);
}
Sample barkToBw(Sample bark) const {
Sample div = c + d*bark;
return bcad/(div*div);
}
Sample hzToBw(Sample hz) const {
Sample l = b - d*hz;
return l*l/bcad;
}
private:
// specialised from signalsmith::curves::Reciprocal<>::barkScale
static constexpr Sample a = -289.6141814389989;
static constexpr Sample b = 1176.757038581856;
static constexpr Sample c = 15.33854709767119;
static constexpr Sample d = -0.5528328119568996;
static constexpr Sample bcad = b*c - a*d;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment