diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2020-05-12 11:32:56 -0600 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2020-05-12 11:34:38 -0600 |
commit | 5b7c20453ff0129eb283bdeeeb67bc73064185c1 (patch) | |
tree | 7cbbd4246d57f6d4fb11102de739ec2725e12ce4 | |
parent | af46adc110cdccec7a8d981e9ab47e9f4ff4085b (diff) |
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
-rw-r--r-- | libs/ardour/disk_reader.cc | 24 |
1 files changed, 14 insertions, 10 deletions
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<Sample> mixdown_buffer (new Sample[bufsize]); - boost::scoped_array<float> gain_buffer (new float[bufsize]); + boost::scoped_array<Sample> mixdown_buffer (new Sample[to_overwrite]); + boost::scoped_array<float> 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<ReaderChannelInfo*> (*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) { |