From c2c41b38d030bf8e84293c17b6b9bb19248d9879 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 20 Feb 2020 00:22:09 -0700 Subject: [PATCH] when seeking in disk reader, adjust start of read (if possible) to allow some reverse internal seek allowance --- libs/ardour/disk_reader.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libs/ardour/disk_reader.cc b/libs/ardour/disk_reader.cc index fadd5c865b..95f926497d 100644 --- a/libs/ardour/disk_reader.cc +++ b/libs/ardour/disk_reader.cc @@ -776,6 +776,17 @@ DiskReader::seek (samplepos_t sample, bool complete_refill) (*chan)->rbuf->reset (); } + /* move the intended read target, so that after the refill is done, + the intended read target is "reservation" from the start of the + playback buffer. Then increment the read ptr, so that we can + potentially do an internal seek backwards of up "reservation" + samples. + */ + + const samplecnt_t shift = sample > c->front()->rbuf->reservation_size() ? c->front()->rbuf->reservation_size() : sample; + + sample -= shift; + playback_sample = sample; file_sample[DataType::AUDIO] = sample; file_sample[DataType::MIDI] = sample; @@ -792,6 +803,16 @@ DiskReader::seek (samplepos_t sample, bool complete_refill) ret = do_refill_with_alloc (true); } + sample += shift; + + playback_sample = sample; + file_sample[DataType::AUDIO] = sample; + file_sample[DataType::MIDI] = sample; + + for (n = 0, chan = c->begin(); chan != c->end(); ++chan, ++n) { + (*chan)->rbuf->increment_read_ptr (shift); + } + return ret; }