File: karplus.syn

package info (click to toggle)
faust 2.14.4~repack2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 276,136 kB
  • sloc: cpp: 231,578; ansic: 15,403; sh: 10,871; java: 6,917; objc: 4,085; makefile: 3,002; cs: 1,077; ruby: 951; python: 885; xml: 550; yacc: 516; lex: 233; lisp: 201
file content (49 lines) | stat: -rw-r--r-- 1,435 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

declare name "karplus -- Karplus-Strong string synth";
declare author "Yann Orlarey";
declare version "1.0";

import("music.lib");

// control variables

// master volume and pan
vol	= hslider("vol", -10, -96, 96, 0.1);	// dB
pan	= hslider("pan", 0, -1, 1, 0.01);	// %

// excitator and resonator parameters
size	= hslider("samples", 512, 1, 1024, 1);	// #samples
dtime	= hslider("decay time", 4, 0, 10, 0.01);// -60db decay time

// voice parameters
freq	= nentry("freq", 440, 20, 20000, 1);	// Hz
gain	= nentry("gain", 1, 0, 10, 0.01);	// %
gate	= button("gate");			// 0/1
bend	= hslider("pitch bend", 0, -2, 2, 0.01);// semitones

/* The excitator: */

upfront(x) 	= (x-x') > 0.0;
decay(n,x)	= x - (x>0)/n;
release(n)	= + ~ decay(n);
trigger(n) 	= upfront : release(n) : >(0.0) : +(leak);
leak		= 1.0/65536.0; // avoid denormals on Pentium
excitator	= trigger(size);

/* The resonator: */

average(x)	= (x+x')/2;
att(d,t)	= 1-1/pow(db2linear(60), d/(SR*t));
comb(d,a)	= (+ : fdelay(4096, d-1.5)) ~ (average : *(1.0-a));
resonator(d)	= comb(d,att(d,dtime));

/* DC blocker (see http://ccrma.stanford.edu/~jos/filters/DC_Blocker.html): */

dcblocker(x)	= (x-x') : (+ ~ *(0.995));

/* Karplus-Strong string synthesizer: */

process	= vgroup("1-excitator", noise*gain : *(gate : excitator))
	: vgroup("2-resonator", resonator(SR/(freq*pow(2,bend/12))))
	: dcblocker
        : vgroup("3-master", *(db2linear(vol)) : panner((pan+1)/2));