From fe1986214251bcd110837b81ed2159d75c58f8e2 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 10 Apr 2021 18:36:47 +0200 Subject: Get rid of big stack allocation during resampler (re-)configuration. --- src/drumgizmo.cc | 11 +++++++---- src/drumgizmo.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index ca91c12..345e89d 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -463,10 +463,13 @@ void DrumGizmo::setSamplerate(float samplerate, float resampling_quality) zita[c].set_inp_data(nullptr); zita[c].set_inp_count(null_size); - constexpr auto sz = 4096 * 16; - sample_t s[sz]; - zita[c].set_out_data(s); - zita[c].set_out_count(sz); + auto scratch_buffer_size = (null_size / ratio) + 1; + if(scratch_buffer.size() < scratch_buffer_size) + { + scratch_buffer.resize(scratch_buffer_size); + } + zita[c].set_out_data(scratch_buffer.data()); + zita[c].set_out_count(scratch_buffer_size); zita[c].process(); } diff --git a/src/drumgizmo.h b/src/drumgizmo.h index f08c9f7..89c2960 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -107,5 +107,5 @@ protected: std::array zita; std::array, NUM_CHANNELS> resampler_input_buffer; double ratio = 1.0; - + std::vector scratch_buffer; }; -- cgit v1.2.3