From 170561fb9bf78e6a3afea62ed2a61ca688aa6054 Mon Sep 17 00:00:00 2001 From: Matt Demanett Date: Wed, 20 Dec 2017 19:40:13 -0500 Subject: [PATCH] Only set speex conversion rates if they actually change. --- include/dsp/samplerate.hpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/dsp/samplerate.hpp b/include/dsp/samplerate.hpp index 73478582..b7087b34 100644 --- a/include/dsp/samplerate.hpp +++ b/include/dsp/samplerate.hpp @@ -12,20 +12,26 @@ template struct SampleRateConverter { SpeexResamplerState *state = NULL; bool noConversion = true; + int inRate = 44100; + int outRate = 44100; SampleRateConverter() { int error; - state = speex_resampler_init(CHANNELS, 44100, 44100, SPEEX_RESAMPLER_QUALITY_DEFAULT, &error); + state = speex_resampler_init(CHANNELS, inRate, outRate, SPEEX_RESAMPLER_QUALITY_DEFAULT, &error); assert(error == RESAMPLER_ERR_SUCCESS); } ~SampleRateConverter() { speex_resampler_destroy(state); } - void setRates(float inRate, float outRate) { - int error = speex_resampler_set_rate(state, inRate, outRate); - assert(error == RESAMPLER_ERR_SUCCESS); - noConversion = inRate == outRate; + void setRates(int in, int out) { + if (in != inRate || out != outRate) { // speex doesn't optimize setting the rates to the existing values. + int error = speex_resampler_set_rate(state, in, out); + assert(error == RESAMPLER_ERR_SUCCESS); + inRate = in; + outRate = out; + noConversion = in == out; + } } void setRatioSmooth(float ratio) DEPRECATED {