- while (rb:read_space() >= fft_size) do
- -- process one line / buffer
- rb:read (mem, fft_size)
+ local ringsize = 2 * rate
+ local ptr_wrap = math.floor(2^50 / ringsize) * ringsize
+
+ local write_ptr
+ function read_space()
+ write_ptr = self:shmem ():atomic_get_int (SHMEM_WRITEPTR)
+ local space = (write_ptr - read_ptr + ptr_wrap) % ptr_wrap
+ if space > ringsize then
+ -- the GUI lagged too much and unread data was overwritten
+ -- jump to the oldest audio still present in the ringtable
+ read_ptr = write_ptr - ringsize
+ space = ringsize
+ end
+ return space
+ end
+
+ while (read_space() >= fft_size) do
+ -- read one window from the circular table
+ if (read_ptr % ringsize + fft_size < ringsize) then
+ ARDOUR.DSP.copy_vector (mem, self:shmem ():to_float (SHMEM_AUDIO + read_ptr % ringsize), fft_size)
+ else
+ local chunk = ringsize - read_ptr % ringsize
+ ARDOUR.DSP.copy_vector (mem, self:shmem ():to_float (SHMEM_AUDIO + read_ptr % ringsize), chunk)
+ ARDOUR.DSP.copy_vector (cmem:to_float(chunk), self:shmem ():to_float (SHMEM_AUDIO), fft_size - chunk)
+ end
+ read_ptr = (read_ptr + fft_size) % ptr_wrap
+
+ -- process one line