So, I'm at a point where I have input and output buffers, and I'm using a frame buffer as storage between the input and output buffers. For some reason though, the callback time needs to be half of the length of the frame buffer. I've tried different frame sizes, different input and output buffer sizes, but the callback time still needs to be half of the frame length.
This confuses me. Shouldn't a callback offset smaller than the number of samples being moved cause the frame read-head to move past where samples are being added to the input buffer.
The code is below. In terms of improvement external to this issue, moving the store_frame closure to it's own process needs to be done, along with a couple of other things.
store_frame2 was trying to rule out the processing time of double writing.
(bind-val input_buffer float* 44100)
(bind-val output_buffer float* 44100)
(bind-val frame_buffer float* 1024)
(bind-val in_size i64 44100)
(bind-val out_size i64 44100)
(bind-val frame_size i64 1024)
(bind-func dsp:[float,float,i64,i64,float*]*
(let ((in_offset_ptr:i64 0)
(out_offset_ptr:i64 0)
(output_sample:float 0.0))
(lambda (in time chan dat)
(pset! input_buffer in_offset_ptr in) ;store the current sample
;(pset! output_buffer out_offset_ptr (pref input_buffer in_offset_ptr)) ;copy the current sample (This was the step before frame buffering)
(set! output_sample (pref output_buffer out_offset_ptr)) ;set the output sample
(set! in_offset_ptr (% (+ in_offset_ptr 1) in_size)) ;advance the input pointer offset
(set! out_offset_ptr (% (+ out_offset_ptr 1) out_size)) ;advance the output pointer offset
output_sample)))
;This one doesn't work properly (Although it would if frame_size was frame_size/2)
(bind-func store_frame
(let ((read_head:i64 0)
(write_head:i64 0))
(lambda ()
(let ((n:i64 0))
(dotimes (n frame_size)
(pset! frame_buffer n (pref input_buffer read_head))
(set! read_head (% (+ read_head 1) in_size)))
(dotimes (n frame_size)
(pset! output_buffer write_head (pref frame_buffer n))
(set! write_head (% (+ write_head 1) out_size)))
(callback (+ (now) frame_size) store_frame)
))))
;This one does work properly
(bind-func store_frame2
(let ((read_head:i64 0)
(write_head:i64 0))
(lambda ()
(let ((n:i64 0))
(dotimes (n frame_size)
(pset! output_buffer write_head (pref input_buffer read_head))
(set! read_head (% (+ read_head 1) in_size))
(set! write_head (% (+ write_head 1) out_size)))
(callback (+ (now) 512) store_frame2)
))))