Hey All,
Today I figured out how to use the FAUST libraries ("import" statements). In the source code for faust, there's a folder called "architecture", and there are files called "music.lib", "oscillators.lib", "effects.lib" etc...
These files can be included, and then you can use the functionality included in them! The following code shows how to create a sawtooth oscillator, and then apply and ADSR to the signal. Pretty simple, but very educational :)
Code:
// import the needed libraries
import("music.lib");
import("oscillator.lib");
// generate a sawtooth wave, using "saw1" from "oscillator.lib"
sawGen = saw1( vslider("Freq", 60, 0, 127, 0.1) );
// get variables for A D S and R stages, using sliders
attack = 1.0/(SR*nentry("[1:]attack [unit:ms][style:knob]", 20, 1, 1000, 1)/1000);
decay = nentry("[2:]decay[style:knob]", 2, 1, 100, 0.1)/100000;
sustain = nentry("[3:]sustain [unit:pc][style:knob]", 10, 1, 100, 0.1)/100;
release = nentry("[4:]release[style:knob]", 10, 1, 100, 0.1)/100000;
// set the process function, using the button to trigger the ADSR, and then volume scale the sawtooth
process = button("play"): hgroup("", adsr(attack, decay, sustain, release) : *(sawGen));
GUI using JACK & GTK:
The comments there should tell you what it does, and the compilation is the same as the last tutorial... Enjoy the sawtooth madness!
A blog dedicated to creating A/V stuff with only open-source software on linux.
Showing posts with label faust. Show all posts
Showing posts with label faust. Show all posts
Thursday, May 10, 2012
Saturday, May 5, 2012
Creating DSP units using Faust
Today we tackle writing DSP code, and then compiling it into a format that is usable for your platform & workflow. That means writing the DSP code once, and compiling it for each platform as nessisary, a big time saver. To do this we have Faust: Functional AUdio STream. Its a high level domain specific programming language to write audio processing code in :)
Best bit: there's an online compiler for you to play with before any commitment! http://faust.grame.fr/index.php/online-examples
So you want to compile plugins locally? Good! Grab the faust package from your distro, it will install the compiler & some extra bits we need.
Now go to your faust programming folder, and lets get started:
touch test1.dsp
grab one of the simple examples from the Online Examples, and copy the Faust code into your .dsp file
First we need to compile from the Faust code into valid C++: that means that we needs to have access to all Faust specific things like architecture files etc. An architecture file is a "template" for building a program, JACK + console is one example. Jack & GTK is another. JACK & QT, LADSPA, LV2 etc are also all architecture examples.
Since I'm on Linux with GTK, I'm using the jack-gtk.cpp architecture file like so:
faust -a jack-gtk.cpp bitcrush.dsp -o bitcrush.cpp
Now we run the generated .cpp file trough g++, a standard C++ compiler, and provide it with the nessisary info to link the executable. Simple huh??
g++ -I/usr/lib/faust/ -lpthread `pkg-config --cflags --libs jack gtk+-2.0` bitcrush.cpp -o bitcrush
Note: I've added an include path there so that the compiler knows what where to look for the architecture files etc, its needed! If you don't you'll get an error like so:
[munch] fatal error: gui/FUI.h: No such file or directory
Once that's fixed by adding the relevant include paths, it should work :D
Enjoy! -Harry
Best bit: there's an online compiler for you to play with before any commitment! http://faust.grame.fr/index.php/online-examples
So you want to compile plugins locally? Good! Grab the faust package from your distro, it will install the compiler & some extra bits we need.
Now go to your faust programming folder, and lets get started:
touch test1.dsp
grab one of the simple examples from the Online Examples, and copy the Faust code into your .dsp file
First we need to compile from the Faust code into valid C++: that means that we needs to have access to all Faust specific things like architecture files etc. An architecture file is a "template" for building a program, JACK + console is one example. Jack & GTK is another. JACK & QT, LADSPA, LV2 etc are also all architecture examples.
Since I'm on Linux with GTK, I'm using the jack-gtk.cpp architecture file like so:
faust -a jack-gtk.cpp bitcrush.dsp -o bitcrush.cpp
Now we run the generated .cpp file trough g++, a standard C++ compiler, and provide it with the nessisary info to link the executable. Simple huh??
g++ -I/usr/lib/faust/ -lpthread `pkg-config --cflags --libs jack gtk+-2.0` bitcrush.cpp -o bitcrush
Note: I've added an include path there so that the compiler knows what where to look for the architecture files etc, its needed! If you don't you'll get an error like so:
[munch] fatal error: gui/FUI.h: No such file or directory
Once that's fixed by adding the relevant include paths, it should work :D
Enjoy! -Harry
Subscribe to:
Posts (Atom)
