Skip to content

Instantly share code, notes, and snippets.

@catfact
Last active September 12, 2020 18:40
Show Gist options
  • Save catfact/288693fa47cbd5d15f04c6452f42a7c7 to your computer and use it in GitHub Desktop.
Save catfact/288693fa47cbd5d15f04c6452f42a7c7 to your computer and use it in GitHub Desktop.
bark scaled multiband envelope follower and freaky vocodder
Routine {
s = Server.default;
s.waitForBoot;
// bark band table.
// each entry: [bark number, cutoff, center, bandwidth]
~bark = [
[ 1, 60, 100, 80 ],
[ 2, 150, 200, 100 ],
[ 3, 250, 300, 100 ],
[ 4, 350, 400, 100 ],
[ 5, 450, 510, 110 ],
[ 6, 570, 630, 120 ],
[ 7, 700, 770, 140 ],
[ 8, 840, 920, 150 ],
[ 9, 1000, 1080, 160 ],
[ 10, 1170, 1270, 190 ],
[ 11, 1370, 1480, 210 ],
[ 12, 1600, 1720, 240 ],
[ 13, 1850, 2000, 280 ],
[ 14, 2150, 2320, 320 ],
[ 15, 2500, 2700, 380 ],
[ 16, 2900, 3150, 450 ],
[ 17, 3400, 3700, 550 ],
[ 18, 4000, 4400, 700 ],
[ 19, 4800, 5300, 900 ],
[ 20, 5800, 6400, 1100 ],
[ 21, 7000, 7700, 1300 ],
[ 22, 8500, 9500, 1800 ],
[ 23, 10500, 12000, 2500 ],
[ 24, 13500, 15500, 3500]
];
n = ~bark.size;
~band_signal_bus = Bus.audio(s, n);
~band_hz_bus = Bus.control(s, n);
~band_amp_bus = Bus.control(s, n);
s.sync;
~band_ana_syn = ~bark.collect({
arg band, i;
var fc = band[2];
var bw = band[3];
var snd_idx = ~band_signal_bus.index + i;
var amp_idx = ~band_amp_bus.index + i;
var hz_idx = ~band_hz_bus.index + i;
{
// 2nd-pole butterworth with appropriate RQ and center freq
var snd, hz, clar;
snd = BPF.ar(SoundIn.ar(0), fc, bw/fc);
#hz, clar = Pitch.kr(snd, minFreq:band[1], maxFreq:band[2] + (band[3]/2));
Out.ar(snd_idx, snd);
Out.kr(amp_idx, PeakFollower.kr(snd, 0.6));
Out.kr(hz_idx, hz);
}.play(s);
});
{ ~band_amp_bus.scope }.defer;
~sines = ~bark.collect({|band, i| {
var hz, amp;
hz = In.kr(~band_hz_bus.index + i);
amp = In.kr(~band_amp_bus.index + i);
amp = amp * (amp > 0.02);
amp = LagUD.ar(K2A.ar(amp), 0.1, 0.5);
Out.ar(0, Pan2.ar(SinOsc.ar(hz, 0, amp*0.5), i.linlin(0, 23, -0.8, 0.8)));
}.play });
}.play;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment