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