summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-04-10 18:36:47 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-07-04 11:27:14 +0200
commitfe1986214251bcd110837b81ed2159d75c58f8e2 (patch)
treec38a0bdb27b877b900227827b98ca5e39709ff09 /src
parenta638001e3249edf7264b5ee0f6d5280229aeb671 (diff)
Get rid of big stack allocation during resampler (re-)configuration.
Diffstat (limited to 'src')
-rw-r--r--src/drumgizmo.cc11
-rw-r--r--src/drumgizmo.h2
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<ZRWrapper, NUM_CHANNELS> zita;
std::array<std::unique_ptr<sample_t>, NUM_CHANNELS> resampler_input_buffer;
double ratio = 1.0;
-
+ std::vector<sample_t> scratch_buffer;
};