2#include <speex/speex_resampler.h>
15template <
int MAX_CHANNELS>
17 SpeexResamplerState*
st = NULL;
19 int quality = SPEEX_RESAMPLER_QUALITY_DEFAULT;
28 speex_resampler_destroy(
st);
59 speex_resampler_destroy(
st);
70 void process(
const float* in,
int inStride,
int* inFrames,
float* out,
int outStride,
int* outFrames) {
77 speex_resampler_set_input_stride(
st, inStride);
78 speex_resampler_set_output_stride(
st, outStride);
80 spx_uint32_t inLen = 0;
81 spx_uint32_t outLen = 0;
85 int err = speex_resampler_process_float(
st, c, &in[c], &inLen, &out[c], &outLen);
93 int frames = std::min(*inFrames, *outFrames);
94 for (
int i = 0; i < frames; i++) {
96 out[outStride * i + c] = in[inStride * i + c];
105 process((
const float*) in, MAX_CHANNELS, inFrames, (
float*) out, MAX_CHANNELS, outFrames);
111template <
int OVERSAMPLE,
int QUALITY,
typename T =
float>
132 inIndex %= OVERSAMPLE * QUALITY;
135 for (
int i = 0; i < OVERSAMPLE * QUALITY; i++) {
137 index = (index + OVERSAMPLE * QUALITY) % (OVERSAMPLE * QUALITY);
146template <
int OVERSAMPLE,
int QUALITY>
170 for (
int i = 0; i < OVERSAMPLE; i++) {
172 for (
int j = 0; j < QUALITY; j++) {
174 index = (index + QUALITY) % QUALITY;
175 int kernelIndex = OVERSAMPLE * j + i;
void boxcarLowpassIR(float *out, int len, float cutoff=0.5f)
Computes the impulse response of a boxcar lowpass filter.
Definition fir.hpp:21
void blackmanHarrisWindow(float *x, int len)
Definition window.hpp:76
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Downsamples by an integer factor.
Definition resampler.hpp:112
T inBuffer[OVERSAMPLE *QUALITY]
Definition resampler.hpp:113
void reset()
Definition resampler.hpp:122
int inIndex
Definition resampler.hpp:115
float kernel[OVERSAMPLE *QUALITY]
Definition resampler.hpp:114
T process(T *in)
in must be length OVERSAMPLE
Definition resampler.hpp:127
Decimator(float cutoff=0.9f)
Definition resampler.hpp:117
Useful for storing arrays of samples in ring buffers and casting them to float* to be used by interle...
Definition common.hpp:92
Resamples by a fixed rational factor.
Definition resampler.hpp:16
~SampleRateConverter()
Definition resampler.hpp:26
void setChannels(int channels)
Sets the number of channels to actually process.
Definition resampler.hpp:33
void setRates(int inRate, int outRate)
Definition resampler.hpp:49
SampleRateConverter()
Definition resampler.hpp:23
SpeexResamplerState * st
Definition resampler.hpp:17
int inRate
Definition resampler.hpp:20
void process(const float *in, int inStride, int *inFrames, float *out, int outStride, int *outFrames)
Definition resampler.hpp:70
int quality
Definition resampler.hpp:19
void setQuality(int quality)
From 0 (worst, fastest) to 10 (best, slowest)
Definition resampler.hpp:42
int outRate
Definition resampler.hpp:21
void process(const Frame< MAX_CHANNELS > *in, int *inFrames, Frame< MAX_CHANNELS > *out, int *outFrames)
Definition resampler.hpp:104
void refreshState()
Definition resampler.hpp:57
int channels
Definition resampler.hpp:18
Upsamples by an integer factor.
Definition resampler.hpp:147
void reset()
Definition resampler.hpp:157
Upsampler(float cutoff=0.9f)
Definition resampler.hpp:152
int inIndex
Definition resampler.hpp:150
void process(float in, float *out)
out must be length OVERSAMPLE
Definition resampler.hpp:162
float inBuffer[QUALITY]
Definition resampler.hpp:148
float kernel[OVERSAMPLE *QUALITY]
Definition resampler.hpp:149