Pure Data: Installing Externals with Deken

The basic install of PD is referred to as Vanilla. Although many things are possible with this plain version, some additional libraries are very helpful and there is a handful which can be considered standard.

Find and Install Extensions

PD comes with Deken, a builtin tool for installing external libraries. Deken can be opened from the menu of the PD GUI. On Linux installs it is located under Help->Find Externals. Deken lets you search for externals by name. The best match is usually found at the top of the results. cyclone is an example for a library with many useful objects:

/images/basics/pd-deken-1.png

Deken lets you select where to install externals in its Preferences menu. Everything will be located in the specified directory afterwards.


Add Libraries to Search Paths

Once installed, it may be necessary to add the individual libraries to the search paths. This is done in an extra step. On Linux installs, this can be found under Edit->Preferences->Path:

/images/basics/pd-deken-2.png

Digital Waveguides: Ideal String without Losses

Ideal String with two Delay Lines

Based on the previously introduced discrete solution for the wave equation, an ideal, lossless string can be implemented using two delay lines with direct coupling. The left-traveling and right-traveling wave are connected end-to-end. Output samples of each delay line are direcly inserted to the input of the counterpart:


The Excitation Function

The waveguides can be initiated - or excited - with any arbitrary function. This may vary, depending on the excitation principle of the instrument to be modeled. For a plucked string, the excitation can be a triangular function with a maximum at the plucking point $p$. Both waveguides (left/right travelling) are initiated with the same function:

$$y[i] = \begin{cases} \frac{i}{p} & \mbox{for } i \leq p \\ 1-\frac{i-p}{N-p} & \mbox{for } i > p \\ \end{cases}$$
    

Oscillation

When both waveguides are shifted by one sample each $\frac{1}{f_s}$ seconds, the ideal string is oscillating with a frequency of $f_0 = \frac{f_s}{N}$. It will oscillate continuously. In fact it is a superimposition of two oscillators with the waveform defined by the excitation function.



Once Loop Reflect

Faust: Delay

Unit Delay

A unit sample delay can be used with the ' operator. This very basic operation is used in standard building blocks like integrators or digital filters.


Integer Delay

The integer delay can be controlled during processing. This example uses a horizontal slider for controlling the delay. Original and delayed signal are sent to the left and right output for testing the effect.

Load the example in the Faust online IDE for a quick start:

text


import("stdfaust.lib");

// get the sample rate
SR    = fconstant(int fSamplingFreq, <math.h>);
delay = hslider("Delay[samples]",0, 0, 10000, 1);

sig = os.lf_saw(1);

process =  sig <: _,(_ , delay : @);

Fractional Delay

Integer delays can only shift the signal by multiples of the inverse sampling frequency. Fractional delays can also shift the signal by non-integer values. The Faust delay library contains multiple implementations.

FM Synthesis: Formula & Spectrum

FM Formula

Frequency modulation with two sinusoidal oscillators can be written as follows:

$$ x(t) = A \sin(\omega_\alpha t + I \sin(\omega_\beta t) ) $$

Modulation Index:

$$I = \frac{\Delta f}{\Delta f_m}$$

Spectrum of Frequency Modulation

Compared to amplitude modulation techniques, FM generates more spectral components, which can be illustrated when calculating the Fourier transform of the FM formula.

Based on the FM formula, the spectrum can be calculated using trigonometric identities:

$$ x(t) = \cos(\omega_\alpha t + I \sin(\omega_\beta t) ) $$

$\text{with:} \cos(a+b) = \cos(a) \cos(b) - \sin(a) \sin(b)$

$$ x(t) = \cos(\omega_\alpha t) \cos(I \sin(\omega_\beta t)) - \sin(\omega_\alpha t) \sin(I \sin(\omega_\beta t)) $$

$\text{with:} \cos(a) \cos(b) = \frac{1}{2} \left( \cos(a-b) + \cos(a+b) \right)$

$\text{and:} \sin(a) \sin(b) = \frac{1}{2} \left( \cos(a-b) - \cos(a+b) \right)$

$$ \begin{eqnarray} &=& \frac{1}{2} ( \sin(\omega_\alpha t + I \sin(\omega_\alpha t)) \\ &&+ \sin(\omega_\alpha t - I \sin(\omega_\alpha t))\\ &&+ \sin(\omega_\alpha t + I \sin(\omega_\alpha t)) \\ &&+ \sin( I \sin(\omega_\alpha t) - \omega_\alpha t) ) \end{eqnarray} $$

Bessel functions

The above equation can be expressed through Bessel functions:

$$ \begin{eqnarray} \sin(\omega_\alpha t + I \sin(\omega_\alpha t)) &=& J_0(I) \cos(\omega_\alpha) \\ % && + J_1(I) \cos(\omega_\alpha - \omega_\beta)t - \cos(\omega_\alpha + \omega_\beta)t \\ % && - J_2(I) \cos(\omega_\alpha - 2 \omega_\beta)t + \cos(\omega_\alpha + 2 \omega_\beta)t \\ % && + ... \end{eqnarray} $$

The spectrum of FM signals thus has an infinite number of sidebands which are increased in energy for high modulation indices.


Harmonic vs Inharmonic

Depending on the ratio between modulator and carrier, the FM spectrum has different properties. In the formula for the FM sidebands is is obvious that for integer ratios between carrier to modulator, all sidebands are integer multiples of the fundamental frequency.

Additive & Spectral: Spectral Modeling

McAulay/Quatieri

Sinusoidal modeling can be considered a higher level algorithm for the additive synthesis of harmonic sounds. It has first been used in speech processing by McAulay, R. and Quatieri (1986). For low framerates they proposed a time-domain method for partial synthesis with original phases of the partials.

/images/Sound_Synthesis/spectral_modeling/quatieri_system.jpg

R. McAulay and T. Quatieri (1986)


SMS

The above presented sinusoidal modeling approach captures only the harmonic portion of a sound. With the Sinusoids plus Noise model (SMS), Serra and Smith (1990) introduced the Deterministic + Stochastic model for spectral modeling, in order to model components in the signal which are not captured by partial tracking. A sound is therefor modeled as a combination of a dererministic component - the sinusoids - and a stochasctic component:

\begin{equation*} x = x_{DET} + x_{STO} \end{equation*}
/images/Sound_Synthesis/spectral_modeling/sines_plus_noise_block.jpg

Deterministic + Stochastic model (Serra and Smith, 1990)

Violin Example

The following example shows the sines + noise decomposition for a single violin sound. The original recording was made in an anechoic chamber:

After partial tracking, the deterministic component can be re-synthesized using an oscillator bank. It features the strings oscillation, in this case with original phases. For a bowed string instrument like the violin, the deterministic model alone can deliver plausible results:

The residual signal still carries some parts of the deterministic part, when calculated with simple subtraction. Most of the residual's energy is caused by the bow friction:


Sines + Transients + Noise

Even the harmonic and noise model can not capture all components of musical sounds. The third - and in this line last - signal component to be included are the transients.

/images/Sound_Synthesis/spectral_modeling/sin-trans-noise.png

Sines + Transients + Noise (Levine and Smith, 1998)


References

2007

  • Arturo Camacho. Swipe: A Sawtooth Waveform Inspired Pitch Estimator for Speech and Music. PhD thesis, University of Florida, Gainesville, FL, USA, 2007.
    [details] [BibTeX▼]

2005

2002

  • Alain de Cheveigné and Hideki Kawahara. YIN, a Fundamental Frequency Estimator for Speech and Music. The Journal of the Acoustical Society of America, 111(4):1917–1930, 2002.
    [details] [BibTeX▼]

1998

1990

1986

  • R. McAulay and T. Quatieri. Speech analysis/Synthesis based on a sinusoidal representation. Acoustics, Speech and Signal Processing, IEEE Transactions on, 34(4):744–754, 1986.
    [details] [BibTeX▼]
  • T Quatieri and Rl McAulay. Speech transformations based on a sinusoidal representation. IEEE Transactions on Acoustics, Speech, and Signal Processing, 34(6):1449–1464, 1986.
    [details] [BibTeX▼]

Faust: OSC Control

For standalone standalone and embedded plugins, OSC control can be a useful option. Faust compiles with OSC functionality with the -osc flag:

$ faust2jaqt -osc sine.dsp

Starting the program in the command line gives information on the standard faust OSC ports:

$ ./sine
Faust OSC version 1.22 - 'sine' is running on UDP ports 5510, 5511, 5512, sending on localhost

The running program can now be controlled through any OSC sender, using the proper IP address, port and paths:

/images/Sound_Synthesis/sine_osc_example.png

Max for Live: Light Dependent Resistor

This example shows how to send serial data from a single sensor from an Arduino to Max for Live. The stream of data will be used to control the cutoff frequency of a subtractive synth patch.


Breadboard Circuit

The breadboard circuit for this example is the same used in the first Arduino-Sensor-Circuit:

/images/basics/ldr_input_fritzing.png

Arduino Code

The same Arduino code can be used to send data to Max or Max for Live:

int analogInput = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{

  float value = analogRead(analogInput);

  Serial.println(value);

  delay(5);
}

Max 4 Live Patch

The following patch is a Max Instrument` which has two audio outputs. It can be used like any other Live synthesizer.

No additional objects or packages are required for getting the Arduino's data to Max or Max for Live via USB serial. Receiving the data sent from the above Arduino code is managed with the serial object in Max. It needs the same baud rate as the sender (9600) as second argument and the Arduino's serial port ID as first argument. Clicking print gives the list of serial devices in the max console. Enter the result into the serial object (in this case 'd' for 'usbmodem').

Once the proper id is set, the metro object can be started using the toggle switch. Every ten milliseconds, data is read from the serial port. The following objects unpack and format the stream and turn it into an integer. The resulting values are just scaled and used for the cutoff frequency of two parallel low pass filters.

/images/basics/arduino/max4live_ldr.png

LDR controlled subtractive synth in the Max device editor.


Additional Resources

This example works with the same approach.

Faust for Web Audio

External Resources

Read the slides by Myles Borins for an introduction about Faust with Web Audio.

The minimal examples by Yosuke Torii are a good way to get started.

Self-Contained HTML

Using the faust2webaudiowasm it is pretty easy to create self-contained HTML instruments. They can run within any webserver.

White Tone Example

The Sine Example

If we want to use Faust-built DSP elements in a more flexible way, there is another way which delivers

$ faust2wasm sine.dsp

Karplus-Strong Example