31template <
typename NumericType>
32double FIR::Coefficients<NumericType>::Coefficients::getMagnitudeForFrequency (
double frequency,
double theSampleRate)
const noexcept
35 jassert (frequency >= 0.0 && frequency <= theSampleRate * 0.5);
37 constexpr Complex<double>
j (0, 1);
38 auto order = getFilterOrder();
40 Complex<double> numerator = 0.0, factor = 1.0;
41 Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequency *
j / theSampleRate);
43 const auto* coefs = coefficients.begin();
45 for (
size_t n = 0;
n <= order; ++
n)
47 numerator +=
static_cast<double> (coefs[
n]) * factor;
51 return std::abs (numerator);
55template <
typename NumericType>
56void FIR::Coefficients<NumericType>::Coefficients::getMagnitudeForFrequencyArray (
double* frequencies,
double* magnitudes,
57 size_t numSamples,
double theSampleRate)
const noexcept
61 constexpr Complex<double>
j (0, 1);
62 const auto* coefs = coefficients.begin();
63 auto order = getFilterOrder();
65 for (
size_t i = 0;
i < numSamples; ++
i)
67 jassert (frequencies[
i] >= 0.0 && frequencies[
i] <= theSampleRate * 0.5);
69 Complex<double> numerator = 0.0;
70 Complex<double> factor = 1.0;
71 Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequencies[
i] *
j / theSampleRate);
73 for (
size_t n = 0;
n <= order; ++
n)
75 numerator +=
static_cast<double> (coefs[
n]) * factor;
79 magnitudes[
i] = std::abs (numerator);
84template <
typename NumericType>
85double FIR::Coefficients<NumericType>::Coefficients::getPhaseForFrequency (
double frequency,
double theSampleRate)
const noexcept
88 jassert (frequency >= 0.0 && frequency <= theSampleRate * 0.5);
90 constexpr Complex<double>
j (0, 1);
92 Complex<double> numerator = 0.0;
93 Complex<double> factor = 1.0;
94 Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequency *
j / theSampleRate);
96 const auto* coefs = coefficients.begin();
97 auto order = getFilterOrder();
99 for (
size_t n = 0;
n <= order; ++
n)
101 numerator +=
static_cast<double> (coefs[
n]) * factor;
105 return std::arg (numerator);
109template <
typename NumericType>
110void FIR::Coefficients<NumericType>::Coefficients::getPhaseForFrequencyArray (
double* frequencies,
double* phases,
111 size_t numSamples,
double theSampleRate)
const noexcept
115 constexpr Complex<double>
j (0, 1);
116 const auto* coefs = coefficients.begin();
117 auto order = getFilterOrder();
119 for (
size_t i = 0;
i < numSamples; ++
i)
121 jassert (frequencies[
i] >= 0.0 && frequencies[
i] <= theSampleRate * 0.5);
123 Complex<double> numerator = 0.0, factor = 1.0;
124 Complex<double> jw = std::exp (-MathConstants<double>::twoPi * frequencies[
i] *
j / theSampleRate);
126 for (
size_t n = 0;
n <= order; ++
n)
128 numerator +=
static_cast<double> (coefs[
n]) * factor;
132 phases[
i] = std::arg (numerator);
137template <
typename NumericType>
138void FIR::Coefficients<NumericType>::Coefficients::normalise()
noexcept
140 auto magnitude =
static_cast<NumericType
> (0);
142 auto* coefs = coefficients.getRawDataPointer();
143 auto n =
static_cast<size_t> (coefficients.size());
145 for (
size_t i = 0;
i <
n; ++
i)
151 auto magnitudeInv = 1 / (4 * std::sqrt (magnitude));
153 FloatVectorOperations::multiply (coefs, magnitudeInv,
static_cast<int> (
n));
157template struct FIR::Coefficients<float>;
158template struct FIR::Coefficients<double>;
#define noexcept
Definition DistrhoDefines.h:72
register unsigned j
Definition inflate.c:1576
register unsigned i
Definition inflate.c:1575
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
int n
Definition crypt.c:458
return c
Definition crypt.c:175