X-Git-Url: https://scm.cri.ensmp.fr/git/Faustine.git/blobdiff_plain/1059e1cc0c2ecfa237406949aa26155b6a5b9154..66f23d4fabf89ad09adbd4dfc15ac6b5b2b7da83:/interpretor/preprocessor/faust-0.9.47mr3/architecture/octave.cpp diff --git a/interpretor/preprocessor/faust-0.9.47mr3/architecture/octave.cpp b/interpretor/preprocessor/faust-0.9.47mr3/architecture/octave.cpp deleted file mode 100644 index 7721d5e..0000000 --- a/interpretor/preprocessor/faust-0.9.47mr3/architecture/octave.cpp +++ /dev/null @@ -1,490 +0,0 @@ -/* octave.cpp - Copyright (C) 2009 by Bjoern Anton Erlach. */ - -// OCTAVE architecture file for faust. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -// 02111-1307 USA -//------------------------------------------------------------------- - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -using namespace std; - -// TODO: find out what to do with this Meta thing -struct Meta : map -{ - void declare (const char* key, const char* value) { (*this)[key]=value; } -}; - - -#define max(x,y) (((x)>(y)) ? (x) : (y)) -#define min(x,y) (((x)<(y)) ? (x) : (y)) - -// abs is now predefined -//template T abs (T a) { return (a> n); } - -/****************************************************************************** -******************************************************************************* - - VECTOR INTRINSICS - -******************************************************************************* -*******************************************************************************/ - -//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); } -//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size)+15,sizeof(char)))+15 & ~15); } - - -<> - -/****************************************************************************** -******************************************************************************* - - ABSTRACT USER INTERFACE - -******************************************************************************* -*******************************************************************************/ - - -class UI -{ - bool fStopped; -public: - - UI() : fStopped(false) {} - virtual ~UI() {} - - // -- active widgets - - virtual void addButton(const char* label, float* zone) = 0; - virtual void addToggleButton(const char* label, float* zone) = 0; - virtual void addCheckButton(const char* label, float* zone) = 0; - virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0; - virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0; - virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) = 0; - - // -- passive widgets - - virtual void addNumDisplay(const char* label, float* zone, int precision) = 0; - virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0; - virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0; - virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0; - - // -- frames and labels - - virtual void openFrameBox(const char* label) = 0; - virtual void openTabBox(const char* label) = 0; - virtual void openHorizontalBox(const char* label) = 0; - virtual void openVerticalBox(const char* label) = 0; - virtual void closeBox() = 0; - - virtual void show() = 0; - virtual void run() = 0; - - void stop() { fStopped = true; } - bool stopped() { return fStopped; } - - virtual void declare(float* zone, const char* key, const char* value) {} -}; - - -struct param { - string fName; float *fVals; float* fZone; float fMin; float fMax; - param(string name, float* z, float init, float a, float b) : fName(name), fVals(NULL), fZone(z), fMin(a), fMax(b) { *z = init; } -}; - - -class FNUI : public UI -{ - vector fParam; - int numOptions; - - -public: - FNUI() : UI() { numOptions=0; } - virtual ~FNUI() {} - - - void addOption(const char* label, float* zone, float init, float min, float max) - { - string fullname = label; - fParam.push_back(param(fullname, zone, init, min, max)); - numOptions++; - } - - virtual vector getOpts () { return fParam; } - - virtual void addButton(const char* label, float* zone) - { - addOption(label,zone,0,0,1); - } - - virtual int getNumOptions() { return numOptions; } - - virtual void addToggleButton(const char* label, float* zone) - { - addOption(label,zone,0,0,1); - } - - virtual void addCheckButton(const char* label, float* zone) - { - addOption(label,zone,0,0,1); - } - - virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) - { - addOption(label,zone,init,min,max); - } - - virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) - { - addOption(label,zone,init,min,max); - } - - virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) - { - addOption(label,zone,init,min,max); - } - - // -- passive widgets - - virtual void addNumDisplay(const char* label, float* zone, int precision) {} - virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {} - virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {} - virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) {} - - - virtual void openFrameBox(const char* label) { } - virtual void openTabBox(const char* label) { } - virtual void openHorizontalBox(const char* label) { } - virtual void openVerticalBox(const char* label) { } - - //virtual void openFrameBox(const char* label) { openAnyBox(label); } - //virtual void openTabBox(const char* label) { openAnyBox(label); } - //virtual void openHorizontalBox(const char* label) { openAnyBox(label); } - //virtual void openVerticalBox(const char* label) { openAnyBox(label); } - - //virtual void closeBox() { fPrefix.pop(); } - virtual void closeBox() { } - virtual void run() {} - virtual void show() {} - -}; - - - -/****************************************************************************** -******************************************************************************* - - FAUST DSP - -******************************************************************************* -*******************************************************************************/ - - - -//---------------------------------------------------------------- -// abstract definition of a signal processor -//---------------------------------------------------------------- - -class dsp { - protected: - int fSamplingFreq; - public: - dsp() {} - virtual ~dsp() {} - - virtual int getNumInputs() = 0; - virtual int getNumOutputs() = 0; - virtual void buildUserInterface(UI* interface) = 0; - virtual void init(int samplingRate) = 0; - virtual void compute(int len, float** inputs, float** outputs) = 0; -}; - - -//---------------------------------------------------------------------------- -// FAUST generated signal processor -//---------------------------------------------------------------------------- - - -<> - - -//---------------------------------------------------------------------------- -// Octave interface -//---------------------------------------------------------------------------- - -// Prefered way to allocate memory -#define ALLOC(x) alloca(x) -#define FREE(x) ((void)0) -// if ALLOCA is not available use MALLOC -//#define ALLOC(x) malloc(x) -//#define FREE(x) free(x) - -#define QUOTEME(x) #x - -#define DEFAULT_SAMPLERATE 44100 -#define DEFAULT_BLOCKSIZE 64 - -// linear interpolation for vector valued control inputs -void -interpolate_ctrlin (float *vals, NDArray in, int n) -{ - int nin = in.length(); - double ratio = (double)(n-1)/(double)(nin-1); - int irat = (int) ratio; - double frat = ratio - (double) irat; - double rest = 0; - int i = 0; - float x; - - for (int j=0; j<(nin-1); j++) { - float del; - int seglength = irat; - rest += frat; - if (rest >= 1.0) { - seglength ++; - rest -= 1.0; - } - del = (in(j+1) - in(j)) / (float) seglength; - x = in(j); - for (int k=0; k opts; - int bsize; - int srate; - octave_value_list retval; - octave_value tmp; - - FNUI* interface = new FNUI(); - DSP.buildUserInterface(interface); - - // check if global variable FAUST_BLOCKSIZE is set. - tmp = get_global_value ("FAUST_BLOCKSIZE", true); - if (tmp.is_defined ()) - bsize = (int) tmp.scalar_value(); - else { - bsize = DEFAULT_BLOCKSIZE; - } - - // check if global variable FAUST_SAMPLERATE is set. - tmp = get_global_value ("FAUST_SAMPLERATE", true); - if (tmp.is_defined ()) - srate = (int) tmp.scalar_value(); - else { - srate = DEFAULT_SAMPLERATE; - } - - DSP.init(srate); - opts = interface->getOpts(); - - numIn = DSP.getNumInputs(); - numOut = DSP.getNumOutputs(); - numOpts = interface->getNumOptions(); - - // print a usage message in case the function is called with too few arguments - if (nargin < numIn || nargin == 0) { - if (numOut>1) { - octave_stdout << "[out1"; - for (i=2; i<=numOut; i++) - octave_stdout << ",out" << i; - octave_stdout << "] = " << QUOTEME(FAUST_FUNC_NAME) << "("; - } else { - octave_stdout << "out = " << QUOTEME(FAUST_FUNC_NAME) << "("; - } - if (numIn == 0) - octave_stdout << "numsamps"; - else - octave_stdout << "in1"; - for (i=2; i<=numIn; i++) - octave_stdout << ", in" << i; - for (i=0; i maxInputLength) - maxInputLength = nc; - } else if (nc == 1) { - if (nr > maxInputLength) - maxInputLength = nr; - } else { - maxInputLength = nc; - octave_stdout << "Argument " << i << " has wrong dimensions " << nr << "x" << nc << "\n"; - } - } - } - - - ctrllength = (maxInputLength+bsize-1)/bsize; - - // check for arguments that should serve as control inputs - for (i=ctrlargoff; i 1) { - allscalarctrls = 0; - opts[i-ctrlargoff].fVals = (float*) ALLOC(sizeof(float)*ctrllength); - interpolate_ctrlin(opts[i-ctrlargoff].fVals, v, ctrllength); - *opts[i-ctrlargoff].fZone = (float) v(0); - } else { - *opts[i-ctrlargoff].fZone = (float) args(i).scalar_value(); - } - } - } - - for (i=0; i m.columns()) { - for (int j=0; j 0) { - int n = min(bsize, nleft); - for (i=0; i