1 /* B.Oops
2  * Glitch effect sequencer LV2 plugin
3  *
4  * Copyright (C) 2020 by Sven Jähnichen
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef FXEQ_HPP_
22 #define FXEQ_HPP_
23 
24 #include "Fx.hpp"
25 #include "BiquadPeakFilter.hpp"
26 
27 class FxEQ : public Fx
28 {
29 public:
30 	FxEQ () = delete;
31 
FxEQ(RingBuffer<Stereo> ** buffer,float * params,Pad * pads,const double rate)32 	FxEQ (RingBuffer<Stereo>** buffer, float* params, Pad* pads, const double rate) :
33 		Fx (buffer, params, pads),
34 		rate (rate),
35 		gains {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}
36 
37 	{
38 		for (int i = 0; i < 6; ++i) filters[i] = BiquadPeakFilter (rate);
39 		filters[0].set (30.0f, M_SQRT1_2, 0.0f);	// Sub
40 		filters[1].set (80.0f, 1.0, 0.0f);	// Boom
41 		filters[2].set (300.0f, M_SQRT1_2, 0.0f);			// Warmth
42 		filters[3].set (1500.0f, 1.0, 0.0f);	// Clarity
43 		filters[4].set (4000.0f, 1.0, 0.0f);	// Presence
44 		filters[5].set (15000.0f, 1.0, 0.0f);	// Air
45 	}
46 
init(const double position)47 	virtual void init (const double position) override
48 	{
49 		Fx::init (position);
50 		for (int i = 0; i < 6; ++i)
51 		{
52 			const double r = bidist (rnd);
53 			gains[i] = 72.0f * LIMIT (params[SLOTS_OPTPARAMS + 2 * i] + r * params[SLOTS_OPTPARAMS + 2 * i + 1], 0.0f, 1.0f) - 36.0f;
54 			filters[i].setPeakGain (gains[i]);
55 		}
56 	}
57 
process(const double position,const double size)58 	virtual Stereo process (const double position, const double size) override
59 	{
60 		Stereo s = (**buffer).front();
61 		for (int i = 0; i < 6; ++i) s = filters[i].process (s);
62 		return s;
63 	}
64 
65 protected:
66 	double rate;
67 	float gains[6];
68 	BiquadPeakFilter filters[6];
69 };
70 
71 #endif /* FXEQ_HPP_ */
72