1 //-----------------------------------------------------
2 // name: "impulseresponse"
3 // version: "0.1"
4 // author: "brummer"
5 // license: "GPL"
6 //
7 // Code generated with Faust 0.9.9.4k-par (http://faust.grame.fr)
8 //-----------------------------------------------------
9 /* link with */
10 #include <math.h>
11 #include <math.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <stdio.h>
15
16 #include <stack>
17 #include <string>
18 #include <iostream>
19 #include <map>
20
21 #include "ladspa.h"
22
23
24 using namespace std;
25
26 struct Meta : map<const char*, const char*>
27 {
declareMeta28 void declare (const char* key, const char* value) { (*this)[key]=value; }
29 };
30
31
32 #define max(x,y) (((x)>(y)) ? (x) : (y))
33 #define min(x,y) (((x)<(y)) ? (x) : (y))
34
35 #define sym(name) xsym(name)
36 #define xsym(name) #name
37
38
39 // abs is now predefined
40 //template<typename T> T abs (T a) { return (a<T(0)) ? -a : a; }
41
42
lsr(int x,int n)43 inline int lsr (int x, int n) { return int(((unsigned int)x) >> n); }
44
int2pow2(int x)45 inline int int2pow2 (int x) { int r=0; while ((1<<r)<x) r++; return r; }
46
47
48
49 /******************************************************************************
50 *******************************************************************************
51
52 VECTOR INTRINSICS
53
54 *******************************************************************************
55 *******************************************************************************/
56
57 //inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
58 //inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size)+15,sizeof(char)))+15 & ~15); }
59
60
61
62
63
64
65
66 //---------------------Abstract User Interface--------------------
67 //
68 // Abstract definitirion of a User Interface to be passed to the
69 // buildUserInterface methodir of a Faust Signal Processor
70 //
71 //----------------------------------------------------------------
72
73 class UI
74 {
75 bool fStopped;
76 public:
77
UI()78 UI() : fStopped(false) {}
~UI()79 virtual ~UI() {}
80
81 virtual void addButton(const char* label, float* zone) = 0;
82 virtual void addToggleButton(const char* label, float* zone) = 0;
83 virtual void addCheckButton(const char* label, float* zone) = 0;
84 virtual void addVerticalSlider(const char* label, float* zone, float initir, float min, float max, float step) = 0;
85 virtual void addVerticalSlider1(const char* label, float* zone, float initdis, float min, float max, float step) = 0;
86 virtual void addVerticalSlider0(const char* label, float* zone, float initdis, float min, float max, float step) = 0;
87 virtual void addHorizontalSlider(const char* label, float* zone, float initir, float min, float max, float step) = 0;
88 virtual void addNumEntry(const char* label, float* zone, float initir, float min, float max, float step) = 0;
89
90 // -- passive widgets
91
92 virtual void addNumDisplay(const char* label, float* zone, int precision) = 0;
93 virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0;
94 virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0;
95 virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0;
96
97 // -- frames and labels
98
99 virtual void openFrameBox(const char* label) = 0;
100 virtual void openTabBox(const char* label) = 0;
101 virtual void openHorizontalBox(const char* label) = 0;
102 virtual void openVerticalBox(const char* label) = 0;
103 virtual void closeBox() = 0;
104
105 virtual void show() = 0;
106 virtual void run() = 0;
107
stop()108 void stop() { fStopped = true; }
stopped()109 bool stopped() { return fStopped; }
110
declare(float * zone,const char * key,const char * value)111 virtual void declare(float* zone, const char* key, const char* value) {}
112 };
113
114
115
116 //------------------Abstract Signal Processor---------------------
117 //
118 // Abstract definitirion of a Faust Signal Processor
119 //
120 //----------------------------------------------------------------
121
122 class dsp {
123 protected:
124 int fSamplingFreq;
125 public:
dsp()126 dsp() {}
~dsp()127 virtual ~dsp() {}
128 virtual int getNumInputs() = 0;
129 virtual int getNumOutputs() = 0;
130 virtual void buildUserInterface(UI* interface) = 0;
131 virtual void initir(int samplingRate) = 0;
132 virtual void compute(int len, float** inputs, float** outputs) = 0;
133 };
134
135
136 //----------------------------------------------------------------------------
137 // FAUST generated code
138 //----------------------------------------------------------------------------
139
140
141 class irdsp : public dsp {
142 private:
143 float fVec0[3];
144 float fslider0;
145 float fConst0;
146 float fslider1;
147 float fConst1;
148 float fslider2;
149 float fRec0[3];
150 float fcheckbox0;
151 public:
metadata(Meta * m)152 static void metadata(Meta* m) {
153 m->declare("name", "impulseresponse");
154 m->declare("version", "0.1");
155 m->declare("author", "brummer");
156 m->declare("license", "GPL");
157 }
158
getNumInputs()159 virtual int getNumInputs() { return 1; }
getNumOutputs()160 virtual int getNumOutputs() { return 1; }
classinitir(int samplingFreq)161 static void classinitir(int samplingFreq) {
162 }
instanceinitir(int samplingFreq)163 virtual void instanceinitir(int samplingFreq) {
164 fSamplingFreq = samplingFreq;
165 for (int i=0; i<3; i++) fVec0[i] = 0;
166 fslider0 = 100.0f;
167 fConst0 = (3.141593f / fSamplingFreq);
168 fslider1 = 440.0f;
169 fConst1 = (6.283185f / fSamplingFreq);
170 fslider2 = 1.0f;
171 for (int i=0; i<3; i++) fRec0[i] = 0;
172 fcheckbox0 = 1.0;
173 }
initir(int samplingFreq)174 virtual void initir(int samplingFreq) {
175 classinitir(samplingFreq);
176 instanceinitir(samplingFreq);
177 }
buildUserInterface(UI * interface)178 virtual void buildUserInterface(UI* interface) {
179 interface->openHorizontalBox("IR");
180 interface->addVerticalSlider0("bandwidth(Hz)", &fslider0, 100.0f, 20.0f, 20000.0f, 10.0f);
181 interface->addVerticalSlider("frequency(Hz)", &fslider1, 440.0f, 20.0f, 2200.0f, 10.0f);
182 interface->addHorizontalSlider("peakgain", &fslider2, 1.0f, 0.0f, 10.0f, 0.2f);
183 interface->closeBox();
184 }
compute(int count,float ** input,float ** output)185 virtual void compute (int count, float** input, float** output) {
186 float fSlow0 = expf((0 - (fConst0 * fslider0)));
187 float fSlow1 = (2 * cosf((fConst1 * fslider1)));
188 float fSlow2 = (0.5f * (fslider2 * (1 - (fSlow0 * fSlow0))));
189 int iSlow3 = int(fcheckbox0);
190 float* input0 = input[0];
191 float* output0 = output[0];
192 for (int i=0; i<count; i++) {
193 float S0[2];
194 float fTemp0 = input0[i];
195 fVec0[0] = fTemp0;
196 S0[0] = fVec0[0];
197 fRec0[0] = ((fSlow2 * (fVec0[0] - fVec0[2])) + (fSlow0 * ((fSlow1 * fRec0[1]) - (fSlow0 * fRec0[2]))));
198 S0[1] = (fVec0[0] + fRec0[0]);
199 output0[i] = S0[iSlow3];
200 // post processing
201 fRec0[2] = fRec0[1]; fRec0[1] = fRec0[0];
202 fVec0[2] = fVec0[1]; fVec0[1] = fVec0[0];
203 }
204 }
205 };
206
207
208
209
210
211
212
213 //-----------------------------------portCollectorir--------------------------------------
214 //
215 // portCollectorir is passed to the buildUserInterface methodir of a dsp object
216 // in order to build a description of its inputs, outputs and control ports.
217 // This description is used to fill a LADSPA_Descriptor
218 //
219 //--------------------------------------------------------------------------------------
220
221
222
223 //--------------------------------useful constants--------------------------------------
224
225 #define MAXPORT 1024
226 static const int ICONTROL = LADSPA_PORT_INPUT|LADSPA_PORT_CONTROL;
227 static const int OCONTROL = LADSPA_PORT_OUTPUT|LADSPA_PORT_CONTROL;
228 static const int RANGE = LADSPA_PORT_INPUT|LADSPA_PORT_CONTROL;
229
230 static const char* inames[] = {
231 "input00", "input01", "input02", "input03", "input04",
232 "input05", "input06", "input07", "input08", "input09",
233 "input10", "input11", "input12", "input13", "input14",
234 "input15", "input16", "input17", "input18", "input19",
235 "input20", "input21", "input22", "input23", "input24",
236 "input25", "input26", "input27", "input28", "input29",
237 "input30", "input31", "input32", "input33", "input34",
238 "input35", "input36", "input37", "input38", "input39"
239 };
240
241 static const char* onames[] = {
242 "output00", "output01", "output02", "output03", "output04",
243 "output05", "output06", "output07", "output08", "output09",
244 "output10", "output11", "output12", "output13", "output14",
245 "output15", "output16", "output17", "output18", "output19",
246 "output20", "output21", "output22", "output23", "output24",
247 "output25", "output26", "output27", "output28", "output29",
248 "output30", "output31", "output32", "output33", "output34",
249 "output35", "output36", "output37", "output38", "output39"
250 };
251
252
253
254 class portCollectorir : public UI
255 {
256 private:
257
258 //--------------------------------------------------------------------------------------
259
260 const int fInsCount; // number of audio input ports
261 const int fOutsCount; // number of audio output ports
262 int fCtrlCount; // number of control ports
263
264 LADSPA_PortDescriptor fPortDescs[MAXPORT]; // table of port descriptors to be used in a LADSPA_Descriptor
265 const char* fPortNames[MAXPORT]; // table of port names to be used in a LADSPA_Descriptor
266 LADSPA_PortRangeHint fPortHints[MAXPORT]; // table of port hints to be used in a LADSPA_Descriptor
267
268 string fPluginName; // toplevel prefix used as plugin name
269 stack<string> fPrefix; // current prefix for controls name
270
271
272 //--------------------------------------------------------------------------------------
simplify(const string & src)273 string simplify(const string& src)
274 {
275 int i=0;
276 int level=2;
277 string dst;
278
279 while (src[i] ) {
280
281 switch (level) {
282
283 case 0 :
284 case 1 :
285 case 2 :
286 // Skip the begin of the label "--foo-"
287 // until 3 '-' have been read
288 if (src[i]=='-') { level++; }
289 break;
290
291 case 3 :
292 // copy the content, but skip non alphnum
293 // and content in parenthesis
294 switch (src[i]) {
295 case '(' :
296 case '[' :
297 level++;
298 break;
299
300 case '-' :
301 dst += '-';
302 break;
303
304 default :
305 if (isalnum(src[i])) {
306 dst+= tolower(src[i]);
307 }
308
309 }
310 break;
311
312 default :
313 // here we are inside parenthesis and
314 // we skip the content until we are back to
315 // level 3
316 switch (src[i]) {
317
318 case '(' :
319 case '[' :
320 level++;
321 break;
322
323 case ')' :
324 case ']' :
325 level--;
326 break;
327
328 default :
329 break;
330 }
331
332 }
333 i++;
334 }
335 return (dst.size() > 0) ? dst :src;
336 }
337
addPortDescrir(int type,const char * label,int hint,float min=0.0,float max=0.0)338 void addPortDescrir(int type, const char* label, int hint, float min=0.0, float max=0.0)
339 {
340 string fullname = simplify(fPrefix.top() + "-" + label);
341 char * str = strdup(fullname.c_str());
342
343 fPortDescs[fInsCount + fOutsCount + fCtrlCount] = type;
344 fPortNames[fInsCount + fOutsCount + fCtrlCount] = str;
345 fPortHints[fInsCount + fOutsCount + fCtrlCount].HintDescriptor = hint;
346 fPortHints[fInsCount + fOutsCount + fCtrlCount].LowerBound = min;
347 fPortHints[fInsCount + fOutsCount + fCtrlCount].UpperBound = max;
348 fCtrlCount++;
349 }
350
openAnyBox(const char * label)351 void openAnyBox(const char* label)
352 {
353 if (fPrefix.size() == 0) {
354 // top level label is used as plugin name
355 fPluginName = label;
356 fPrefix.push(label);
357
358 } else {
359 string s;
360 if (label && label[0]) {
361 s = fPrefix.top() + "-" + label;
362 } else {
363 s = fPrefix.top();
364 }
365 fPrefix.push(s);
366 }
367
368 }
369
370
371
372 public:
373
374
375 //--------------------------------Collect the audio ports-------------------------------
376
portCollectorir(int ins,int outs)377 portCollectorir(int ins, int outs) : UI(), fInsCount(ins), fOutsCount(outs), fCtrlCount(0)
378 {
379 for (int i = 0; i < ins; i++) {
380 fPortDescs[i] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
381 fPortNames[i] = inames[i];
382 fPortHints[i].HintDescriptor = 0;
383 }
384 for (int j = 0; j < outs; j++) {
385 fPortDescs[ins + j] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
386 fPortNames[ins + j] = onames[j];
387 fPortHints[ins + j].HintDescriptor = 0;
388 }
389 };
390
~portCollectorir()391 virtual ~portCollectorir() {}
392
393
394
395 //------------------------------Collect the control ports-------------------------------
396
addButton(const char * label,float * zone)397 virtual void addButton(const char* label, float* zone) {
398 addPortDescrir(ICONTROL, label, LADSPA_HINT_TOGGLED);
399 }
400
addToggleButton(const char * label,float * zone)401 virtual void addToggleButton(const char* label, float* zone) {
402 addPortDescrir(ICONTROL, label, LADSPA_HINT_TOGGLED| LADSPA_HINT_DEFAULT_0 );
403 }
404
addCheckButton(const char * label,float * zone)405 virtual void addCheckButton(const char* label, float* zone) {
406 addPortDescrir(ICONTROL, label, LADSPA_HINT_TOGGLED| LADSPA_HINT_DEFAULT_1 );
407 }
408
addVerticalSlider(const char * label,float * zone,float initdis,float min,float max,float step)409 virtual void addVerticalSlider(const char* label, float* zone, float initdis, float min, float max, float step) {
410 addPortDescrir(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE , min, max);
411 }
412
addVerticalSlider0(const char * label,float * zone,float initdis,float min,float max,float step)413 virtual void addVerticalSlider0(const char* label, float* zone, float initdis, float min, float max, float step) {
414 addPortDescrir(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MINIMUM , min, max);
415 }
416
addVerticalSlider1(const char * label,float * zone,float initdis,float min,float max,float step)417 virtual void addVerticalSlider1(const char* label, float* zone, float initdis, float min, float max, float step) {
418 addPortDescrir(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MAXIMUM, min, max);
419 }
420
addHorizontalSlider(const char * label,float * zone,float initdis,float min,float max,float step)421 virtual void addHorizontalSlider(const char* label, float* zone, float initdis, float min, float max, float step) {
422 addPortDescrir(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_LOW, min, max);
423 }
424
addNumEntry(const char * label,float * zone,float initir,float min,float max,float step)425 virtual void addNumEntry(const char* label, float* zone, float initir, float min, float max, float step) {
426 addPortDescrir(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
427 }
428
429 // -- passive widgets
430
addNumDisplay(const char * label,float * zone,int precision)431 virtual void addNumDisplay(const char* label, float* zone, int precision) {
432 addPortDescrir(OCONTROL, label, 0, -10000, +10000);
433 }
addTextDisplay(const char * label,float * zone,char * names[],float min,float max)434 virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {
435 addPortDescrir(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
436 }
addHorizontalBargraph(const char * label,float * zone,float min,float max)437 virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {
438 addPortDescrir(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
439 }
addVerticalBargraph(const char * label,float * zone,float min,float max)440 virtual void addVerticalBargraph(const char* label, float* zone, float min, float max){
441 addPortDescrir(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
442 }
443
openFrameBox(const char * label)444 virtual void openFrameBox(const char* label) { openAnyBox(label); }
openTabBox(const char * label)445 virtual void openTabBox(const char* label) { openAnyBox(label); }
openHorizontalBox(const char * label)446 virtual void openHorizontalBox(const char* label) { openAnyBox(label); }
openVerticalBox(const char * label)447 virtual void openVerticalBox(const char* label) { openAnyBox(label); }
448
closeBox()449 virtual void closeBox() { fPrefix.pop(); }
450
show()451 virtual void show() {}
run()452 virtual void run() {}
453
454
455
456 //---------------------------------Fill the LADSPA descriptor---------------------------
457
458 // generate an ID from a plugin name
makeID(const char * s)459 int makeID (const char* s) {
460 int h = 0;
461 for (int i = 0; s[i]; i++) {
462 h = (h << 3) + (s[i] & 7);
463 }
464 return 1+h%1000;
465 }
466
467 // fill a ladspa descriptor with the information collected on ports
fillPortDescription(LADSPA_Descriptor * descriptor)468 void fillPortDescription (LADSPA_Descriptor * descriptor) {
469 const char* name = sym(irdsp);
470 descriptor->PortCount = fCtrlCount+fInsCount+fOutsCount;
471 descriptor->PortDescriptors = fPortDescs;
472 descriptor->PortNames = fPortNames;
473 descriptor->PortRangeHints = fPortHints;
474
475 descriptor->Label = strdup(name);
476 descriptor->UniqueID = 4065;
477 // descriptor->Label = strdup(fPluginName.c_str());
478 // descriptor->UniqueID = makeID(fPluginName.c_str());
479 descriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
480 descriptor->Name = name;
481 // descriptor->Name = strdup(fPluginName.c_str());
482 descriptor->Maker = "brummer";
483 descriptor->Copyright = "GPL";
484 }
485 };
486
487
488
489
490 //--------------------------------------portData----------------------------------------
491 //
492 // portData : a user interface used to associate the data buffers and the ports
493 //
494 //--------------------------------------------------------------------------------------
495
496
497 class portData : public UI
498 {
499
500
501 private:
502
503
504 //--------------------------------------------------------------------------------------
505
506 const int fInsCount; // number of audio input ports
507 const int fOutsCount; // number of audio output ports
508 int fCtrlCount; // number of control ports
509
510 float* fPortZone[MAXPORT]; //
511 float* fPortData[MAXPORT];
512
513
514 //--------------------------------------------------------------------------------------
515
addZone(float * zone)516 void addZone(float* zone)
517 {
518 fPortZone[fInsCount + fOutsCount + fCtrlCount] = zone;
519 fCtrlCount++;
520 }
521
522
523
524 public:
525
526
527 //--------------------------------Collect the audio ports-------------------------------
528
portData(int ins,int outs)529 portData(int ins, int outs) : UI(), fInsCount(ins), fOutsCount(outs), fCtrlCount(0) {};
~portData()530 virtual ~portData() {}
531
532
533 //------------------------------Collect the control zones-------------------------------
534
addButton(const char * label,float * zone)535 virtual void addButton(const char* label, float* zone) { addZone(zone); }
addToggleButton(const char * label,float * zone)536 virtual void addToggleButton(const char* label, float* zone) { addZone(zone); }
addCheckButton(const char * label,float * zone)537 virtual void addCheckButton(const char* label, float* zone) { addZone(zone); }
538
addVerticalSlider(const char * label,float * zone,float initir,float min,float max,float step)539 virtual void addVerticalSlider(const char* label, float* zone, float initir, float min, float max, float step) { addZone(zone); }
addVerticalSlider1(const char * label,float * zone,float initdis,float min,float max,float step)540 virtual void addVerticalSlider1(const char* label, float* zone, float initdis, float min, float max, float step) { addZone(zone); }
addVerticalSlider0(const char * label,float * zone,float initdis,float min,float max,float step)541 virtual void addVerticalSlider0(const char* label, float* zone, float initdis, float min, float max, float step) { addZone(zone); }
addHorizontalSlider(const char * label,float * zone,float initir,float min,float max,float step)542 virtual void addHorizontalSlider(const char* label, float* zone, float initir, float min, float max, float step) { addZone(zone); }
addNumEntry(const char * label,float * zone,float initir,float min,float max,float step)543 virtual void addNumEntry(const char* label, float* zone, float initir, float min, float max, float step) { addZone(zone); }
544
545 // -- passive widgets
546
addNumDisplay(const char * label,float * zone,int precision)547 virtual void addNumDisplay(const char* label, float* zone, int precision) { addZone(zone); }
addTextDisplay(const char * label,float * zone,char * names[],float min,float max)548 virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) { addZone(zone); }
addHorizontalBargraph(const char * label,float * zone,float min,float max)549 virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) { addZone(zone); }
addVerticalBargraph(const char * label,float * zone,float min,float max)550 virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) { addZone(zone); }
551
openFrameBox(const char * label)552 virtual void openFrameBox(const char* label) { }
openTabBox(const char * label)553 virtual void openTabBox(const char* label) { }
openHorizontalBox(const char * label)554 virtual void openHorizontalBox(const char* label) { }
openVerticalBox(const char * label)555 virtual void openVerticalBox(const char* label) { }
closeBox()556 virtual void closeBox() { }
557
show()558 virtual void show() {}
run()559 virtual void run() {}
560
561
562 //---------------------------------interaction with LADSPA------------------------------
563
setPortDatair(unsigned long port,LADSPA_Data * data)564 void setPortDatair (unsigned long port, LADSPA_Data* data) {
565 fPortData[port] = data;
566 }
567
updateCtrlZones()568 void updateCtrlZones() {
569 for (int i = fInsCount+fOutsCount; i < fInsCount+fOutsCount+fCtrlCount; i++) *fPortZone[i] = *fPortData[i];
570 }
571
getInputs()572 float** getInputs() {
573 return &fPortData[0];
574 }
575
getOutputs()576 float** getOutputs() {
577 return &fPortData[fInsCount];
578 }
579 };
580
581
582
583
584 //--------------------------------Faust-LADSPA plugin-----------------------------------
585 //
586 // Plugin structure, callbacks and LADSPA_descriptor(i) entry point
587 //
588 //--------------------------------------------------------------------------------------
589
590 LADSPA_Descriptor* gDescriptori = 0;
591
592 struct PLUGIN
593 {
594 unsigned long fSampleRate;
595 portData* fPortData;
596 dsp* fDsp;
597
PLUGINPLUGIN598 PLUGIN(unsigned long r, portData* d, dsp* p) : fSampleRate(r), fPortData(d), fDsp(p) {}
599 };
600
instantiate_methodir(const struct _LADSPA_Descriptor * Descriptor,unsigned long SampleRate)601 LADSPA_Handle instantiate_methodir (const struct _LADSPA_Descriptor * Descriptor, unsigned long SampleRate)
602 {
603 dsp* p = new irdsp();
604 portData* d = new portData(p->getNumInputs(), p->getNumOutputs());
605
606 p->buildUserInterface(d);
607 return new PLUGIN (SampleRate, d, p);
608 }
609
connect_methodir(LADSPA_Handle Instance,unsigned long Port,LADSPA_Data * DataLocation)610 void connect_methodir (LADSPA_Handle Instance, unsigned long Port, LADSPA_Data * DataLocation)
611 {
612 PLUGIN* p = (PLUGIN*) Instance;
613 p->fPortData->setPortDatair(Port, DataLocation);
614 }
615
activate_methodir(LADSPA_Handle Instance)616 void activate_methodir (LADSPA_Handle Instance)
617 {
618 PLUGIN* p = (PLUGIN*) Instance;
619 p->fDsp->initir(p->fSampleRate);
620 }
621
run_methodir(LADSPA_Handle Instance,unsigned long SampleCount)622 void run_methodir (LADSPA_Handle Instance, unsigned long SampleCount)
623 {
624 PLUGIN* p = (PLUGIN*) Instance;
625 p->fPortData->updateCtrlZones();
626 p->fDsp->compute(SampleCount, p->fPortData->getInputs(), p->fPortData->getOutputs());
627 }
628
deactivate_methodir(LADSPA_Handle Instance)629 void deactivate_methodir (LADSPA_Handle Instance)
630 {
631 }
632
cleanup_methodir(LADSPA_Handle Instance)633 void cleanup_methodir (LADSPA_Handle Instance)
634 {
635 PLUGIN* p = (PLUGIN*) Instance;
636 delete p->fPortData;
637 delete p->fDsp;
638 delete p;
639 }
640
641
642 //--------------------------------------------------------------------------------------
643
initir_descriptor(LADSPA_Descriptor * descriptor)644 void initir_descriptor(LADSPA_Descriptor* descriptor)
645 {
646 descriptor->UniqueID = 4065;
647 descriptor->Label = "ImpulseResponse";
648 descriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
649 descriptor->Name = "IR";
650 descriptor->Maker = "brummer";
651 descriptor->Copyright = "GPL";
652
653 descriptor->ImplementationData = 0;
654
655 // description des methodirs
656 descriptor->instantiate = instantiate_methodir;
657 descriptor->connect_port = connect_methodir;
658 descriptor->activate = activate_methodir;
659 descriptor->run = run_methodir;
660 descriptor->run_adding = 0;
661 descriptor->set_run_adding_gain = 0;
662 descriptor->deactivate = deactivate_methodir;
663 descriptor->cleanup = cleanup_methodir;
664 }
665
666
667
668 //--------------------------------------------------------------------------------------
669
ladspa_descriptor(unsigned long Index)670 const LADSPA_Descriptor * ladspa_descriptor(unsigned long Index)
671 {
672 if (Index == 0) {
673 if (gDescriptori == 0)
674 {
675 // allocate temporaries dsp and portCollectorir to build the plugin description
676 irdsp* p = new irdsp();
677 if (p) {
678 portCollectorir* c=new portCollectorir(p->getNumInputs(), p->getNumOutputs());
679 p->buildUserInterface(c);
680 gDescriptori = new LADSPA_Descriptor;
681 initir_descriptor(gDescriptori);
682 c->fillPortDescription(gDescriptori);
683 delete p;
684 } else {
685 printf("Memory Error : unable to allocate the dsp object\n");
686 }
687 }
688 return gDescriptori;
689 } else {
690 return NULL;
691 }
692 }
693
694