From 5b7c20453ff0129eb283bdeeeb67bc73064185c1 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 12 May 2020 11:32:56 -0600 Subject: DiskReader::overwrite_existing_audio() now only overwrites data that would be read There's no need to fill the whole buffer, because we do not consider the whole buffer readable. This uses the recently-added PlaybackBuffer::overwritable_at() API to compute the correct amount of data to overwrite --- libs/ardour/disk_reader.cc | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/disk_reader.cc b/libs/ardour/disk_reader.cc index c4a8717065..961fd27c0a 100644 --- a/libs/ardour/disk_reader.cc +++ b/libs/ardour/disk_reader.cc @@ -687,38 +687,42 @@ DiskReader::overwrite_existing_audio () samplecnt_t chunk1_cnt; samplecnt_t chunk2_cnt; - const samplecnt_t bufsize = c->front ()->rbuf->bufsize (); + const samplecnt_t to_overwrite = c->front()->rbuf->overwritable_at (overwrite_offset); chunk1_offset = overwrite_offset; - chunk1_cnt = bufsize - overwrite_offset; + chunk1_cnt = min (c->front()->rbuf->bufsize() - overwrite_offset, to_overwrite); - if (chunk1_cnt == bufsize) { + if (chunk1_cnt == to_overwrite) { chunk1_cnt--; chunk2_cnt = 0; } else { - chunk2_cnt = bufsize - 1 - chunk1_cnt; + chunk2_cnt = to_overwrite - chunk1_cnt; } - /* this is a complete buffer fill */ - assert (chunk1_cnt + chunk2_cnt == bufsize - 1); - - boost::scoped_array mixdown_buffer (new Sample[bufsize]); - boost::scoped_array gain_buffer (new float[bufsize]); + boost::scoped_array mixdown_buffer (new Sample[to_overwrite]); + boost::scoped_array gain_buffer (new float[to_overwrite]); uint32_t n = 0; bool ret = true; + samplepos_t start; for (ChannelList::iterator chan = c->begin (); chan != c->end (); ++chan, ++n) { - samplepos_t start = overwrite_sample; Sample* buf = (*chan)->rbuf->buffer (); ReaderChannelInfo* rci = dynamic_cast (*chan); + /* Note that @param start is passed by reference and will be + * updated by the ::audio_read() call + */ + + start = overwrite_sample; + if (chunk1_cnt) { if (audio_read (buf + chunk1_offset, mixdown_buffer.get (), gain_buffer.get (), start, chunk1_cnt, rci, n, reversed) != chunk1_cnt) { error << string_compose (_("DiskReader %1: when overwriting(1), cannot read %2 from playlist at sample %3"), id (), chunk1_cnt, overwrite_sample) << endmsg; ret = false; continue; } + } if (chunk2_cnt) { -- cgit v1.2.3