Commit 99c14e26 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #28679: audio: don't create a new scratch buffer every time we resample

parent f388aade
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "sfl_types.h" #include "sfl_types.h"
SamplerateConverter::SamplerateConverter(int freq, size_t channels /* = 1 */) : floatBufferIn_(), SamplerateConverter::SamplerateConverter(int freq, size_t channels /* = 1 */) : floatBufferIn_(),
floatBufferOut_(), samples_(0), channels_(channels), maxFreq_(freq), src_state_(0) floatBufferOut_(), scratchBuffer_(), samples_(0), channels_(channels), maxFreq_(freq), src_state_(0)
{ {
int err; int err;
src_state_ = src_new(SRC_LINEAR, channels_, &err); src_state_ = src_new(SRC_LINEAR, channels_, &err);
...@@ -41,6 +41,7 @@ SamplerateConverter::SamplerateConverter(int freq, size_t channels /* = 1 */) : ...@@ -41,6 +41,7 @@ SamplerateConverter::SamplerateConverter(int freq, size_t channels /* = 1 */) :
floatBufferIn_.resize(samples_); floatBufferIn_.resize(samples_);
floatBufferOut_.resize(samples_); floatBufferOut_.resize(samples_);
scratchBuffer_.resize(samples_);
} }
SamplerateConverter::~SamplerateConverter() SamplerateConverter::~SamplerateConverter()
...@@ -86,6 +87,7 @@ void SamplerateConverter::resample(const AudioBuffer &dataIn, AudioBuffer &dataO ...@@ -86,6 +87,7 @@ void SamplerateConverter::resample(const AudioBuffer &dataIn, AudioBuffer &dataO
samples_ = std::max(inSamples, outSamples); samples_ = std::max(inSamples, outSamples);
floatBufferIn_.resize(inSamples); floatBufferIn_.resize(inSamples);
floatBufferOut_.resize(outSamples); floatBufferOut_.resize(outSamples);
scratchBuffer_.resize(outSamples);
SRC_DATA src_data; SRC_DATA src_data;
src_data.data_in = floatBufferIn_.data(); src_data.data_in = floatBufferIn_.data();
...@@ -102,7 +104,6 @@ void SamplerateConverter::resample(const AudioBuffer &dataIn, AudioBuffer &dataO ...@@ -102,7 +104,6 @@ void SamplerateConverter::resample(const AudioBuffer &dataIn, AudioBuffer &dataO
/* /*
TODO: one-shot deinterleave and float-to-short conversion TODO: one-shot deinterleave and float-to-short conversion
*/ */
std::vector<SFLAudioSample> scratch_buff(outSamples); src_float_to_short_array(floatBufferOut_.data(), scratchBuffer_.data(), outSamples);
src_float_to_short_array(floatBufferOut_.data(), scratch_buff.data(), outSamples); dataOut.deinterleave(scratchBuffer_.data(), src_data.output_frames, nbChans);
dataOut.deinterleave(scratch_buff.data(), src_data.output_frames, nbChans);
} }
...@@ -78,6 +78,7 @@ class SamplerateConverter { ...@@ -78,6 +78,7 @@ class SamplerateConverter {
/* temporary buffers */ /* temporary buffers */
std::vector<float> floatBufferIn_; std::vector<float> floatBufferIn_;
std::vector<float> floatBufferOut_; std::vector<float> floatBufferOut_;
std::vector<SFLAudioSample> scratchBuffer_;
size_t samples_; // size in samples of temporary buffers size_t samples_; // size in samples of temporary buffers
size_t channels_; // number of channels configured size_t channels_; // number of channels configured
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment