File: nrev.scm

package info (click to toggle)
snd 25.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,016 kB
  • sloc: ansic: 291,818; lisp: 260,387; ruby: 71,134; sh: 3,293; fortran: 2,342; csh: 1,062; cpp: 294; makefile: 294; python: 87; xml: 27; javascript: 1
file content (96 lines) | stat: -rw-r--r-- 3,521 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;; NREV (the most popular Samson box reverb)

(provide 'snd-nrev.scm)

(if (provided? 'snd)
    (require snd-ws.scm)
    (require sndlib-ws.scm))


(definstrument (nrev (reverb-factor 1.09) (lp-coeff 0.7) (volume 1.0))
  ;; reverb-factor controls the length of the decay -- it should not exceed (/ 1.0 .823)
  ;; lp-coeff controls the strength of the low pass filter inserted in the feedback loop
  ;; output-scale can be used to boost the reverb output

  (let ((dly-len (if (= (floor *clm-srate*) 44100)
		     #i(2467 2753 3217 3533 3877 4127 599 197 67 101 97 73 67 53 37)
		     (and (= (floor *clm-srate*) 22050)
			  #i(1237 1381 1607 1777 1949 2063 307 97 31 53 47 37 31 29 17))))
	(chan2 (> (channels *output*) 1))
	(chan4 (= (channels *output*) 4)))
	
    (if (not dly-len)
	(let ((srscale (/ *clm-srate* 25641))
	      (next-prime (lambda (val)
			    (do ((val val (+ val 2)))
				((or (= val 2)
				     (and (odd? val)
					  (do ((i 3 (+ i 2))
					       (lim (sqrt val)))
					      ((or (= 0 (modulo val i))
						   (> i lim))
					       (> i lim)))))
				 val)))))

	  (set! dly-len #i(1433 1601 1867 2053 2251 2399 347 113 37 59 53 43 37 29 19))
	  (do ((i 0 (+ i 1)))
	      ((= i 15))
	    (let ((val (floor (* srscale (dly-len i)))))
	      (if (even? val) (set! val (+ val 1)))
	      (set! (dly-len i) (next-prime val))))))

    (let* ((len (+ (floor *clm-srate*) (framples *reverb*)))
	   (comb1 (make-comb (* .822 reverb-factor) (dly-len 0)))
	   (comb2 (make-comb (* .802 reverb-factor) (dly-len 1)))
	   (comb3 (make-comb (* .773 reverb-factor) (dly-len 2)))
	   (comb4 (make-comb (* .753 reverb-factor) (dly-len 3)))
	   (comb5 (make-comb (* .753 reverb-factor) (dly-len 4)))
	   (comb6 (make-comb (* .733 reverb-factor) (dly-len 5)))
	   (low (make-one-pole lp-coeff (- lp-coeff 1.0)))
	   (allpass1 (make-all-pass -0.700 0.700 (dly-len 6)))
	   (allpass2 (make-all-pass -0.700 0.700 (dly-len 7)))
	   (allpass3 (make-all-pass -0.700 0.700 (dly-len 8)))
	   (allpass4 (make-all-pass -0.700 0.700 (dly-len 9))) ; 10 for quad
	   (allpass5 (make-all-pass -0.700 0.700 (dly-len 11)))
	   (allpass6 (and chan2 (make-all-pass -0.700 0.700 (dly-len 12))))
	   (allpass7 (and chan4 (make-all-pass -0.700 0.700 (dly-len 13))))
	   (allpass8 (and chan4 (make-all-pass -0.700 0.700 (dly-len 14))))
	   
	   (filts (if (not chan2)
		      (vector allpass5)
		      (if (not chan4)
			  (vector allpass5 allpass6)
			  (vector allpass5 allpass6 allpass7 allpass8))))
	   (combs (make-comb-bank (vector comb1 comb2 comb3 comb4 comb5 comb6)))
	   (allpasses (make-all-pass-bank (vector allpass1 allpass2 allpass3))))
      
      (if chan4
	  (do ((i 0 (+ i 1)))
	      ((= i len))
	    (out-bank filts i
		      (all-pass allpass4
				(one-pole low
					  (all-pass-bank allpasses 
							 (comb-bank combs (* volume (ina i *reverb*))))))))
	  (if chan2
	      (let ((gen1 (filts 0))
		    (gen2 (filts 1)))
		(do ((i 0 (+ i 1)))
		    ((= i len))
		  (let ((val (all-pass allpass4
				       (one-pole low
						 (all-pass-bank allpasses 
								(comb-bank combs (* volume (ina i *reverb*))))))))
		    (outa i (all-pass gen1 val))
		    (outb i (all-pass gen2 val)))))
	      
	      (let ((gen (filts 0)))
		(do ((i 0 (+ i 1)))
		    ((= i len))
		  (outa i (all-pass gen
				    (all-pass allpass4
					      (one-pole low
							(all-pass-bank allpasses 
								       (comb-bank combs (* volume (ina i *reverb*)))))))))))))))

;;; (with-sound (:reverb nrev) (outa 0 .1) (outa 0 .5 *reverb*))