Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
661 lines (523 sloc) 18.7 KB
//-----------------------------------------------------
// name: "Noise"
// version: "1.1"
// author: "Grame"
// license: "BSD"
// copyright: "(c)GRAME 2009"
//
// Code generated with Faust 0.9.67 (http://faust.grame.fr)
//-----------------------------------------------------
/* link with */
/************************************************************************
************************************************************************
FAUST Architecture File
Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This is sample code. This file is provided as an example of minimal
FAUST architecture file. Redistribution and use in source and binary
forms, with or without modification, in part or in full are permitted.
In particular you can create a derived work of this FAUST architecture
and distribute that work under terms of your choice.
This sample code 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.
************************************************************************
************************************************************************/
#include <cmath>
#ifndef FAUST_GUI_H
#define FAUST_GUI_H
#ifndef FAUST_UI_H
#define FAUST_UI_H
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
/*******************************************************************************
* UI : Faust User Interface
* This abstract class contains only the method that the faust compiler can
* generate to describe a DSP interface.
******************************************************************************/
class UI
{
public:
UI() {}
virtual ~UI() {}
// -- widget's layouts
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;
// -- active widgets
virtual void addButton(const char* label, FAUSTFLOAT* zone) = 0;
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) = 0;
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) = 0;
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) = 0;
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) = 0;
// -- passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) = 0;
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) = 0;
// -- metadata declarations
virtual void declare(FAUSTFLOAT*, const char*, const char*) {}
};
#endif
#include <list>
#include <map>
/*******************************************************************************
* GUI : Abstract Graphic User Interface
* Provides additional macchanismes to synchronize widgets and zones. Widgets
* should both reflect the value of a zone and allow to change this value.
******************************************************************************/
class uiItem;
typedef void (*uiCallback)(FAUSTFLOAT val, void* data);
class clist : public std::list<uiItem*>
{
public:
virtual ~clist();
};
class GUI : public UI
{
typedef std::map<FAUSTFLOAT*, clist*> zmap;
private:
static std::list<GUI*> fGuiList;
zmap fZoneMap;
bool fStopped;
public:
GUI() : fStopped(false)
{
fGuiList.push_back(this);
}
virtual ~GUI()
{
// delete all
zmap::iterator g;
for (g = fZoneMap.begin(); g != fZoneMap.end(); g++) {
delete (*g).second;
}
// suppress 'this' in static fGuiList
fGuiList.remove(this);
}
// -- registerZone(z,c) : zone management
void registerZone(FAUSTFLOAT* z, uiItem* c)
{
if (fZoneMap.find(z) == fZoneMap.end()) fZoneMap[z] = new clist();
fZoneMap[z]->push_back(c);
}
void updateAllZones();
void updateZone(FAUSTFLOAT* z);
static void updateAllGuis()
{
std::list<GUI*>::iterator g;
for (g = fGuiList.begin(); g != fGuiList.end(); g++) {
(*g)->updateAllZones();
}
}
void addCallback(FAUSTFLOAT* zone, uiCallback foo, void* data);
virtual void show() {};
virtual void run() {};
void stop() { fStopped = true; }
bool stopped() { return fStopped; }
virtual void declare(FAUSTFLOAT* , const char* , const char* ) {}
};
/**
* User Interface Item: abstract definition
*/
class uiItem
{
protected :
GUI* fGUI;
FAUSTFLOAT* fZone;
FAUSTFLOAT fCache;
uiItem (GUI* ui, FAUSTFLOAT* zone) : fGUI(ui), fZone(zone), fCache(-123456.654321)
{
ui->registerZone(zone, this);
}
public :
virtual ~uiItem()
{}
void modifyZone(FAUSTFLOAT v)
{
fCache = v;
if (*fZone != v) {
*fZone = v;
fGUI->updateZone(fZone);
}
}
FAUSTFLOAT cache() { return fCache; }
virtual void reflectZone() = 0;
};
/**
* Callback Item
*/
struct uiCallbackItem : public uiItem
{
uiCallback fCallback;
void* fData;
uiCallbackItem(GUI* ui, FAUSTFLOAT* zone, uiCallback foo, void* data)
: uiItem(ui, zone), fCallback(foo), fData(data) {}
virtual void reflectZone() {
FAUSTFLOAT v = *fZone;
fCache = v;
fCallback(v, fData);
}
};
// en cours d'installation de call back. a finir!!!!!
/**
* Update all user items reflecting zone z
*/
inline void GUI::updateZone(FAUSTFLOAT* z)
{
FAUSTFLOAT v = *z;
clist* l = fZoneMap[z];
for (clist::iterator c = l->begin(); c != l->end(); c++) {
if ((*c)->cache() != v) (*c)->reflectZone();
}
}
/**
* Update all user items not up to date
*/
inline void GUI::updateAllZones()
{
for (zmap::iterator m = fZoneMap.begin(); m != fZoneMap.end(); m++) {
FAUSTFLOAT* z = m->first;
clist* l = m->second;
FAUSTFLOAT v = *z;
for (clist::iterator c = l->begin(); c != l->end(); c++) {
if ((*c)->cache() != v) (*c)->reflectZone();
}
}
}
inline void GUI::addCallback(FAUSTFLOAT* zone, uiCallback foo, void* data)
{
new uiCallbackItem(this, zone, foo, data);
};
inline clist::~clist()
{
std::list<uiItem*>::iterator it;
for (it = begin(); it != end(); it++) {
delete (*it);
}
}
#endif
/************************************************************************
IMPORTANT NOTE : this file contains two clearly delimited sections :
the ARCHITECTURE section (in two parts) and the USER section. Each section
is governed by its own copyright and license. Please check individually
each section for license and copyright information.
*************************************************************************/
/*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section 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 3 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, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************
************************************************************************/
/******************************************************************************
*******************************************************************************
FAUST DSP
*******************************************************************************
*******************************************************************************/
#ifndef __dsp__
#define __dsp__
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
class UI;
//----------------------------------------------------------------
// signal processor definition
//----------------------------------------------------------------
class dsp {
protected:
int fSamplingFreq;
public:
dsp() {}
virtual ~dsp() {}
virtual int getNumInputs() = 0;
virtual int getNumOutputs() = 0;
virtual void buildUserInterface(UI* ui_interface) = 0;
virtual void init(int samplingRate) = 0;
virtual void compute(int len, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) = 0;
};
// On Intel set FZ (Flush to Zero) and DAZ (Denormals Are Zero)
// flags to avoid costly denormals
#ifdef __SSE__
#include <xmmintrin.h>
#ifdef __SSE2__
#define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8040)
#else
#define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8000)
#endif
#else
#define AVOIDDENORMALS
#endif
#endif
/************************************************************************
************************************************************************
FAUST Architecture File
Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section 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 3 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, see <http://www.gnu.org/licenses/>.
************************************************************************
************************************************************************/
#ifndef __misc__
#define __misc__
#include <algorithm>
#include <map>
#include <string.h>
#include <stdlib.h>
/************************************************************************
************************************************************************
FAUST Architecture File
Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section 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 3 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, see <http://www.gnu.org/licenses/>.
************************************************************************
************************************************************************/
#ifndef __meta__
#define __meta__
struct Meta
{
virtual void declare(const char* key, const char* value) = 0;
};
#endif
using std::max;
using std::min;
struct XXXX_Meta : std::map<const char*, const char*>
{
void declare(const char* key, const char* value) { (*this)[key]=value; }
};
struct MY_Meta : Meta, std::map<const char*, const char*>
{
void declare(const char* key, const char* value) { (*this)[key]=value; }
};
inline int lsr(int x, int n) { return int(((unsigned int)x) >> n); }
inline int int2pow2(int x) { int r=0; while ((1<<r)<x) r++; return r; }
long lopt(char *argv[], const char *name, long def)
{
int i;
for (i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return atoi(argv[i+1]);
return def;
}
bool isopt(char *argv[], const char *name)
{
int i;
for (i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return true;
return false;
}
const char* lopts(char *argv[], const char *name, const char* def)
{
int i;
for (i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return argv[i+1];
return def;
}
#endif
/******************************************************************************
*******************************************************************************
VECTOR INTRINSICS
*******************************************************************************
*******************************************************************************/
/******************************************************************************
*******************************************************************************
ABSTRACT USER INTERFACE
*******************************************************************************
*******************************************************************************/
//----------------------------------------------------------------------------
// FAUST generated signal processor
//----------------------------------------------------------------------------
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
typedef long double quad;
#ifndef FAUSTCLASS
#define FAUSTCLASS Noise
#endif
class Noise : public dsp {
public:
FAUSTFLOAT fslider0;
int iRec0[2];
public:
static void metadata(Meta* m) {
m->declare("name", "Noise");
m->declare("version", "1.1");
m->declare("author", "Grame");
m->declare("license", "BSD");
m->declare("copyright", "(c)GRAME 2009");
}
virtual int getNumInputs() { return 0; }
virtual int getNumOutputs() { return 1; }
static void classInit(int samplingFreq) {
}
virtual void instanceInit(int samplingFreq) {
fSamplingFreq = samplingFreq;
fslider0 = 0.0f;
for (int i=0; i<2; i++) iRec0[i] = 0;
}
virtual void init(int samplingFreq) {
classInit(samplingFreq);
instanceInit(samplingFreq);
}
virtual void buildUserInterface(UI* interface) {
interface->openVerticalBox("noise");
interface->declare(&fslider0, "style", "knob");
interface->addVerticalSlider("Volume", &fslider0, 0.0f, 0.0f, 1.0f, 0.1f);
interface->closeBox();
}
virtual void compute (int count, FAUSTFLOAT** input, FAUSTFLOAT** output) {
float fSlow0 = (4.656612875245797e-10f * float(fslider0));
FAUSTFLOAT* output0 = output[0];
for (int i=0; i<count; i++) {
iRec0[0] = (12345 + (1103515245 * iRec0[1]));
output0[i] = (FAUSTFLOAT)(fSlow0 * iRec0[0]);
// post processing
iRec0[1] = iRec0[0];
}
}
};
#ifdef FAUST_UIMACROS
#define FAUST_INPUTS 0
#define FAUST_OUTPUTS 1
#define FAUST_ACTIVES 1
#define FAUST_PASSIVES 0
FAUST_ADDVERTICALSLIDER("noise/Volume", fslider0, 0.0f, 0.0f, 1.0f, 0.1f);
#endif
// Adapted From https://gist.github.com/camupod/5640386
// compile using "C" linkage to avoid name obfuscation
#include <emscripten.h>
#include <map>
#include <string>
extern "C" {
typedef std::map<std::string, FAUSTFLOAT*> UImap;
class JSUI : public UI
{
public:
JSUI() {};
~JSUI() {};
public:
UImap uiMap;
UImap::iterator iter;
public:
// -- widget's layouts
void openTabBox(const char* label)
{
};
void openHorizontalBox(const char* label)
{
};
void openVerticalBox(const char* label)
{
};
void closeBox()
{
};
// -- active widgets
void insertMap(const char* label, FAUSTFLOAT* zone)
{
uiMap.insert( std::pair<std::string, FAUSTFLOAT*>(label, zone));
}
void addButton(const char* label, FAUSTFLOAT* zone)
{
insertMap(label, zone);
};
void addCheckButton(const char* label, FAUSTFLOAT* zone)
{
insertMap(label, zone);
};
void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT fmin, FAUSTFLOAT fmax, FAUSTFLOAT step)
{
insertMap(label, zone);
};
void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT fmin, FAUSTFLOAT fmax, FAUSTFLOAT step)
{
insertMap(label, zone);
};
void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT fmin, FAUSTFLOAT fmax, FAUSTFLOAT step)
{
insertMap(label, zone);
};
// -- passive widgets
void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT fmin, FAUSTFLOAT fmax)
{
};
void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT fmin, FAUSTFLOAT fmax)
{
};
// -- metadata declarations
void declare(FAUSTFLOAT* zone, const char* key, const char* val)
{
};
};
class Noise_wrap : public Noise
{
public:
JSUI *ui;
};
//constructor
void *NOISE_constructor(int samplingFreq) {
// Make a new noise object
Noise_wrap* n = new Noise_wrap();
n->ui = new JSUI();
// Init it with samplingFreq supplied... should we give a sample size here too?
n->init(samplingFreq);
n->buildUserInterface(n->ui);
n->ui->iter = n->ui->uiMap.begin();
return n;
}
int NOISE_getNumParams(Noise_wrap *n)
{
return n->ui->uiMap.size();
}
FAUSTFLOAT* NOISE_getNextParam(Noise_wrap *n, char *key)
{
FAUSTFLOAT* valPtr = n->ui->iter->second;
strcpy(key, n->ui->iter->first.c_str());
n->ui->iter++;
if (n->ui->iter == n->ui->uiMap.end())
{
n->ui->iter = n->ui->uiMap.begin();
}
return valPtr;
}
int NOISE_compute(Noise_wrap *n, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) {
n->compute(count, inputs, outputs);
return 1;
}
int NOISE_getNumInputs(Noise_wrap *n){
return n->getNumInputs();
}
int NOISE_getNumOutputs(Noise_wrap *n){
return n->getNumOutputs();
}
void NOISE_destructor(Noise_wrap *n) {
delete n;
}
}