31 template <
typename NumericType>
48 template <
typename SampleType>
55 using NumericType =
typename SampleTypeHelpers::ElementType<SampleType>::Type;
78 jassert (spec.numChannels == 1);
95 memory.malloc (1 + jmax (newSize, size,
static_cast<size_t> (128)));
97 fifo = snapPointerToAlignment (memory.getData(), sizeof (SampleType));
101 for (
size_t i = 0; i < size; ++i)
102 fifo[i] = SampleType {0};
117 template <
typename ProcessContext>
118 void process (
const ProcessContext& context)
noexcept
120 static_assert (std::is_same_v<typename ProcessContext::SampleType, SampleType>,
121 "The sample-type of the FIR filter must match the sample-type supplied to this process callback");
124 auto&& inputBlock = context.getInputBlock();
125 auto&& outputBlock = context.getOutputBlock();
129 jassert (inputBlock.getNumChannels() == 1);
130 jassert (outputBlock.getNumChannels() == 1);
132 auto numSamples = inputBlock.getNumSamples();
133 auto* src = inputBlock .getChannelPointer (0);
134 auto* dst = outputBlock.getChannelPointer (0);
139 if (context.isBypassed)
141 for (
size_t i = 0; i < numSamples; ++i)
143 fifo[p] = dst[i] = src[i];
144 p = (p == 0 ? size - 1 : p - 1);
149 for (
size_t i = 0; i < numSamples; ++i)
150 dst[i] = processSingleSample (src[i], fifo, fir, size, p);
163 return processSingleSample (sample, fifo,
coefficients->getRawCoefficients(), size, pos);
169 SampleType* fifo =
nullptr;
170 size_t pos = 0, size = 0;
181 static SampleType JUCE_VECTOR_CALLTYPE processSingleSample (SampleType sample, SampleType* buf,
182 const NumericType* fir,
size_t m,
size_t& p)
noexcept
189 for (k = 0; k < m - p; ++k)
190 out += buf[(p + k)] * fir[k];
192 for (
size_t j = 0; j < p; ++j)
193 out += buf[j] * fir[j + k];
195 p = (p == 0 ? m - 1 : p - 1);
201 JUCE_LEAK_DETECTOR (
Filter)
212 template <
typename NumericType>
248 size_t numSamples,
double sampleRate)
const noexcept;
259 size_t numSamples,
double sampleRate)
const noexcept;
Coefficients< NumericType >::Ptr coefficients
typename Coefficients< NumericType >::Ptr CoefficientsPtr
void process(const ProcessContext &context) noexcept
typename SampleTypeHelpers::ElementType< SampleType >::Type NumericType
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType sample) noexcept
Filter(CoefficientsPtr coefficientsToUse)
void prepare(const ProcessSpec &spec) noexcept
void normalise() noexcept
void getMagnitudeForFrequencyArray(double *frequencies, double *magnitudes, size_t numSamples, double sampleRate) const noexcept
size_t getFilterOrder() const noexcept
Coefficients(const NumericType *samples, size_t numSamples)
Coefficients(size_t size)
double getMagnitudeForFrequency(double frequency, double sampleRate) const noexcept
ReferenceCountedObjectPtr< Coefficients > Ptr
Array< NumericType > coefficients
double getPhaseForFrequency(double frequency, double sampleRate) const noexcept
NumericType * getRawCoefficients() noexcept
const NumericType * getRawCoefficients() const noexcept
void getPhaseForFrequencyArray(double *frequencies, double *phases, size_t numSamples, double sampleRate) const noexcept