41 template <
typename NumericType>
58 template <
typename SampleType>
65 using NumericType =
typename SampleTypeHelpers::ElementType<SampleType>::Type;
88 jassert (spec.numChannels == 1);
106 memory.
malloc (1 + jmax (newSize, size, static_cast<size_t> (128)));
108 fifo = snapPointerToAlignment (memory.
getData(),
sizeof (SampleType));
112 for (
size_t i = 0; i < size; ++i)
113 fifo[i] = SampleType {0};
128 template <
typename ProcessContext>
129 void process (
const ProcessContext& context) noexcept
131 static_assert (std::is_same<typename ProcessContext::SampleType, SampleType>::value,
132 "The sample-type of the FIR filter must match the sample-type supplied to this process callback");
135 auto&& inputBlock = context.getInputBlock();
136 auto&& outputBlock = context.getOutputBlock();
140 jassert (inputBlock.getNumChannels() == 1);
141 jassert (outputBlock.getNumChannels() == 1);
143 auto numSamples = inputBlock.getNumSamples();
144 auto* src = inputBlock .getChannelPointer (0);
145 auto* dst = outputBlock.getChannelPointer (0);
147 auto* fir = coefficients->getRawCoefficients();
150 if (context.isBypassed)
152 for (
size_t i = 0; i < numSamples; ++i)
154 fifo[p] = dst[i] = src[i];
155 p = (p == 0 ? size - 1 : p - 1);
160 for (
size_t i = 0; i < numSamples; ++i)
161 dst[i] = processSingleSample (src[i], fifo, fir, size, p);
174 return processSingleSample (sample, fifo, coefficients->getRawCoefficients(), size, pos);
180 SampleType* fifo =
nullptr;
181 size_t pos = 0, size = 0;
186 jassert (coefficients !=
nullptr);
188 if (size != (coefficients->getFilterOrder() + 1))
192 static SampleType JUCE_VECTOR_CALLTYPE processSingleSample (SampleType sample, SampleType* buf,
193 const NumericType* fir,
size_t m,
size_t& p) noexcept
200 for (k = 0; k < m - p; ++k)
201 out += buf[(p + k)] * fir[k];
203 for (
size_t j = 0; j < p; ++j)
204 out += buf[j] * fir[j + k];
206 p = (p == 0 ? m - 1 : p - 1);
212 JUCE_LEAK_DETECTOR (
Filter)
223 template <
typename NumericType>
253 double getMagnitudeForFrequency (
double frequency,
double sampleRate)
const noexcept;
258 void getMagnitudeForFrequencyArray (
double* frequencies,
double* magnitudes,
259 size_t numSamples,
double sampleRate)
const noexcept;
264 double getPhaseForFrequency (
double frequency,
double sampleRate)
const noexcept;
269 void getPhaseForFrequencyArray (
double* frequencies,
double* phases,
270 size_t numSamples,
double sampleRate)
const noexcept;
280 void normalise() noexcept;
Coefficients(const NumericType *samples, size_t numSamples)
Creates a set of coefficients from an array of samples.
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType sample) noexcept
Processes a single sample, without any locking.
void prepare(const ProcessSpec &spec) noexcept
Prepare this filter for processing.
A set of coefficients for use in an FIRFilter object.
size_t getFilterOrder() const noexcept
Returns the filter order associated with the coefficients.
void malloc(SizeType newNumElements, size_t elementSize=sizeof(ElementType))
Allocates a specified amount of memory.
ElementType * getData() const noexcept
Returns a raw pointer to the allocated data.
typename SampleTypeHelpers::ElementType< SampleType >::Type NumericType
The NumericType is the underlying primitive type used by the SampleType (which could be either a prim...
A processing class that can perform FIR filtering on an audio signal, in the time domain...
Filter()
This will create a filter which will produce silence.
Coefficients< NumericType >::Ptr coefficients
The coefficients of the FIR filter.
Coefficients(size_t size)
Creates a null set of coefficients of a given size.
const NumericType * getRawCoefficients() const noexcept
Returns a raw data pointer to the coefficients.
NumericType * getRawCoefficients() noexcept
Returns a raw data pointer to the coefficients.
Coefficients()
Creates a null set of coefficients (which will produce silence).
void reset()
Resets the filter's processing pipeline, ready to start a new stream of data.
void process(const ProcessContext &context) noexcept
Processes a block of samples.
Array< NumericType > coefficients
The raw coefficients.
This is a handy base class for the state of a processor (such as parameter values) which is typically...
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
A smart-pointer class which points to a reference-counted object.
Filter(CoefficientsPtr coefficientsToUse)
Creates a filter with a given set of coefficients.
typename Coefficients< NumericType >::Ptr CoefficientsPtr
A typedef for a ref-counted pointer to the coefficients object.