From 7c203c5ddcddd451b0656ee6c9cd0206b17782f0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 21 Dec 2008 18:24:59 +0000 Subject: Fix mixdown of several connections with varying sizes (i.e. control and audio) (fix ticket #308). Fix off-by-one error when copying a control buffer to an audio buffer. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1889 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/AudioBuffer.cpp | 13 +++++++------ src/engine/InputPort.cpp | 2 -- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src/engine') diff --git a/src/engine/AudioBuffer.cpp b/src/engine/AudioBuffer.cpp index 2fc1b234..4ee42274 100644 --- a/src/engine/AudioBuffer.cpp +++ b/src/engine/AudioBuffer.cpp @@ -204,13 +204,13 @@ AudioBuffer::copy(const Buffer* src, size_t start_sample, size_t end_sample) const Sample* const src_buf = ((AudioBuffer*)src)->data(); assert(src_buf); - const size_t to_copy = std::min(end_sample, _size); - for (size_t i=start_sample; i <= to_copy; ++i) + const size_t to_copy = std::min(end_sample, _size - 1); + for (size_t i = start_sample; i <= to_copy; ++i) buf[i] = src_buf[i]; } -/** Accumulate a block of @a src into @a dst. +/** Accumulate a block of @a src into buffer. * * @a start_sample and @a end_sample define the inclusive range to be accumulated. * This function only adds the same range in one buffer to another. @@ -219,16 +219,17 @@ void AudioBuffer::accumulate(const AudioBuffer* const src, size_t start_sample, size_t end_sample) { assert(end_sample >= start_sample); - assert(end_sample < _size); assert(src); - + assert(src->type() == DataType::CONTROL || DataType::AUDIO); + Sample* const buf = data(); assert(buf); const Sample* const src_buf = src->data(); assert(src_buf); - for (size_t i=start_sample; i <= end_sample; ++i) + const size_t to_copy = std::min(end_sample, _size - 1); + for (size_t i = start_sample; i <= to_copy; ++i) buf[i] += src_buf[i]; } diff --git a/src/engine/InputPort.cpp b/src/engine/InputPort.cpp index 9282ca22..e2247a45 100644 --- a/src/engine/InputPort.cpp +++ b/src/engine/InputPort.cpp @@ -247,9 +247,7 @@ InputPort::pre_process(ProcessContext& context) // Accumulate the rest if (_connections.size() > 1) { - Connections::iterator c = _connections.begin(); - for (++c; c != _connections.end(); ++c) ((AudioBuffer*)buffer(voice))->accumulate( ((AudioBuffer*)(*c)->buffer(voice)), 0, _buffer_size-1); -- cgit v1.2.1