1 /*
2 * Author: Harry van Haaren 2014
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 #include "shared.hxx"
22
23 #include "dsp_sample_hold.hxx"
24
instantiate(const LV2_Descriptor * descriptor,double samplerate,const char * bundle_path,const LV2_Feature * const * features)25 LV2_Handle Friza::instantiate(const LV2_Descriptor* descriptor,
26 double samplerate,
27 const char* bundle_path,
28 const LV2_Feature* const* features)
29 {
30 return (LV2_Handle) new Friza( samplerate );
31 }
32
Friza(int rate)33 Friza::Friza(int rate)
34 {
35 shs = new SampleHoldShift( rate );
36
37 audioInput = 0;
38 audioOutput = 0;
39
40 length = 0;
41 doIt = 0;
42 }
43
~Friza()44 Friza::~Friza()
45 {
46 delete shs;
47 }
48
activate(LV2_Handle instance)49 void Friza::activate(LV2_Handle instance)
50 {
51 Friza* self = (Friza*) instance;
52 }
53
deactivate(LV2_Handle instance)54 void Friza::deactivate(LV2_Handle instance)
55 {
56 }
57
connect_port(LV2_Handle instance,uint32_t port,void * data)58 void Friza::connect_port(LV2_Handle instance, uint32_t port, void *data)
59 {
60 Friza* self = (Friza*) instance;
61
62 switch (port) {
63 case FRIZA_INPUT:
64 self->audioInput = (float*)data;
65 break;
66 case FRIZA_OUTPUT:
67 self->audioOutput = (float*)data;
68 break;
69
70 case FRIZA_DO_IT:
71 self->doIt = (float*)data;
72 break;
73 case FRIZA_LENGTH:
74 self->length = (float*)data;
75 break;
76 case FRIZA_POSITION:
77 self->position = (float*)data;
78 break;
79 case FRIZA_VOLUME:
80 self->volume = (float*)data;
81 break;
82 }
83 }
84
run(LV2_Handle instance,uint32_t nframes)85 void Friza::run(LV2_Handle instance, uint32_t nframes)
86 {
87 Friza* self = (Friza*) instance;
88
89 /// audio inputs
90 float* in = self->audioInput;
91 float* out = self->audioOutput;
92
93 self->shs->length ( *self->length );
94 self->shs->position( *self->position );
95 self->shs->volume ( *self->volume );
96 self->shs->doIt ( (*self->doIt >= 0.500) ? true : false );
97
98 self->shs->process( nframes, in, out );
99 }
100
cleanup(LV2_Handle instance)101 void Friza::cleanup(LV2_Handle instance)
102 {
103 delete ((Friza*) instance);
104 }
105
extension_data(const char * uri)106 const void* Friza::extension_data(const char* uri)
107 {
108 return 0;
109 }
110