From 98d56d6b21e9616b873a90d27dfbe9e7e52fa1de Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 12 May 2020 10:12:58 -0600 Subject: Add API to PlaybackBuffer to compute amount of data that can overwritten The distance is between a given offset in the buffer (probably a read position at some point in time) and the write ptr. Any data after the write ptr is "old" and not readable, and thus not worth overwriting since we would not read it anyway. --- libs/pbd/pbd/playback_buffer.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libs/pbd') diff --git a/libs/pbd/pbd/playback_buffer.h b/libs/pbd/pbd/playback_buffer.h index 75a30bc86f..2926e90be2 100644 --- a/libs/pbd/pbd/playback_buffer.h +++ b/libs/pbd/pbd/playback_buffer.h @@ -122,6 +122,18 @@ public: } } + /* write thread */ + guint overwritable_at (guint r) const { + guint w; + + w = g_atomic_int_get (&write_idx); + + if (w > r) { + return w - r; + } + return (w - r + size) & size_mask; + } + /* read-thead */ guint read (T *dest, guint cnt, bool commit = true, guint offset = 0); -- cgit v1.2.3