From c1fd6fe6a5ac76063f0b0725e2996382bfd3018a Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Wed, 12 May 2021 17:26:27 +0100 Subject: [PATCH] Fix overrun --- src/dsp/BQResampler.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dsp/BQResampler.cpp b/src/dsp/BQResampler.cpp index 2a628f8..2ec624e 100644 --- a/src/dsp/BQResampler.cpp +++ b/src/dsp/BQResampler.cpp @@ -581,15 +581,17 @@ BQResampler::reconstruct_one(state *s) const int phase_length = pr.length; double result = 0.0; + int dot_length = min(phase_length, int(s->buffer.size()) - s->left); + if (m_dynamism == RatioMostlyFixed) { int phase_start = pr.start_index; if (m_channels == 1) { result = v_multiply_and_sum (s->phase_sorted_filter.data() + phase_start, s->buffer.data() + s->left, - phase_length); + dot_length); } else { - for (int i = 0; i < phase_length; ++i) { + for (int i = 0; i < dot_length; ++i) { result += s->phase_sorted_filter[phase_start + i] * s->buffer[s->left + i * m_channels + s->current_channel]; @@ -597,7 +599,7 @@ BQResampler::reconstruct_one(state *s) const } } else { double m = double(m_proto_length - 1) / double(s->filter_length - 1); - for (int i = 0; i < phase_length; ++i) { + for (int i = 0; i < dot_length; ++i) { double sample = s->buffer[s->left + i * m_channels + s->current_channel]; int filter_index = i * s->parameters.numerator + s->current_phase;