32template <
typename NumericType>
33double FIR::Coefficients<NumericType>::Coefficients::getMagnitudeForFrequency (
double frequency,
double theSampleRate)
const noexcept
35 jassert (theSampleRate > 0.0);
36 jassert (frequency >= 0.0 && frequency <= theSampleRate * 0.5);
38 constexpr Complex<double> j (0, 1);
39 auto order = getFilterOrder();
41 Complex<double> numerator = 0.0, factor = 1.0;
44 const auto* coefs = coefficients.begin();
46 for (
size_t n = 0; n <= order; ++n)
48 numerator +=
static_cast<double> (coefs[n]) * factor;
52 return std::abs (numerator);
56template <
typename NumericType>
57void FIR::Coefficients<NumericType>::Coefficients::getMagnitudeForFrequencyArray (
double* frequencies,
double* magnitudes,
58 size_t numSamples,
double theSampleRate)
const noexcept
60 jassert (theSampleRate > 0.0);
62 constexpr Complex<double> j (0, 1);
63 const auto* coefs = coefficients.begin();
64 auto order = getFilterOrder();
66 for (
size_t i = 0; i < numSamples; ++i)
68 jassert (frequencies[i] >= 0.0 && frequencies[i] <= theSampleRate * 0.5);
70 Complex<double> numerator = 0.0;
71 Complex<double> factor = 1.0;
74 for (
size_t n = 0; n <= order; ++n)
76 numerator +=
static_cast<double> (coefs[n]) * factor;
80 magnitudes[i] = std::abs (numerator);
85template <
typename NumericType>
86double FIR::Coefficients<NumericType>::Coefficients::getPhaseForFrequency (
double frequency,
double theSampleRate)
const noexcept
88 jassert (theSampleRate > 0.0);
89 jassert (frequency >= 0.0 && frequency <= theSampleRate * 0.5);
91 constexpr Complex<double> j (0, 1);
93 Complex<double> numerator = 0.0;
94 Complex<double> factor = 1.0;
97 const auto* coefs = coefficients.begin();
98 auto order = getFilterOrder();
100 for (
size_t n = 0; n <= order; ++n)
102 numerator +=
static_cast<double> (coefs[n]) * factor;
106 return std::arg (numerator);
110template <
typename NumericType>
111void FIR::Coefficients<NumericType>::Coefficients::getPhaseForFrequencyArray (
double* frequencies,
double* phases,
112 size_t numSamples,
double theSampleRate)
const noexcept
114 jassert (theSampleRate > 0.0);
116 constexpr Complex<double> j (0, 1);
117 const auto* coefs = coefficients.begin();
118 auto order = getFilterOrder();
120 for (
size_t i = 0; i < numSamples; ++i)
122 jassert (frequencies[i] >= 0.0 && frequencies[i] <= theSampleRate * 0.5);
124 Complex<double> numerator = 0.0, factor = 1.0;
127 for (
size_t n = 0; n <= order; ++n)
129 numerator +=
static_cast<double> (coefs[n]) * factor;
133 phases[i] = std::arg (numerator);
138template <
typename NumericType>
139void FIR::Coefficients<NumericType>::Coefficients::normalise() noexcept
141 auto magnitude =
static_cast<NumericType
> (0);
143 auto* coefs = coefficients.getRawDataPointer();
144 auto n =
static_cast<size_t> (coefficients.size());
146 for (
size_t i = 0; i < n; ++i)
152 auto magnitudeInv = 1 / (4 * std::sqrt (magnitude));
158template struct FIR::Coefficients<float>;
159template struct FIR::Coefficients<double>;
static void JUCE_CALLTYPE multiply(float *dest, const float *src, int numValues) noexcept
static const FloatType twoPi