DSP Programming with Faust, Q and Supercollider Yann Orlarey, Albert Graef, Stefan Kersten

DSP Programming with Faust, Q and Supercollider Yann Orlarey, Albert Graef, Stefan Kersten

DSP Programming with Faust, Q and SuperCollider Yann Orlarey, Albert Graef, Stefan Kersten To cite this version: Yann Orlarey, Albert Graef, Stefan Kersten. DSP Programming with Faust, Q and SuperCollider. Linux Audio Conference, 2006, Karlsruhe, Germany. hal-02158894 HAL Id: hal-02158894 https://hal.archives-ouvertes.fr/hal-02158894 Submitted on 18 Jun 2019 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. DSP Programming with Faust, Q and SuperCollider Yann ORLAREY Albert GRAF¨ Stefan KERSTEN Grame, Centre National Dept. of Music Informatics Dept. of Communication de Creation Musicale Johannes Gutenberg University Science Lyon, France Mainz, Germany Technical University [email protected] [email protected] Berlin, Germany [email protected] Abstract diagram syntax. The functional programming Faust is a functional programming language for real- approach provides a natural framework for sig- time signal processing and synthesis that targets nal processing. Digital signals are modeled as high-performance signal processing applications and discrete functions of time, and signal processors audio plugins. The paper gives a brief introduction as second order functions that operate on them. to Faust and discusses its interfaces to Q, a general- Moreover Faust block-diagram composition op- purpose functional programming language, and Su- erators, used to combine signal processors to- perCollider, an object-oriented sound synthesis lan- gether, fit in the same picture as third order guage and engine. functions. Keywords Faust is a compiled language. The compiler Computer music, digital signal processing, Faust translates Faust programs into equivalent C++ programming language, functional programming, Q programs. It uses several optimization tech- programming language, SuperCollider niques in order to generate the most efficient code. The resulting code can usually compete 1 Introduction with, and sometimes outperform, DSP code di- Faust is a programming language for real-time rectly written in C. It is also self-contained and signal processing and synthesis that targets doesn’t depend on any DSP runtime library. high-performance signal processing applications Thanks to specific architecture files, a single and audio plugins. This paper gives a brief in- Faust program can be used to produce code for a troduction to Faust, emphasizing practical ex- variety of platforms and plugin formats. These amples rather than theoretic concepts which can architecture files act as wrappers and describe be found elsewhere (Orlarey et al., 2004). the interactions with the host audio and GUI A Faust program describes a signal proces- system. Currently more than 8 architectures sor, a DSP algorithm that transforms input are supported (see Table 1) and new ones can signals into output signals. Faust is a func- be easily added. tional programming language which models sig- nals as functions (of time) and DSP algorithms alsa-gtk.cpp ALSA application as higher-order functions operating on signals. jack-gtk.cpp JACK application Faust programs are compiled to efficient C++ sndfile.cpp command line application code which can be included in C/C++ appli- ladspa.cpp LADSPA plugin cations, and which can also be executed ei- max-msp.cpp Max MSP plugin ther as standalone programs or as plugins in supercollider.cpp Supercollider plugin other environments. In particular, in this pa- vst.cpp VST plugin per we describe Faust’s interfaces to Q, an in- q.cpp Q language plugin terpreted, general-purpose functional program- ming language based on term rewriting (Gr¨af, Table 1: The main architecture files available 2005), and SuperCollider (McCartney, 2002), for Faust the well-known object-oriented sound synthesis language and engine. In the following subsections we give a short and informal introduction to the language 2 Faust through two simple examples. Interested read- The programming model of Faust combines a ers can refer to (Orlarey et al., 2004) for a more functional programming approach with a block- complete description. 2.1 A simple noise generator 2.2 Invoking the compiler A Faust program describes a signal processor The role of the compiler is to translate Faust by combining primitive operations on signals programs into equivalent C++ programs. The √ (like +, −, ∗, /, , sin, cos,...) using an algebra key idea to generate efficient code is not to com- of high level composition operators (see Table pile the block diagram itself, but what it com- 2). You can think of these composition opera- putes. tors as a generalization of mathematical func- Driven by the semantic rules of the language tion composition f ◦ g. the compiler starts by propagating symbolic sig- nals into the block diagram, in order to discover f ∼ g recursive composition how each output signal can be expressed as a f , g parallel composition function of the input signals. f : g sequential composition These resulting signal expressions are then f <: g split composition simplified and normalized, and common subex- f :> g merge composition pressions are factorized. Finally these expres- sions are translated into a self contained C++ Table 2: The five high level block-diagram com- class that implements all the required computa- position operators used in Faust tion. To compile our noise generator example we A Faust program is organized as a set of use the following command : definitions with at least one for the keyword process (the equivalent of main in C). $ faust noise.dsp Our noise generator example noise.dsp only involves three very simple definitions. But it also shows some specific aspects of the language: This command generates the C++ code in Figure 1. The generated class con- random = +(12345) ~ *(1103515245); tains five methods. getNumInputs() and noise = random/2147483647.0; getNumOutputs() return the number of input process = noise * checkbox("generate"); and output signals required by our signal pro- cessor. init() initializes the internal state of The first definition describes a (pseudo) ran- the signal processor. buildUserInterface() dom number generator. Each new random num- can be seen as a list of high level commands, ber is computed by multiplying the previous one independent of any toolkit, to build the user by 1103515245 and adding to the result 12345. interface. The method compute() does the ac- The expression +(12345) denotes the op- tual signal processing. It takes 3 arguments: the eration of adding 12345 to a signal. It is number of frames to compute, the addresses of an example of a common technique in func- the input buffers and the addresses of the out- tional programming called partial application: put buffers, and computes the output samples the binary operation + is here provided with according to the input samples. only one of its arguments. In the same way The faust command accepts several options *(1103515245) denotes the multiplication of a to control the generated code. Two of them signal by 1103515245. are widely used. The option -o outputfile spec- The two resulting operations are recursively ifies the output file to be used instead of the composed using the ∼ operator. This opera- standard output. The option -a architecturefile tor connects in a feedback loop the output of defines the architecture file used to wrap the +(12345) to the input of *(1103515245) (with generate C++ class. an implicit 1-sample delay) and the output of For example the command faust -a q.cpp *(1103515245) to the input of +(12345). -o noise.cpp noise.dsp generates an exter- The second definition transforms the random nal object for the Q language, while faust -a signal into a noise signal by scaling it between jack-gtk.cpp -o noise.cpp noise.dsp gen- -1.0 and +1.0. erates a standalone Jack application using the Finally, the definition of process adds a simple GTK toolkit. user interface to control the production of the Another interesting option is -svg that gen- sound. The noise signal is multiplied by a GUI erates one or more SVG graphic files that rep- checkbox signal of value 1.0 when it is checked resent the block-diagram of the program as in and 0.0 otherwise. Figure 2. class mydsp : public dsp { private: int R0_0; float fcheckbox0; public: virtual int getNumInputs() { return 0; } virtual int getNumOutputs() { return 1; } virtual void init(int samplingFreq) { fSamplingFreq = samplingFreq; Figure 2: Graphic block-diagram of the noise R0_0 = 0; generator produced with the -svg option fcheckbox0 = 0.0; } virtual void buildUserInterface(UI* ui) { 2.3.1 The noise generator ui->openVerticalBox("faust"); We simply reuse here the noise generator of the ui->addCheckButton("generate", previous example (subsection 2.1). &fcheckbox0); ui->closeBox(); random = +(12345) ~ *(1103515245); } noise = random/2147483647.0; virtual void compute (int count, float** input, float** output) { 2.3.2 The trigger float* output0; output0 = output[0]; The trigger is used to transform the signal de- float ftemp0 = 4.656613e-10f*fcheckbox0; livered by a user interface button into a pre- for (int i=0; i<count; i++) { cisely calibrated control signal. We want this R0_0 = (12345 + (1103515245 * R0_0)); control signal to be 1.0 for a duration of exactly output0[i] = (ftemp0 * R0_0); n samples, independentely of how long the but- } } ton is pressed. }; impulse(x) = x - mem(x) : >(0.0); decay(n,x) = x - (x>0.0)/n; Figure 1: The C++ implementation code of the release(n) = + ~ decay(n); noise generator produced by the Faust compiler trigger(n) = button("play") : impulse : release(n) : >(0.0); For that purpose we first transforms the but- 2.3 The Karplus-Strong Algorithm ton signal into a 1-sample impulse correspond- ing to the raising front of the button signal.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us