11#ifndef MARVIN_RBJCOEFFICIENTS_H
12#define MARVIN_RBJCOEFFICIENTS_H
24 template <FloatType SampleType>
26 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
27 const auto fs{
static_cast<SampleType
>(sampleRate) };
28 const auto omega{ twoPi * (cutoff / fs) };
29 const auto cosOmega = std::cos(omega);
30 const auto sinOmega = std::sin(omega);
31 const auto alpha{ sinOmega / (
static_cast<SampleType
>(2.0) * q) };
32 const auto a0 = (
static_cast<SampleType
>(1.0) - cosOmega) /
static_cast<SampleType
>(2.0);
33 const auto a1 =
static_cast<SampleType
>(1.0) - cosOmega;
35 const auto b0 =
static_cast<SampleType
>(1.0) + alpha;
36 const auto b1 =
static_cast<SampleType
>(-2.0) * cosOmega;
37 const auto b2 =
static_cast<SampleType
>(1.0) - alpha;
55 template <FloatType SampleType>
57 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
58 const auto fs{
static_cast<SampleType
>(sampleRate) };
59 const auto omega{ twoPi * (cutoff / fs) };
60 const auto cosOmega = std::cos(omega);
61 const auto sinOmega = std::sin(omega);
62 const auto alpha{ sinOmega / (
static_cast<SampleType
>(2.0) * q) };
63 const auto a0 = (
static_cast<SampleType
>(1.0) + cosOmega) /
static_cast<SampleType
>(2.0);
64 const auto a1 =
static_cast<SampleType
>(-1.0) * (
static_cast<SampleType
>(1.0) + cosOmega);
66 const auto b0 =
static_cast<SampleType
>(1.0) + alpha;
67 const auto b1 =
static_cast<SampleType
>(-2.0) * cosOmega;
68 const auto b2 =
static_cast<SampleType
>(1.0) - alpha;
86 template <FloatType SampleType>
88 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
89 const auto fs{
static_cast<SampleType
>(sampleRate) };
90 const auto omega{ twoPi * (centreFrequency / fs) };
91 const auto cosOmega = std::cos(omega);
92 const auto sinOmega = std::sin(omega);
93 const auto log2Over2 = std::log(
static_cast<SampleType
>(2.0)) /
static_cast<SampleType
>(2.0);
94 const auto alpha = sinOmega * std::sinh(log2Over2 * bandwidth * (omega / sinOmega));
95 const auto a0 = (sinOmega /
static_cast<SampleType
>(2.0)) * (peakGain * alpha);
96 const auto a1 =
static_cast<SampleType
>(0.0);
97 const auto a2 =
static_cast<SampleType
>(-1.0) * (sinOmega /
static_cast<SampleType
>(2.0));
98 const auto b0 =
static_cast<SampleType
>(1.0) + alpha;
99 const auto b1 =
static_cast<SampleType
>(-2.0) * cosOmega;
100 const auto b2 =
static_cast<SampleType
>(1.0) - alpha;
118 template <FloatType SampleType>
120 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
121 const auto fs{
static_cast<SampleType
>(sampleRate) };
122 const auto omega{ twoPi * (centreFrequency / fs) };
123 const auto cosOmega = std::cos(omega);
124 const auto sinOmega = std::sin(omega);
125 const auto log2Over2 = std::log(
static_cast<SampleType
>(2.0)) /
static_cast<SampleType
>(2.0);
126 const auto alpha = sinOmega * std::sinh(log2Over2 * bandwidth * (omega / sinOmega));
127 const auto a0 = alpha;
128 const auto a1 =
static_cast<SampleType
>(0.0);
129 const auto a2 =
static_cast<SampleType
>(-1.0) * alpha;
130 const auto b0 =
static_cast<SampleType
>(1.0) + alpha;
131 const auto b1 =
static_cast<SampleType
>(-2.0) * cosOmega;
132 const auto b2 =
static_cast<SampleType
>(1.0) - alpha;
150 template <FloatType SampleType>
152 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
153 const auto fs{
static_cast<SampleType
>(sampleRate) };
154 const auto omega{ twoPi * (centreFrequency / fs) };
155 const auto cosOmega = std::cos(omega);
156 const auto sinOmega = std::sin(omega);
157 const auto log2Over2 = std::log(
static_cast<SampleType
>(2.0)) /
static_cast<SampleType
>(2.0);
158 const auto alpha = sinOmega * std::sinh(log2Over2 * bandwidth * (omega / sinOmega));
159 const auto a0 =
static_cast<SampleType
>(1.0);
160 const auto a1 =
static_cast<SampleType
>(-2.0) * cosOmega;
161 const auto a2 =
static_cast<SampleType
>(1.0);
162 const auto b0 =
static_cast<SampleType
>(1.0) + alpha;
163 const auto b1 =
static_cast<SampleType
>(-2.0) * cosOmega;
164 const auto b2 =
static_cast<SampleType
>(1.0) - alpha;
181 template <FloatType SampleType>
183 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
184 const auto fs{
static_cast<SampleType
>(sampleRate) };
185 const auto omega{ twoPi * (cutoff / fs) };
186 const auto cosOmega = std::cos(omega);
187 const auto sinOmega = std::sin(omega);
188 const auto log2Over2 = std::log(
static_cast<SampleType
>(2.0)) /
static_cast<SampleType
>(2.0);
189 const auto alpha = sinOmega * std::sinh(log2Over2 * q * (omega / sinOmega));
190 const auto a0 =
static_cast<SampleType
>(1.0) - alpha;
191 const auto a1 =
static_cast<SampleType
>(-2.0) * cosOmega;
192 const auto a2 =
static_cast<SampleType
>(1.0) + alpha;
193 const auto b0 =
static_cast<SampleType
>(1.0) + alpha;
194 const auto b1 =
static_cast<SampleType
>(-2.0) * cosOmega;
195 const auto b2 =
static_cast<SampleType
>(1.0) - alpha;
214 template <FloatType SampleType>
216 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
217 const auto fs{
static_cast<SampleType
>(sampleRate) };
218 const auto A = std::pow(
static_cast<SampleType
>(10.0), dbGain /
static_cast<SampleType
>(40.0));
219 const auto omega{ twoPi * (centreFrequency / fs) };
220 const auto cosOmega = std::cos(omega);
221 const auto sinOmega = std::sin(omega);
222 const auto log2Over2 = std::log(
static_cast<SampleType
>(2.0)) /
static_cast<SampleType
>(2.0);
223 const auto alpha = sinOmega * std::sinh(log2Over2 * bandwidth * (omega / sinOmega));
224 const auto a0 =
static_cast<SampleType
>(1.0) + (alpha * A);
225 const auto a1 =
static_cast<SampleType
>(-2.0) * cosOmega;
226 const auto a2 =
static_cast<SampleType
>(1.0) - (alpha * A);
227 const auto b0 =
static_cast<SampleType
>(1.0) + (alpha / A);
228 const auto b1 =
static_cast<SampleType
>(-2.0) * cosOmega;
229 const auto b2 =
static_cast<SampleType
>(1.0) - (alpha / A);
248 template <FloatType SampleType>
250 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
251 const auto fs{
static_cast<SampleType
>(sampleRate) };
252 const auto A = std::pow(
static_cast<SampleType
>(10.0), dbGain /
static_cast<SampleType
>(40.0));
253 const auto omega{ twoPi * (centreFrequency / fs) };
254 const auto cosOmega = std::cos(omega);
255 const auto sinOmega = std::sin(omega);
258 const auto slopeFrac = (
static_cast<SampleType
>(1.0) / slope) -
static_cast<SampleType
>(1.0);
263 const auto twoRootAAlpha = sinOmega * std::sqrt(((std::pow(A,
static_cast<SampleType
>(2.0)) +
static_cast<SampleType
>(1.0)) * slopeFrac) + (
static_cast<SampleType
>(2.0) * A));
264 const auto a0 = A * ((A +
static_cast<SampleType
>(1.0)) - ((A -
static_cast<SampleType
>(1.0)) * cosOmega) + twoRootAAlpha);
265 const auto a1 =
static_cast<SampleType
>(2.0) * A * ((A -
static_cast<SampleType
>(1.0)) - ((A +
static_cast<SampleType
>(1.0)) * cosOmega));
266 const auto a2 = A * ((A +
static_cast<SampleType
>(1.0)) - ((A -
static_cast<SampleType
>(1.0)) * cosOmega) - twoRootAAlpha);
267 const auto b0 = (A +
static_cast<SampleType
>(1.0)) + ((A -
static_cast<SampleType
>(1.0)) * cosOmega) + twoRootAAlpha;
268 const auto b1 =
static_cast<SampleType
>(-2.0) * ((A -
static_cast<SampleType
>(1.0)) + ((A +
static_cast<SampleType
>(1.0)) * cosOmega));
269 const auto b2 = (A +
static_cast<SampleType
>(1.0)) + ((A -
static_cast<SampleType
>(1.0)) * cosOmega) - twoRootAAlpha;
288 template <FloatType SampleType>
290 constexpr static auto twoPi = std::numbers::pi_v<SampleType> *
static_cast<SampleType
>(2.0);
291 const auto fs{
static_cast<SampleType
>(sampleRate) };
292 const auto A = std::pow(
static_cast<SampleType
>(10.0), dbGain /
static_cast<SampleType
>(40.0));
293 const auto omega{ twoPi * (centreFrequency / fs) };
294 const auto cosOmega = std::cos(omega);
295 const auto sinOmega = std::sin(omega);
296 const auto alpha = (sinOmega /
static_cast<SampleType
>(2.0)) * std::sqrt(((A + (
static_cast<SampleType
>(1.0) / A)) * ((
static_cast<SampleType
>(1.0) / slope) -
static_cast<SampleType
>(1.0))) +
static_cast<SampleType
>(2.0));
297 const auto twoRootAAlpha =
static_cast<SampleType
>(2.0) * std::sqrt(A * alpha);
298 const auto a0 = A * ((A +
static_cast<SampleType
>(1.0)) + (A -
static_cast<SampleType
>(1.0)) * cosOmega + twoRootAAlpha);
299 const auto a1 =
static_cast<SampleType
>(-2.0) * A * ((A -
static_cast<SampleType
>(1.0)) + (A +
static_cast<SampleType
>(1.0)) * cosOmega);
300 const auto a2 = A * ((A +
static_cast<SampleType
>(1.0)) + (A -
static_cast<SampleType
>(1.0)) * cosOmega - twoRootAAlpha);
301 const auto b0 = (A +
static_cast<SampleType
>(1.0)) - (A -
static_cast<SampleType
>(1.0)) * cosOmega + twoRootAAlpha;
302 const auto b1 =
static_cast<SampleType
>(2.0) * ((A -
static_cast<SampleType
>(1.0)) - (A +
static_cast<SampleType
>(1.0)) * cosOmega);
303 const auto b2 = (A +
static_cast<SampleType
>(1.0)) - (A -
static_cast<SampleType
>(1.0)) * cosOmega - twoRootAAlpha;
Implementations of Robert Brinstow Johnson's RBJ Cookbook formulae.
Definition marvin_RBJCoefficients.h:16
BiquadCoefficients< SampleType > allpass(double sampleRate, SampleType cutoff, SampleType q) noexcept
Definition marvin_RBJCoefficients.h:182
BiquadCoefficients< SampleType > lowShelf(double sampleRate, SampleType centreFrequency, SampleType slope, SampleType dbGain) noexcept
Definition marvin_RBJCoefficients.h:249
BiquadCoefficients< SampleType > bandpass(double sampleRate, SampleType centreFrequency, SampleType bandwidth, SampleType peakGain) noexcept
Definition marvin_RBJCoefficients.h:87
BiquadCoefficients< SampleType > highpass(double sampleRate, SampleType cutoff, SampleType q) noexcept
Definition marvin_RBJCoefficients.h:56
BiquadCoefficients< SampleType > lowpass(double sampleRate, SampleType cutoff, SampleType q) noexcept
Definition marvin_RBJCoefficients.h:25
BiquadCoefficients< SampleType > highShelf(double sampleRate, SampleType centreFrequency, SampleType slope, SampleType dbGain) noexcept
Definition marvin_RBJCoefficients.h:289
BiquadCoefficients< SampleType > notch(double sampleRate, SampleType centreFrequency, SampleType bandwidth) noexcept
Definition marvin_RBJCoefficients.h:151
BiquadCoefficients< SampleType > peak(double sampleRate, SampleType centreFrequency, SampleType bandwidth, SampleType dbGain) noexcept
Definition marvin_RBJCoefficients.h:215
A POD type for use with the Biquad class, and the SmoothedBiquadCoefficients class.
Definition marvin_BiquadCoefficients.h:22