;; where size is a roomsize from 0.0-1.0
;; predelay is in ms - 40ms is a good start but can go as high as 2 seconds
;; absorb is the amount of highfrq damping 0.0-1.0
;; mix is 0.0 dry to 1.0 wet
;; works as stereo or mono (mono input only)
(bind-func static reverb_c
(lambda ()
(let ((MILLIS (* .001 SRs))
(dly1 (comb_c (* SR 4))) (dly1_delay (* 40.0 MILLIS)) (dly1_fb 0.0)
(lpf1 (lpf_1p_c)) (lpf1_g 0.45)
(apf1 (comb_apf_c (/ SR 4))) (apf1_delay (* 13.28 MILLIS)) (apf1_gain 0.7)
(apf2 (comb_apf_c (/ SR 4))) (apf2_delay (* 28.13 MILLIS)) (apf2_gain -0.7)
(comb1 (comb_c (/ SR 4))) (comb1_delay (* 31.71 MILLIS)) (comb1_fb 0.0)
(comb2 (comb_c (/ SR 4))) (comb2_delay (* 37.11 MILLIS)) (comb2_fb 0.0)
(comb3 (comb_c (/ SR 4))) (comb3_delay (* 40.23 MILLIS)) (comb3_fb 0.0)
(comb4 (comb_c (/ SR 4))) (comb4_delay (* 44.14 MILLIS)) (comb4_fb 0.0)
(comb5 (comb_c (/ SR 4))) (comb5_delay (* 30.47 MILLIS)) (comb5_fb 0.0)
(comb6 (comb_c (/ SR 4))) (comb6_delay (* 33.98 MILLIS)) (comb6_fb 0.0)
(comb7 (comb_c (/ SR 4))) (comb7_delay (* 41.41 MILLIS)) (comb7_fb 0.0)
(comb8 (comb_c (/ SR 4))) (comb8_delay (* 42.58 MILLIS)) (comb8_fb 0.0)
(lpf2 (lpf_1p_c)) (lpf2_g 0.5)
(lpf3 (lpf_1p_c)) (lpf3_g 0.5)
(apf3 (comb_apf_c (* SR 1))) (apf3_delay (* 9.38 MILLIS)) (apf3_gain -0.6)
(apf4 (comb_apf_c (* SR 1))) (apf4_delay (* 11.0 MILLIS)) (apf4_gain 0.6)
(oldsize:SAMPLE 0.0)
(lout:SAMPLE 0.0)
(rout:SAMPLE 0.0)
(input 0.0)
(out:SAMPLE 0.0))
(lambda (chan:i64 x size predelay:SAMPLE absorb:SAMPLE mix)
(if (= chan 0)
(begin
(if (<> size oldsize)
(begin (set! oldsize size)
(set! size (* size 5000.0))
(set! comb1_fb (comb_fb_from_rtsixty size comb1_delay))
(set! comb2_fb (comb_fb_from_rtsixty size comb2_delay))
(set! comb3_fb (comb_fb_from_rtsixty size comb3_delay))
(set! comb4_fb (comb_fb_from_rtsixty size comb4_delay))
(set! comb5_fb (comb_fb_from_rtsixty size comb5_delay))
(set! comb6_fb (comb_fb_from_rtsixty size comb6_delay))
(set! comb7_fb (comb_fb_from_rtsixty size comb7_delay))
(set! comb8_fb (comb_fb_from_rtsixty size comb8_delay))))
(set! input x)
;; predelay
(set! dly1_delay (* predelay MILLIS))
(set! out (dly1 input dly1_delay 0.5 0.5 0.0)) ;dly1_fb))
;; input diffusion
(set! out (lpf1 out absorb))
(set! out (apf1 out apf1_delay apf1_gain))
(set! out (apf2 out apf2_delay apf2_gain))))
;; left channel
(if (= chan 0)
(begin
(set! lout (+ (* 0.15 (comb1 out comb1_delay 1.0 1.0 comb1_fb))
(* -0.15 (comb2 out comb2_delay 1.0 1.0 comb2_fb))
(* 0.15 (comb3 out comb3_delay 1.0 1.0 comb3_fb))
(* -0.15 (comb4 out comb4_delay 1.0 1.0 comb4_fb))))
(set! lout (lpf2 lout lpf2_g))
(set! lout (apf3 lout apf3_delay apf3_gain))))
;; right channel
(if (= chan 1)
(begin
(set! rout (+ (* 0.15 (comb5 out comb5_delay 1.0 1.0 comb5_fb))
(* -0.15 (comb6 out comb6_delay 1.0 1.0 comb6_fb))
(* 0.15 (comb7 out comb7_delay 1.0 1.0 comb7_fb))
(* -0.15 (comb8 out comb8_delay 1.0 1.0 comb8_fb))))
(set! rout (lpf3 rout lpf3_g))
(set! rout (apf4 rout apf4_delay apf4_gain))))
(if (= chan 0)
(* (+ 1.0 mix) (+ (* input (- 1.0 mix)) (* lout mix)))
(if (= chan 1)
(* (+ 1.0 mix) (+ (* input (- 1.0 mix)) (* rout mix)))
0.0))))))