From 3c96ba1de615d4ef071692ea69ea8b3722913374 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 7 Feb 2019 01:30:43 +0100 Subject: [PATCH] Allow reading future data without read-commit This is in preparation for de-click, fade-out. A disk-reader can keep going, reading buffered data (if any) without changing the read-index. --- libs/pbd/pbd/playback_buffer.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/pbd/pbd/playback_buffer.h b/libs/pbd/pbd/playback_buffer.h index 3ec7d57897..d20cea83e6 100644 --- a/libs/pbd/pbd/playback_buffer.h +++ b/libs/pbd/pbd/playback_buffer.h @@ -111,7 +111,7 @@ public: } /* read-thead */ - guint read (T *dest, guint cnt, bool commit = true); + guint read (T *dest, guint cnt, bool commit = true, guint offset = 0); /* write-thead */ guint write (T const * src, guint cnt); @@ -254,7 +254,7 @@ PlaybackBuffer::write_zero (guint cnt) } template /*LIBPBD_API*/ guint -PlaybackBuffer::read (T *dest, guint cnt, bool commit) +PlaybackBuffer::read (T *dest, guint cnt, bool commit, guint offset) { Glib::Threads::Mutex::Lock lm (_reset_lock, Glib::Threads::TRY_LOCK); if (!lm.locked ()) { @@ -265,7 +265,16 @@ PlaybackBuffer::read (T *dest, guint cnt, bool commit) guint r = g_atomic_int_get (&read_idx); const guint w = g_atomic_int_get (&write_idx); - const guint free_cnt = (w > r) ? (w - r) : ((w - r + size) & size_mask); + guint free_cnt = (w > r) ? (w - r) : ((w - r + size) & size_mask); + + if (!commit && offset > 0) { + if (offset > free_cnt) { + return 0; + } + free_cnt -= offset; + r = (r + offset) & size_mask; + } + const guint to_read = cnt > free_cnt ? free_cnt : cnt; const guint cnt2 = r + to_read;