{
   "labels" : [
      "formant synthesis"
   ],
   "code" : "////////////////////////////////////////////\r\n// Silly formant synthesis example.\r\n// Using Pmono or Pbind to create a voice.\r\n// SynthDef is hardwired to bass formants.\r\n\r\n// Evaluate SynthDef first, then scroll down for examples\r\n\r\n(\r\n// SynthDef\r\nSynthDef(\"sillyVoice\", { arg\r\n\tfreq = 220,\r\n\tamp = 0.5,\r\n\tvibratoSpeed = 6,\r\n\tvibratoDepth = 4,\r\n\tvowel = 0,\r\n\tatt = 0.01,\r\n\trel = 0.1,\r\n\tpos = 0,\r\n\tgate = 1;\r\n\r\n\tvar in, vibrato, above, below, env, va, ve, vi, vo, vu, snd;\r\n\r\n\t// calculate vibrato \r\n\t// vibratoDepth is number of semitones to go up and down\r\n\tabove = (freq.cpsmidi + vibratoDepth).midicps - freq;\r\n\tbelow = (freq.cpsmidi - vibratoDepth).midicps - freq;\r\n\tvibrato = SinOsc.kr(vibratoSpeed).range(below, above); \r\n\t// this is the basic sound source\r\n\tin = Saw.ar(Lag.kr(freq) + vibrato);\r\n\t// amplitude envelope\r\n\tenv = Env.asr(att, amp, rel).kr(doneAction: 2, gate: gate);\r\n\r\n\tva = BBandPass.ar(\r\n\t\tin: in,\r\n\t\tfreq: [ 600, 1040, 2250, 2450, 2750 ],\r\n\t\tbw: [ 0.1, 0.0673, 0.0488, 0.0489, 0.0472 ],\r\n\t\tmul: [ 1, 0.4466, 0.3548, 0.3548, 0.1 ]);\r\n\r\n\tve = BBandPass.ar(\r\n\t\tin: in,\r\n\t\tfreq: [ 400, 1620, 2400, 2800, 3100 ] ,\r\n\t\tbw: [ 0.1, 0.0494, 0.0417, 0.0429, 0.0387 ],\r\n\t\tmul: [ 1, 0.2512, 0.3548, 0.2512, 0.1259 ]);\r\n\r\n\tvi = BBandPass.ar(\r\n\t\tin: in,\r\n\t\tfreq: [ 250, 1750, 2600, 3050, 3340 ] ,\r\n\t\tbw: [ 0.24, 0.0514, 0.0385, 0.0393, 0.0359 ],\r\n\t\tmul: [ 1, 0.0316, 0.1585, 0.0794, 0.0398 ] );\r\n\r\n\tvo = BBandPass.ar(\r\n\t\tin: in,\r\n\t\tfreq:[ 400, 750, 2400, 2600, 2900 ] ,\r\n\t\tbw: [ 0.1, 0.1067, 0.0417, 0.0462, 0.0414 ],\r\n\t\tmul: [ 1, 0.2818, 0.0891, 0.1, 0.01 ]);\r\n\r\n\tvu = BBandPass.ar(\r\n\t\tin: in,\r\n\t\tfreq: [ 350, 600, 2400, 2675, 2950 ],\r\n\t\tbw: [ 0.1143, 0.1333, 0.0417, 0.0449, 0.0407 ],\r\n\t\tmul: [ 1, 0.1, 0.0251, 0.0398, 0.0158 ]);\r\n\r\n\tsnd = SelectX.ar(Lag.kr(vowel, 0.3), [va, ve, vi, vo, vu]);\r\n\tsnd = Pan2.ar(Mix(snd), pos);\r\n\tOut.ar(0, snd * env * 2);\r\n}).add;\r\n)\r\n\r\n// Play around with these examples/\r\n// Vowels a e i o u correspond to number 0 1 2 3 4\r\n\r\n// Example 1\r\n(\r\nPbind(\r\n\t\\instrument, \"sillyVoice\",\r\n\t\\note, Pseq([0, -5, -3, -8, -7, 0, -7, -5], inf),\r\n\t\\ctranspose, -12,\r\n\t\\dur, 1,\r\n\t\\amp, 1,\r\n\t\\vibratoSpeed, 6,\r\n\t\\vibratoDepth, 1, // in semitones\r\n\t\\vowel, Pseq([0, 1, 2, 3, 4], inf),\r\n\t\\legato, 1,\r\n\t\\att, 0.1,\r\n\t\\rel, 0.1,\r\n\t\\pos, Pwhite(-1, 1.0)\r\n).play;\r\n)\r\n\r\n\r\n// Example 2\r\n(\r\nPbind(\r\n\t\\instrument, \"sillyVoice\",\r\n\t\\note, Prand([0, 5, 7, 9, -11, -7], inf),\r\n\t\\ctranspose, -14,\r\n\t\\dur, Pwhite(0.61, 1.7),\r\n\t\\amp, 1,\r\n\t\\vibratoSpeed, Pwhite(6,8),\r\n\t\\vibratoDepth, Pwhite(0.5, 1.5),\r\n\t\\vowel, Pwrand([0, 1, 3], [0.8, 0.1, 0.1], inf),\r\n\t\\legato, 2, // notes overlap\r\n\t\\att, 1.1, // softer attack\r\n\t\\rel, 2.5\r\n).play;\r\n)\r\n\r\n// Example 3: using Pmono\r\n(\r\nPmono(\r\n\t\"sillyVoice\",\r\n\t\\note, Pseq([-5, -3, -1, 0], inf),\r\n\t\\ctranspose, -14,\r\n\t\\dur, Pwhite(0.5, 1.0),\r\n\t\\amp, 1,\r\n\t\\vibratoSpeed, Pwhite(6,7),\r\n\t\\vibratoDepth, 1,\r\n\t\\vowel, Prand([0, 1, 2, 3, 4], inf),\r\n\t\\lag, 0.3\r\n).play;\r\n)",
   "is_private" : null,
   "id" : "1-4Vm",
   "author" : "Bruno Ruviaro",
   "name" : "Silly Voice",
   "description" : "",
   "ancestor_list" : []
}
