1 /************************************************************************
2     IMPORTANT NOTE : this file contains two clearly delimited sections :
3     the ARCHITECTURE section (in two parts) and the USER section. Each section
4     is governed by its own copyright and license. Please check individually
5     each section for license and copyright information.
6 *************************************************************************/
7 
8 /*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/
9 
10 /************************************************************************
11     FAUST Architecture File
12     Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
13     ---------------------------------------------------------------------
14     This Architecture section is free software; you can redistribute it
15     and/or modify it under the terms of the GNU General Public License
16     as published by the Free Software Foundation; either version 3 of
17     the License, or (at your option) any later version.
18 
19     This program is distributed in the hope that it will be useful,
20     but WITHOUT ANY WARRANTY; without even the implied warranty of
21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22     GNU General Public License for more details.
23 
24     You should have received a copy of the GNU General Public License
25     along with this program; If not, see <http://www.gnu.org/licenses/>.
26 
27     EXCEPTION : As a special exception, you may create a larger work
28     that contains this FAUST architecture section and distribute
29     that work under terms of your choice, so long as this FAUST
30     architecture section is not modified.
31 
32  ************************************************************************
33  ************************************************************************/
34 
35 /******************************************************************************
36 *******************************************************************************
37 
38 								FAUST DSP
39 
40 *******************************************************************************
41 *******************************************************************************/
42 
43 #ifndef __dsp__
44 #define __dsp__
45 
46 #ifndef FAUSTFLOAT
47 #define FAUSTFLOAT float
48 #endif
49 
50 class UI;
51 struct Meta;
52 
53 /**
54 * Signal processor definition.
55 */
56 
57 class dsp {
58 
59     public:
60 
dsp()61         dsp() {}
~dsp()62         virtual ~dsp() {}
63 
64         /* Return instance number of audio inputs */
65         virtual int getNumInputs() = 0;
66 
67         /* Return instance number of audio outputs */
68         virtual int getNumOutputs() = 0;
69 
70         /**
71          * Trigger the UI* parameter with instance specific calls
72          * to 'addBtton', 'addVerticalSlider'... in order to build the UI.
73          *
74          * @param ui_interface - the UI* user interface builder
75          */
76         virtual void buildUserInterface(UI* ui_interface) = 0;
77 
78         /* Returns the sample rate currently used by the instance */
79         virtual int getSampleRate() = 0;
80 
81         /** Global init, calls the following methods:
82          * - static class 'classInit': static table initialisation
83          * - 'instanceInit': constants and instance table initialisation
84          *
85          * @param samplingRate - the sampling rate in Herz
86          */
87         virtual void init(int samplingRate) = 0;
88 
89         /** Init instance state
90          *
91          * @param samplingRate - the sampling rate in Hertz
92          */
93         virtual void instanceInit(int samplingRate) = 0;
94 
95         /** Init instance constant state
96          *
97          * @param samplingRate - the sampling rate in Hertz
98          */
99         virtual void instanceConstants(int samplingRate) = 0;
100 
101         /* Init default control parameters values */
102         virtual void instanceResetUserInterface() = 0;
103 
104         /* Init instance state (delay lines...) */
105         virtual void instanceClear() = 0;
106 
107         /**
108          * Return a clone of the instance.
109          *
110          * @return a copy of the instance on success, otherwise a null pointer.
111          */
112         virtual dsp* clone() = 0;
113 
114         /**
115          * Trigger the Meta* parameter with instance specific calls to 'declare' (key, value metadata).
116          *
117          * @param m - the Meta* meta user
118          */
119         virtual void metadata(Meta* m) = 0;
120 
121         /**
122          * DSP instance computation, to be called with sucessive in/out audio buffers.
123          *
124          * @param count - the nomber of frames to compute
125          * @param inputs - the input audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, double or quad)
126          * @param outputs - the output audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, double or quad)
127          *
128          */
129         virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) = 0;
130 
131         /**
132          * DSP instance computation: alternative method to be used by subclasses.
133          *
134          * @param date_usec - the timestamp in microsec given by audio driver.
135          * @param count - the nomber of frames to compute
136          * @param inputs - the input audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, double or quad)
137          * @param outputs - the output audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, double or quad)
138          *
139          */
compute(double date_usec,int count,FAUSTFLOAT ** inputs,FAUSTFLOAT ** outputs)140         virtual void compute(double date_usec, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { compute(count, inputs, outputs); }
141 
142 };
143 
144 /**
145  * Generic DSP decorator.
146  */
147 
148 class decorator_dsp : public dsp {
149 
150     protected:
151 
152         dsp* fDSP;
153 
154     public:
155 
fDSP(dsp)156         decorator_dsp(dsp* dsp = 0):fDSP(dsp) {}
~decorator_dsp()157         virtual ~decorator_dsp() { delete fDSP; }
158 
getNumInputs()159         virtual int getNumInputs() { return fDSP->getNumInputs(); }
getNumOutputs()160         virtual int getNumOutputs() { return fDSP->getNumOutputs(); }
buildUserInterface(UI * ui_interface)161         virtual void buildUserInterface(UI* ui_interface) { fDSP->buildUserInterface(ui_interface); }
getSampleRate()162         virtual int getSampleRate() { return fDSP->getSampleRate(); }
init(int samplingRate)163         virtual void init(int samplingRate) { fDSP->init(samplingRate); }
instanceInit(int samplingRate)164         virtual void instanceInit(int samplingRate) { fDSP->instanceInit(samplingRate); }
instanceConstants(int samplingRate)165         virtual void instanceConstants(int samplingRate) { fDSP->instanceConstants(samplingRate); }
instanceResetUserInterface()166         virtual void instanceResetUserInterface() { fDSP->instanceResetUserInterface(); }
instanceClear()167         virtual void instanceClear() { fDSP->instanceClear(); }
clone()168         virtual decorator_dsp* clone() { return new decorator_dsp(fDSP->clone()); }
metadata(Meta * m)169         virtual void metadata(Meta* m) { return fDSP->metadata(m); }
170         // Beware: subclasses usually have to overload the two 'compute' methods
compute(int count,FAUSTFLOAT ** inputs,FAUSTFLOAT ** outputs)171         virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { fDSP->compute(count, inputs, outputs); }
compute(double date_usec,int count,FAUSTFLOAT ** inputs,FAUSTFLOAT ** outputs)172         virtual void compute(double date_usec, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { fDSP->compute(date_usec, count, inputs, outputs); }
173 
174 };
175 
176 /**
177  * On Intel set FZ (Flush to Zero) and DAZ (Denormals Are Zero)
178  * flags to avoid costly denormals.
179  */
180 
181 #ifdef __SSE__
182     #include <xmmintrin.h>
183     #ifdef __SSE2__
184         #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8040)
185     #else
186         #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8000)
187     #endif
188 #else
189     #define AVOIDDENORMALS
190 #endif
191 
192 #endif
193