31 template <
typename NumericType>
48 template <
typename SampleType>
55 using NumericType =
typename SampleTypeHelpers::ElementType<SampleType>::Type;
101 for (
size_t i = 0; i < size; ++i)
102 fifo[i] = SampleType {0};
117 template <
typename ProcessContext>
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,
189 for (k = 0; k < m - p; ++k)
190 out +=
buf[(p + k)] *
fir[k];
192 for (
size_t j = 0;
j < p; ++
j)
195 p = (p == 0 ? m - 1 : p - 1);
212 template <
typename NumericType>
248 size_t numSamples,
double sampleRate)
const noexcept;
259 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...
Very simple container class to hold a pointer to some data on the heap.
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.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
Classes for FIR filter processing.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Type * snapPointerToAlignment(Type *basePointer, IntegerType alignmentBytes) noexcept
A handy function to round up a pointer to the nearest multiple of a given number of bytes.
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.
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.
NumericType * getRawCoefficients() noexcept
Returns a raw data pointer to the coefficients.
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...