;--------------------------------------------------------------------------------------------------------------------
;Overlap-Add
;This is only included for demonstration purposes, and whacky effects.
;This is the most basic of algorithms for time stretching, and modifies the pitch as well as time.
;Could include applying a window function.
;If the sample_Sa calculation is set to be the same as every other method, the stereo field signal will flip back and forth.
;--------------------------------------------------------------------------------------------------------------------
(bind-func store_frame_OLA
(lambda (window_size:i64)
(let ((read_head:i64 0)
(write_head:i64 0))
(lambda (input_buffer:float* in_size:i64 output_buffer:float* out_size:i64 Sa:i64 Ss:i64)
(let ((n:i64 0)
(window_buffer:float* (salloc window_size)))
(dotimes (n window_size)
(pset! window_buffer n (* 0.5 (pref input_buffer (% (+ n read_head) in_size)))))
(set! read_head (% (+ read_head Sa ) in_size)) ;Advance the playhead by the Analysis hopsize
(dotimes (n window_size) ;Overlap-Add section
(cond ((< n (- window_size Ss))
(pset! output_buffer (% (+ write_head n) out_size) (+ (pref window_buffer n)
(pref output_buffer (% (+ write_head n) out_size)))))
(else
(pset! output_buffer (% (+ write_head n) out_size) (pref window_buffer n)))))
(set! write_head (% (+ write_head Ss ) out_size))
(set! TSM_active 1)
void
)))))