1 /*
2  * Author: Harry van Haaren 2013
3  *         harryhaaren@gmail.com
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  */
20 
21 #ifndef OPENAV_DUCKA
22 #define OPENAV_DUCKA
23 
24 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
25 
26 #define DUCKA_URI    "http://www.openavproductions.com/artyfx#ducka"
27 #define DUCKA_UI_URI "http://www.openavproductions.com/artyfx#ducka/gui"
28 
29 typedef enum {
30 	DUCKA_INPUT_L = 0,
31 	DUCKA_INPUT_R,
32 
33 	DUCKA_SIDECHAIN,
34 
35 	DUCKA_OUTPUT_L,
36 	DUCKA_OUTPUT_R,
37 
38 	DUCKA_THRESHOLD,
39 	DUCKA_REDUCTION,
40 	DUCKA_RELEASE_TIME,
41 
42 	DUCKA_SIDECHAIN_AMP,
43 
44 	DUCKA_ATOM_IN,
45 } PortIndex;
46 
47 #include "lv2/lv2plug.in/ns/ext/atom/atom.h"
48 #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
49 
50 class Ducka
51 {
52 public:
53 	Ducka(int rate);
54 	Ducka(int rate, LV2_URID_Map* map);
~Ducka()55 	~Ducka() {}
56 	static LV2_Handle instantiate(const LV2_Descriptor* descriptor,
57 	                              double samplerate,
58 	                              const char* bundle_path,
59 	                              const LV2_Feature* const* features);
60 	static void activate(LV2_Handle instance);
61 	static void deactivate(LV2_Handle instance);
62 	static void connect_port(LV2_Handle instance, uint32_t port, void *data);
63 	static void run(LV2_Handle instance, uint32_t n_samples);
64 	static void cleanup(LV2_Handle instance);
65 	static const void* extension_data(const char* uri);
66 
67 	/// audio buffers
68 	float* audioInputL;
69 	float* audioInputR;
70 	float* audioSidechain;
71 	float* audioOutputL;
72 	float* audioOutputR;
73 
74 	/// Atom port
75 	LV2_URID time_Position;
76 	LV2_URID time_barBeat;
77 	LV2_URID time_beatsPerMinute;
78 	LV2_URID time_speed;
79 
80 	LV2_URID atom_Blank;
81 	LV2_URID atom_Float;
82 
83 	LV2_URID_Map* map;
84 	LV2_URID_Unmap* unmap;
85 	LV2_Atom_Sequence* atom_port;
86 
setUnmap(LV2_URID_Unmap * um)87 	void setUnmap( LV2_URID_Unmap* um )
88 	{
89 		unmap = um;
90 	}
91 
92 	/// control signals
93 	float* controlThreshold;
94 	float* controlReduction;
95 	float* controlReleaseTime;
96 	float* controlSidechainAmp;
97 
98 	/// filter state
99 	float w, a, b, g1, g2;
100 
101 	/// last peak history
102 	long samplerate;
103 	bool nowIsAPeak;
104 	long peakFrameCounter;
105 
106 	/// nframes available for countdown
107 	long peakCountDuration;
108 
109 	/// control output
110 	float currentTarget;
111 };
112 
113 
114 #endif // OPENAV_DUCKA
115