-
Notifications
You must be signed in to change notification settings - Fork 4
/
Enhancer.ny
86 lines (74 loc) · 3.03 KB
/
Enhancer.ny
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
;nyquist plug-in
;version 3
;type process
;categories "http://lv2plug.in/ns/lv2core/#DistortionPlugin"
;name "Harmonic Enhancer..."
;action "Adding Harmonics..."
;info " By Jvo Studer <[email protected]>. GPL v2.\n\n Adds high frequency harmonics to brighten up dull recordings."
;; enhancer.ny by Jvo Studer, March 2011
;; Version 1.0
;; Released under terms of the GNU General Public License version 2
;; http://www.gnu.org/licenses/gpl-2.0.html
;control freq "Enhancer Crossover Frequency" int "Hz" 3200 2000 4500
;control drive "Enhancer Drive" int "dB" 0 -10 10
;control mode "Harmonic Generator Mode" choice "Even order,Odd order" 0
;control th_ng "Enhancer Noise Gate Threshold" int "dB" -28 -40 -16
;control effmix "Enhancer Mix Level" int "dB" -10 -26 6
;control output "Output" choice "Mix (Normal),Effect Only,Effect Level" 0
(setq freq (max (min freq (/ *sound-srate* 4)) 20));; limit freq selection
(setf limit 0.20);; this is the max positive limiting value
(setf lim1 (* -1 limit))
(setf ratio1 (/ lim1))
(if (= mode 0)
(setf lim2 (* lim1 -11))
(setf lim2 (* lim1 -1.1)))
(setf ratio2 (/ lim2))
(setf fcomp (* freq 0.93)); crossover compensation eq
(setf gcomp (max 0 (/ (+ drive effmix 16) 5.2)))
(setf wcomp 0.81)
(setf fc_ng (* freq 0.125)); noise gate parameters
(setf trise 0.005)
(setf tfall 0.425)
(setf lookah (+ trise tfall)); must be (tf+tr) or higher for correct operation
(setf floor (db-to-linear -26))
; modified 1-pole highpass (due to gain loss at mid to high frequencies)
(defun hp1 (x fc)
(if (< fc 493) (hp x fc)
(if (< fc 2375)
(scale-db (- (log fc) 6.2) (hp x fc))
(scale-db (- (* (log fc) 2) 13.97) (hp x fc)))))
; sidechain filter function, 3rd order butterworth
(defun sidechain (sig gain fc)
(highpass2
(hp1
(scale-db gain
(eq-highshelf sig (/ *sound-srate* 3.1) -4 1.0))
(* fc 1.07))
(* fc 1.0) 1.06))
; the actual soft clipping limiter (similar to a diode limiter)
(defun enhance (sig)
(let* ((top (mult ratio1 (s-max sig 0))); scaled positive peaks
(bottom (sum (mult ratio2 (s-min sig 0))))); scaled neg peaks
(sim
(scale lim1 (sum (s-exp top) -1))
(scale lim2 (sum (s-exp bottom) -1)))))
; enhancer noise gate, for stereo in apply in mono to preserve stereo image
(defun noisegate (sig thres fsig_hp)
(if (arrayp s)
(gate (hp (scale-db drive (sum (aref sig 0) (aref sig 1))) fsig_hp)
lookah trise tfall floor (* (db-to-linear thres) 2))
(gate (hp (scale-db drive s) fsig_hp)
lookah trise tfall floor (db-to-linear thres))))
(case output
(0 (eq-band
(sim s
(scale-db (+ effmix 0.13)
(hp1 (mult (multichan-expand #'enhance (sidechain s drive freq))
(noisegate s th_ng fc_ng))
(/ freq 10))))
fcomp gcomp wcomp))
(1 (mult (multichan-expand #'enhance (sidechain s drive freq))
(noisegate s th_ng fc_ng)))
(2 (scale (/ 0.501 limit) ; 8dB gain at lim=0.2
(mult (sidechain s drive freq)
(noisegate s th_ng fc_ng)))))