(bind-func TSM_TIM_sPL
(lambda ()
(let ((in_offset_ptr:i64 0)
(out_offset_ptr:i64 0)
(output_sample:float 0.0)
(in_size:i64 (bitwise-shift-left 2 20)) ;increase the second argument if audio is wrapping around circular buffer to soon
(window_size:i64 8192) ;This is split between the number of input channels. FFT size is window_size/IN_CHANNELS
(out_size:i64 (* window_size 2))
(input_buffer:float* (zalloc in_size))
(output_buffer:float* (zalloc out_size))
(window_buffer:float* (zalloc window_size))
(framing (store_frame_sPL window_size))
(first:i64 1))
(lambda (in:float)
(let ((overlap_factor:i64 4)
(sample_Ss:i64 (/ window_size overlap_factor))
(sample_Sa:i64 (ftoi64 (round (* (i64tof sample_Ss) speed))))) ;speed is a global variable
(pset! input_buffer in_offset_ptr in) ;Set 'in' to whatever you want to be time stretched
(if (= (% in_offset_ptr sample_Ss) 0)
(if (= first 0)
(framing input_buffer in_size output_buffer out_size sample_Sa sample_Ss)))
(if (= in_offset_ptr window_size) ;Start the TSM process after window_size number of samples
(set! first 0))
(set! in_offset_ptr (% (+ in_offset_ptr 1) in_size))
(cond ((= TSM_active 0)
(set! output_sample 0.0))
(else (set! output_sample (pref output_buffer out_offset_ptr))
(set! out_offset_ptr (% (+ out_offset_ptr 1) out_size))
output_sample)))))))