1declare id   "bassEnhancer";
2declare name "Bass Enhancer";
3declare shortname "BassEnhancer";
4declare category "Misc";
5
6//------------------------------------
7//Based at:
8//"LOW COMPLEXITY VIRTUAL BASS ENHANCEMENT ALGORITHM FOR PORTABLE MULTIMEDIA DEVICE"
9//MANISH ARORA, HAN-GIL MOON, AND SEONGCHEOL JANG
10//Audio lab, DM R&D Center, Samsung Electronics co. Ltd, Suwon, South Korea
11//------------------------------------
12
13import("stdfaust.lib");
14
15//Controls
16lp_freq = hslider("Frequency",100,60,240,5);
17harmonics_volume = hslider("HarmonicsdB[name:Harmonics]",0, -16, +32, 0.1): ba.db2linear : si.smooth(0.999);
18
19//Can be moved to .lib
20X = (_,_)<:(!,_,_,!);
21switch(c,x,y) = sel(c,x,y)
22with {
23	sel(c,x,y) = (1-c)*x + c*y;
24};
25
26//NLD and consts
27harm1 = 0.03;
28harm2 = 0.015;
29get_const(a,b,x,y) = (x <= y)*a + (x > y)*b;
30nld1(a,b) = _<:(_,_,X,_,_:_,X,_,_,_:((get_const(a,b):1-_),_,get_const(a,b),_):(_*_,_*_:(_+_)))~_~_~_;
31
32process = _,_<:hp_branch,(_,_:>lp_branch<:_,_),(_,_:>be_branch<:_,_),hp_branch:>_,_
33with {
34	hp_branch = fi.dcblockerat(20) : fi.highpass(8, lp_freq);
35	lp_branch = fi.dcblockerat(20) : fi.lowpass(8,lp_freq);
36	be_branch = fi.lowpass(8,lp_freq) : nld1(harm1,harm2) : _*harmonics_volume;
37};
38