;convert LR interleaved signal to 3 buffers buffer_size/2 in length
(bind-func LR_to_MS_3_channels
(lambda (buffer:float* buffer_size:i64 mid:float* side_l:float* side_r:float*)
(let ((n:i64 0))
(dotimes (n (/ buffer_size 2))
(pset! mid n (+ (pref buffer (* n 2)) (pref buffer (+ (* n 2) 1)))) ;l+r
(pset! side_l n (- (pref buffer (* n 2)) (pref buffer (+ (* n 2) 1)))) ;l-r
(pset! side_r n (- (pref buffer (+ (* n 2) 1)) (pref buffer (* n 2))))) ;r-l
void)))