Signalsmith Audio's DSP Library  1.6.0
Useful C++ classes/templates for audio effects
Methods
signalsmith::rates::Oversampler2xFIR< Sample > Struct Template Reference

#include <rates.h>

Detailed Description

template<typename Sample>
struct signalsmith::rates::Oversampler2xFIR< Sample >

2x FIR oversampling for block-based processing.

Upsample response for various lengths

The oversampled signal is stored inside this object, with channels accessed via oversampler[c]. For example, you might do:

// Upsample from multi-channel input (inputBuffers[c][i] is a sample)
oversampler.up(inputBuffers, bufferLength)
// Modify the contents at the higher rate
for (int c = 0; c < 2; ++c) {
float *channel = oversampler[c];
for (int i = 0; i < bufferLength*2; ++i) {
channel[i] = std::abs(channel[i]);
}
}
// Downsample into the multi-channel output
oversampler.down(outputBuffers, bufferLength);

The performance depends not just on the length, but also on where you end the passband, allowing a wider/narrower transition band. Frequencies above this limit (relative to the lower sample-rate) may alias when upsampling and downsampling.

Resample error rates for different passband thresholds

Since both upsample and downsample are stateful, channels are meaningful. If your input channel-count doesn't match your output, you can size it to the larger of the two, and use .upChannel() and .downChannel() to only process the channels which exist.

Methods

 Oversampler2xFIR (int channels, int maxBlock, int halfLatency=16, double passFreq=0.43)
 
void resize (int nChannels, int maxBlockLength)
 
void resize (int nChannels, int maxBlockLength, int halfLatency, double passFreq=0.43)
 
void reset ()
 
int latency () const
 Round-trip latency (or equivalently: upsample latency at the higher rate). More...
 
template<class Data >
void up (Data &&data, int lowSamples)
 Upsamples from a multi-channel input into the internal buffer. More...
 
template<class Data >
void upChannel (int c, Data &&data, int lowSamples)
 Upsamples a single-channel input into the internal buffer. More...
 
template<class Data >
void down (Data &&data, int lowSamples)
 Downsamples from the internal buffer to a multi-channel output. More...
 
template<class Data >
void downChannel (int c, Data &&data, int lowSamples)
 Downsamples a single channel from the internal buffer to a single-channel output. More...
 
Sample * operator[] (int c)
 Gets the samples for a single (higher-rate) channel. The valid length depends how many input samples were passed into .up()/.upChannel(). More...
 
const Sample * operator[] (int c) const
 

Method Details

◆ down()

template<typename Sample >
template<class Data >
void signalsmith::rates::Oversampler2xFIR< Sample >::down ( Data &&  data,
int  lowSamples 
)
inline

Downsamples from the internal buffer to a multi-channel output.

◆ downChannel()

template<typename Sample >
template<class Data >
void signalsmith::rates::Oversampler2xFIR< Sample >::downChannel ( int  c,
Data &&  data,
int  lowSamples 
)
inline

Downsamples a single channel from the internal buffer to a single-channel output.

◆ latency()

template<typename Sample >
int signalsmith::rates::Oversampler2xFIR< Sample >::latency ( ) const
inline

Round-trip latency (or equivalently: upsample latency at the higher rate).

This will be twice the value passed into the constructor or .resize().

◆ operator[]()

template<typename Sample >
Sample* signalsmith::rates::Oversampler2xFIR< Sample >::operator[] ( int  c)
inline

Gets the samples for a single (higher-rate) channel. The valid length depends how many input samples were passed into .up()/.upChannel().

◆ up()

template<typename Sample >
template<class Data >
void signalsmith::rates::Oversampler2xFIR< Sample >::up ( Data &&  data,
int  lowSamples 
)
inline

Upsamples from a multi-channel input into the internal buffer.

◆ upChannel()

template<typename Sample >
template<class Data >
void signalsmith::rates::Oversampler2xFIR< Sample >::upChannel ( int  c,
Data &&  data,
int  lowSamples 
)
inline

Upsamples a single-channel input into the internal buffer.