{
   "ancestor_list" : [],
   "description" : "A function to get the n loudest partials, or all partials louder than a threshold, for a formant filter using Klank and Vowel",
   "author" : "julian.rohrhuber",
   "name" : "Formant filter using the Vowel Quark",
   "code" : "// a function to get the n loudest partials for a formant filter using Klank and Vowel\r\n\r\n// needs the Vowel quark:\r\n\r\n\"Vowel\".include;\r\n\r\n// tenor, for instance\r\na = \"aeiou\".as(Array).collect { |x| Vowel(x.asSymbol, \\tenor) };\r\n\r\n// function for threshold\r\n(\r\nf = { |vowel, thresh = 0.3|\r\n\tvar freqs = (40..10000).collect { |x| x + 0.5.rand2 };\r\n\tvar result = [];\r\n\tfreqs.do { |freq|\r\n\t\tvar amp = vowel.ampAt(freq);\r\n\t\tif(amp > thresh) {\r\n\t\t\tresult = result.add([freq, amp])\r\n\t\t}\r\n\t};\r\n\tresult.size.postln;\r\n\tresult.flop\r\n};\r\n)\r\n// or alternatively, for number of partials\r\n(\r\ng = { |vowel, numPartials = 30|\r\n\tvar freqs = (40..10000).collect { |x| x + 0.5.rand2 };\r\n\tvar result = [];\r\n\tfreqs.do { |freq|\r\n\t\tvar amp = vowel.ampAt(freq);\r\n\t\tresult = result.add([freq, amp])\r\n\t};\r\n\r\n\tresult = result.sort { |a, b| a[1] > b[1] }.keep(numPartials);\r\n\r\n\tresult.flop\r\n};\r\n)\r\n\r\n// some examples\r\n\r\nNdef(\\vow, { Klank.ar(`(f.(a[0], 0.7) ++ 0.2), Impulse.ar(MouseX.kr(1, 1000, 1))) * 0.001 }).play;\r\nNdef(\\vow, { Klank.ar(`(f.(a[0], 0.3) ++ 0.2), Impulse.ar(MouseX.kr(1, 1000, 1))) * 0.001 }).play;\r\nNdef(\\vow, { Klank.ar(`(f.(a[2], 0.7) ++ 0.2), Impulse.ar(MouseX.kr(1, 1000, 1))) * 0.001 }).play;\r\nNdef(\\vow, { Klank.ar(`(f.(a[2], 0.3) ++ 0.2), Impulse.ar(MouseX.kr(1, 1000, 1))) * 0.001 }).play;\r\n\r\n// use for instance to get the 42 loudest partials, for each vowel\r\nz = a.collect { |x| g.(x, 42) }.flopDeep(1);",
   "id" : "1-504",
   "is_private" : null,
   "labels" : [
      "filter",
      "vowel"
   ]
}
