FaustWorkshop2014-CostaRica

From CCRMA Wiki
Jump to: navigation, search

For any question/comment, please contact Romain Michon (rmichon_at_ccrma_dot_stanford_dot_edu).

Day 1

Simple Gain Controller

import("filter.lib");

process = *(hslider("gain",0.5,0,1,0.01)) : smooth(0.999);

Simple Sine Oscillator Synthesizer

import("music.lib");
import("filter.lib");

g = hslider("myParameter",0,0,1,0.01);
freq = hslider("frequency",440,50,1000,0.1);

myOsc(frequency,gain) = osc(frequency)*(smoothGain) 
with{
        // the smooth(0.999) function interpolates the different values of gain so that it doesn't click
	smoothGain = gain : smooth(0.999);
};

process = myOsc(freq,g) ;

Working with Signals

process = _ <: _,_,_,_ :> _;

is the same as:

process = _ <: _+_+_+_;

Simple Panner

import("filter.lib");

// the metadata "[style:knob]" turns the horizontal slider into a knob
pan = hslider("pan [style:knob]",0.5,0,1,0.01) : smooth(0.999);

process = _ <: *(pan),*(1-pan);

Additive Synthesizer

import("music.lib");
import("effect.lib");

gain = hslider("gain",0,0,1,0.01) : smooth(0.999);
freq = hslider("freq",440,50,1000,0.1) : smooth(0.999);
// the smooth function can be used as a simple envelope generator for gate
gate = button("gate") : smooth(0.999);

process = osc(freq),osc(freq*2),osc(freq*3) :> *(gain)*gate <: _,_;

The last line of the code can be replaced by:

process = par(i,3,osc(freq*(i+1))) :> *(gain)*gate <: _,_;

or

process = sum(i,3,osc(freq*(i+1))) : *(gain)*gate <: _,_;

Wave Shape Synthesis

saw1(freq) // Sawtooth wave 
lf_imptrain(freq) // Impulse train
lf_squarewave(freq) // Square wave

Day 2

Tremolo and Ring Modulation

https://ccrma.stanford.edu/~jos/rbeats/Sinusoidal_Amplitude_Modulation_AM.html

import("filter.lib");

freq = hslider("freq",2,1,500,0.01);
gain = hslider("gain",1,0,1,0.01) : smooth(0.999);
depth = hslider("depth",0,0,1,0.01) : smooth(0.999);

ringMod = *(1-(depth*osc(freq)/2 + 0.5));

process = ringMod*gain <: _,_;

Stereo Ring Modulator

import("filter.lib");

freq = hslider("freq",2,1,500,0.01);
gain = hslider("gain",1,0,1,0.01) : smooth(0.999);
depth = hslider("depth",0,0,1,0.01) : smooth(0.999);

pan = 1-(depth*osc(freq)/2 + 0.5);
stereoRingMod = _ <: *(pan),*(1-pan); 

process = stereoRingMod : *(gain), *(gain);

Delay

One sample delay:

_';

N samples delay:

_@N;

Fractional delay:

fdelay1(MaxDelayLength, delayLength)

The Simplest Lowpass/Highpass Filter

https://ccrma.stanford.edu/~jos/filters/One_Zero.html

import("filter.lib");
import("music.lib");

b1 = hslider("feedforward",0,-1,1,0.01) : smooth(0.999);
filter = _ <: _+(_' : *(b1)) : *(0.5); 
process = noise : filter;

Feedforward Comb Filter

https://ccrma.stanford.edu/~jos/pasp/Feedforward_Comb_Filters.html

import("filter.lib");
import("music.lib");

b = hslider("feedforward",0,-1,1,0.01) : smooth(0.999);
del = hslider("del",1,1,100,1);
filter = _ <: _+(_@del : *(b)) : *(0.5);
process = noise : filter;

Flanger

https://ccrma.stanford.edu/~jos/pasp/Flanging.html

Workshop Version
import("music.lib");
import("filter.lib");

flangeDelay = hslider("flangeDelay",0.05,0.001,1,0.001)*SR*0.001;
depth = hslider("depth",0.5,-1,1,0.01) : smooth(0.999);
speed = hslider("speed",0.5,0.1,20,0.01);
gain = hslider("gain",0.8,0,1,0.01) : smooth(0.999);

myFlanger = _ <: _,fdelay1(1024,delayLength)*depth : + : *(0.5)
with{
	delayLength = flangeDelay*(1 + osc(speed))/2;
};

process = myFlanger*gain;

Day 3

Echo

import("music.lib");
import("filter.lib");
delayDuration = hslider("duration",1,0.01,1,0.01); // in seconds
feedback = hslider("feedback",0,0,0.99,0.01) : smooth(0.999);
delayLength = SR*delayDuration;
process = (+ : fdelay(SR,delayLength)) ~ *(feedback);

Feedback Comb Filter

https://ccrma.stanford.edu/~jos/pasp/Feedback_Comb_Filters.html

import("music.lib");
import("filter.lib");
delayLength = hslider("delayLength",1,0,1000,1); // in samples
feedback = hslider("feedback",0,0,0.99,0.01) : smooth(0.999);
process = (+ : fdelay(1024,delayLength)) ~ *(-feedback);

Karplus Strong

A simple string physical model. An average filter is used to attenuate high frequencies faster than low frequencies.

https://ccrma.stanford.edu/~jos/pasp/Karplus_Strong_Algorithm.html

import("filter.lib");
import("music.lib");

freq = hslider("freq",440,50,1000,0.1);
feedback = hslider("feedback",0,0,0.999,0.001);

string = + ~ (fdelay(1024,delayLength) : *(feedback) : filter)
with{
	delayLength = SR/freq;
	filter = _ <: (_+_')/2;
};

impulse = button("gate") <: _,_' : - : >(0);

process = impulse : string;

Resonant Bandpass Filter

import("filter.lib");

ctFreq = hslider("ctFreq",400,50,2000,0.01) : smooth(0.999);
BW = hslider("Bandwidth",100,1,1000,1) : smooth(0.999);
Q = ctFreq/BW;

process = noise : resonbp(ctFreq,Q,1);

Parametric Equalizer

Workshop Version
import("filter.lib");
import("effect.lib");

bandsNumber = 10;
highestBand = 15000;

oneBand(cnt) = vgroup("Band %cnt",peak_eq(Lfx,fx,B)) 
with{
	Lfx = vslider("Level",0,-60,10,0.1);
	fx = nentry("Freq",highestBand*(cnt+1)/bandsNumber,40,highestBand,0.1);
	B = hslider("Bdwth [style: knob]",100,1,5000,0.1);
};

bp = checkbox("Bypass");

process = hgroup("Parametric Equalizer",bypass1(bp,seq(i,bandsNumber,oneBand(i))));
filter.lib Version
import("filter.lib");

process = _ : parametric_eq_demo: _;

Readings

Look at 1, 2 and 3 in the online books section of https://ccrma.stanford.edu/~jos/.

Day 4

Cubic Distortion

https://ccrma.stanford.edu/realsimple/faust_strings/Cubic_Nonlinear_Distortion.html

Workshop Version
import("filter.lib");

drive = hslider("Drive",0,0,1,0.01) : smooth(tau2pole(0.1));
offset = hslider("Offset",0,-1,1,0.01) : smooth(0.999);

gain = pow(10.0,2*drive);
clip(lo,hi) = min(hi) : max(lo);
cubic = _ <: _ - _*_*_/3;

process = *(gain) : +(offset) : clip(-1,1) : cubic : dcblocker;
effect.lib Version
import("effect.lib");

process = _ : cubicnl_demo : _;

Vocoder

Workshop Version
import("filter.lib");
import("effect.lib");
import("oscillator.lib");

oneVocoderBand(band,nBands,bwRatio,bandGain) = resonbp(bandFreq,bandQ,bandGain)
with{
	bandFreq = 25*pow(2,(band+1)*(9/nBands));
	BW = (bandFreq - 25*pow(2,band*9/nBands))*bwRatio;
	bandQ = bandFreq/BW;
};

vocoder(nBands,att,rel,bwRatio,source,excitation) = source <: par(i,nBands,oneVocoderBand(i,nBands,bwRatio,1) : amp_follower_ud(att,rel) : _,excitation : oneVocoderBand(i,nBands,bwRatio)) :> _;

vocoder_demo = _,lf_imptrain(freq)*gain : vocoder(bands,att,rel,bwRatio)
with{
	bands = 64;
	vocoderGroup(x) = vgroup("Vocoder Params",x);
	att = vocoderGroup(hslider("[0]Attack [style: knob]",5,0.1,100,0.1)*0.001);
	rel = vocoderGroup(hslider("[1]Release [style: knob]",5,0.1,100,0.1)*0.001);
	bwRatio = vocoderGroup(hslider("[2]BW [style: knob]",0.5,0.1,2,0.001));
	excitGroup(x) = vgroup("Excitation Params",x);
	freq = excitGroup(hslider("Freq [style: knob]",330,50,2000,0.1));
	gain = excitGroup(vslider("Gain",0.5,0,1,0.01) : smooth(0.999));
};

process = hgroup("Vocoder",vocoder_demo);
effect.lib Version
import("effect.lib");

process = _ : vocoder_demo : _,_;

Day 5

Schroeder Reverberator: Freeverb

https://ccrma.stanford.edu/~jos/pasp/Freeverb.html

Workshop Version
import("effect.lib");

mono_reverb(fb1,fb2,damp,spread) = _ <: par(i,8,lpcf(combTuningL(i)+spread,fb1,damp)) :> seq(i,4,allpass_comb(1024, allpassTuningL(i)+spread,-fb2))
with{
	origSR = 44100;
	combTuningL(0) = 1116*SR/origSR : int;
	combTuningL(1) = 1188*SR/origSR : int;
	combTuningL(2) = 1277*SR/origSR : int;
	combTuningL(3) = 1356*SR/origSR : int;
	combTuningL(4) = 1422*SR/origSR : int;
	combTuningL(5) = 1491*SR/origSR : int;
	combTuningL(6) = 1557*SR/origSR : int;
	combTuningL(7) = 1617*SR/origSR : int;
	
	allpassTuningL(0) = 556*SR/origSR : int;
	allpassTuningL(1) = 441*SR/origSR : int;
	allpassTuningL(2) = 341*SR/origSR : int;
	allpassTuningL(3) = 225*SR/origSR : int;
	lpcf(dt,fb,damp) = (+ : @(dt)) ~ (*(1-damp) : (+ ~ *(damp)) : *(fb));
};


stereo_reverb(fb1,fb2,damp,spread) = + <: mono_reverb(fb1,fb2,damp,0), mono_reverb(fb1,fb2,damp,spread);

reverb_demo = _,_ <: (*(g),*(g) : stereo_reverb(combfeed,allpassfeed,damping,spatSpread)), *(1-g), *(1-g) :> _,_
with{
	scaleroom = 0.28;
	offsetroom = 0.7;
	allpassfeed = 0.5;
	scaledamp = 0.4;
	fixedgain = 0.1;
	origSR = 44100;
	
	damping = hslider("Damp",0.5,0,1,0.001)*scaledamp*SR/origSR;
	combfeed = hslider("RoomSize", 0.5,0,1,0.001)*scaleroom*SR/origSR + offsetroom;
	spatSpread = hslider("StereoSpread",0.5,0,1,0.01)*46*SR/origSR : int;
	g = hslider("DryWet",0.3333,0,1,0.001);
};

process = reverb_demo;
effect.lib Version
import("effect.lib");

process = _,_ : freeverb_demo : _,_;

Compressor

https://ccrma.stanford.edu/~jos/fp/Nonlinear_Filter_Example_Dynamic.html

Workshop Version
import("effect.lib");

compressor(ratio,thresh,att,rel,kneesAtt,gain) = _ <: *(amp_follower_ud(att,rel) : linear2db : outminusindb(ratio,thresh) : kneesmooth(kneesAtt) : visualizer : db2linear) : *(gain)
with{
	outminusindb(ratio,thresh,level) = max(level-thresh,0.0)*(1.0/float(ratio)-1.0);
	kneesmooth(att) = smooth(tau2pole(att));
	visualizer = hbargraph("Compressor Gain [unit:dB]",-60,10);
};

compressorDemo = compressor(ratio,threshold,attack,release,kneesAttack,makeUpGain)
with{
	ratio = hslider("[0]Ratio",4,1,20,0.1);
	threshold = hslider("[1]Threshold [unit:dB]",-30,-70,10,0.1);
	attack = hslider("[2]Attack",50,0,500,0.1)*0.001;
	release = hslider("[3]Release",100,0,800,0.1)*0.001;
	kneesAttack = hslider("[4]KneesAttack",25,0,250,0.1)*0.001;
	makeUpGain = hslider("[5]MakeUpGain [unit:dB]",0,-70,10,0.1) : db2linear;
};

switch = checkbox("Bypass");

process = _ <: (*(1-switch) : compressorDemo),*(switch) : +;
effect.lib Version
import("effect.lib");

process = _,_ : compressor_demo : _,_;