Skip to content

Instantly share code, notes, and snippets.

@audionerd
Created January 6, 2009 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audionerd/43670 to your computer and use it in GitHub Desktop.
Save audionerd/43670 to your computer and use it in GitHub Desktop.
// FormantTable demo in SuperCollider
// boot the server
s.boot;
// Saw freq is controlled by mouse X position
// BBandPass filter is controlled by
// FormantTable data (frequencies, resonances, amplitudes)
(
SynthDef(\formantVoice, { arg
f = #[ 400, 750, 2400, 2600, 2900 ],
a = #[ 1, 0.28183829312645, 0.089125093813375, 0.1, 0.01 ],
q = #[ 0.1, 0.10666666666667, 0.041666666666667,
0.046153846153846, 0.041379310344828 ];
var scale = [0, 2, 4, 7, 9]; // pentatonic major
var scaleBuf = LocalBuf(scale.size, 1).set(scale);
var degree = Index.kr(scaleBuf, MouseX.kr(0, BufFrames.kr(scaleBuf)));
var vibrato = SinOsc.kr(6, mul:4);
var base = 4 * 12;
var in = Saw.ar(((degree + base).midicps + vibrato).lag(0.3));
Out.ar(0, Mix.new(BBandPass.ar(in, f, q) * a).dup);
}).send(s);
)
// create a menu of the FormantTable options for preview
(
var voices = [ \sopranoA, \sopranoE, \sopranoI, \sopranoO, \sopranoU,
\altoA, \altoE, \altoI, \altoO, \altoU, \counterTenorA, \counterTenorE,
\counterTenorI, \counterTenorO, \counterTenorU, \tenorA, \tenorE, \tenorI,
\tenorO, \tenorU, \bassA, \bassE, \bassI, \bassO, \bassU ];
// start an instance of the synth
#f, a, q = FormantTable.get( voices.first );
x = Synth(\formantVoice, [\f, f, \a, a, \q, q]);
w = SCWindow("FormantTable Browser",
Rect( SCWindow.screenBounds.width/2 - 150,
SCWindow.screenBounds.height/2 - 30,
300, 60));
SCStaticText(w, Rect(0, 5, w.view.bounds.width, 20))
.font_(Font("Helvetica", 11))
.string_("Move mouse left/right to change pitch")
.align_(\center);
SCPopUpMenu(w, w.view.bounds.insetBy(15, 20).moveBy(0, 10))
.items_(voices)
.action_({ |v|
// change the data based on user action
#f, a, q = FormantTable.get( v.item );
x.setn(\f, f);
x.setn(\a, a);
x.setn(\q, q); });
w.onClose_({ x.free });
w.front;
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment