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);
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;
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>
259 size_t numSamples,
double sampleRate)
const noexcept;
270 size_t numSamples,
double sampleRate)
const noexcept;
Holds a resizable array of primitive or copy-by-value objects.
int size() const noexcept
Returns the current number of elements in the array.
ElementType * begin() noexcept
Returns a pointer to the first element in the array.
ElementType * getRawDataPointer() noexcept
Returns a pointer to the actual array data.
void resize(int targetNumItems)
This will enlarge or shrink the array to the given number of elements, by adding or removing items fr...
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.
A smart-pointer class which points to a reference-counted object.
A processing class that can perform FIR filtering on an audio signal, in the time domain.
Coefficients< NumericType >::Ptr coefficients
The coefficients of the FIR filter.
typename Coefficients< NumericType >::Ptr CoefficientsPtr
A typedef for a ref-counted pointer to the coefficients object.
void process(const ProcessContext &context) noexcept
Processes a block of samples.
typename SampleTypeHelpers::ElementType< SampleType >::Type NumericType
The NumericType is the underlying primitive type used by the SampleType (which could be either a prim...
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType sample) noexcept
Processes a single sample, without any locking.
Filter(CoefficientsPtr coefficientsToUse)
Creates a filter with a given set of coefficients.
void prepare(const ProcessSpec &spec) noexcept
Prepare this filter for processing.
Filter()
This will create a filter which will produce silence.
void reset()
Resets the filter's processing pipeline, ready to start a new stream of data.
A set of coefficients for use in an FIRFilter object.
void normalise() noexcept
Scales the values of the FIR filter with the sum of the squared coefficients.
void getMagnitudeForFrequencyArray(double *frequencies, double *magnitudes, size_t numSamples, double sampleRate) const noexcept
Returns the magnitude frequency response of the filter for a given frequency array and sample rate.
NumericType * getRawCoefficients() noexcept
Returns a raw data pointer to the coefficients.
size_t getFilterOrder() const noexcept
Returns the filter order associated with the coefficients.
Coefficients()
Creates a null set of coefficients (which will produce silence).
Coefficients(const NumericType *samples, size_t numSamples)
Creates a set of coefficients from an array of samples.
Coefficients(size_t size)
Creates a null set of coefficients of a given size.
double getMagnitudeForFrequency(double frequency, double sampleRate) const noexcept
Returns the magnitude frequency response of the filter for a given frequency and sample rate.
Array< NumericType > coefficients
The raw coefficients.
double getPhaseForFrequency(double frequency, double sampleRate) const noexcept
Returns the phase frequency response of the filter for a given frequency and sample rate.
const NumericType * getRawCoefficients() const noexcept
Returns a raw data pointer to the coefficients.
void getPhaseForFrequencyArray(double *frequencies, double *phases, size_t numSamples, double sampleRate) const noexcept
Returns the phase frequency response of the filter for a given frequency array and sample rate.
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
This is a handy base class for the state of a processor (such as parameter values) which is typically...