Skip to content

Instantly share code, notes, and snippets.

@nwoeanhinnogaehr
Last active September 5, 2016 17:03
Show Gist options
  • Save nwoeanhinnogaehr/441c1654bc28824fda2478695d9211f8 to your computer and use it in GitHub Desktop.
Save nwoeanhinnogaehr/441c1654bc28824fda2478695d9211f8 to your computer and use it in GitHub Desktop.
(
s.boot;
~snd = Buffer.read(s, "/home/me/final.flac");
)
(
var b = { Buffer.alloc(s,2048,1) }.dup;
var hop = 1/4;
PyOnce("
pv = PhaseVocoder(hop)
def fn(x, midi):
idx = indices(x.shape)[1]
x = pv.forward(x)
x = pv.to_bin_offset(x)
# bin flipper
x.imag = x.imag*midi[0]
x = pv.from_bin_offset(x)
# pitch shift
x = pv.shift(x, lambda y: y*(midi[1]+1))
# frequency shift
x = pv.shift(x, lambda y: y+midi[2]*512)
# frequency warp
x = pv.shift(x, lambda y: y + (0.5+0.5*midi[4])*sin(idx*0.1+time)*32)
# frequency quantization
if midi[7] < 0.95:
r = (midi[7]+1.0001)*0.1
x.imag = round(x.imag*r)/r
x = pv.backward(x)
x = to_polar(x)
# noise
x.real = x.real**(midi[3]*0.5+0.5)
x = from_polar(x)
# quantization
r = midi[5]*8+8.01
x = round(x/r)*r
return x
", (hop:hop));
s.freeAll;
{
var freq, hasFreq;
var in2 = AudioIn.ar([1,2]); // for feedback
var in3 = PlayBuf.ar(2, ~snd.bufnum);
var in = (in2 + in3)/2;
var chain = FFT(b.collect(_.bufnum), in, hop:1/4);
Py("
out(x, fn(array(x), array(midi)))
", (x:chain, time:Sweep.kr, midi:~midi));
Out.ar(0, IFFT(chain));
}.play(s)
)
(
~midi = Buffer.alloc(s,10);
MIDIIn.connectAll;
MIDIIn.control = { |src, chan, num, val|
var offset = num-1;
var x = val/127.0*2-1;
if ((x > -0.02) && (x < 0.02), {
x = 0
}, {
});
~midi.set(offset, x);
[chan, num, x].postln;
};
MIDIIn.bend = { |src, chan, bend|
~midi.set(8, bend/16383.0*2-1);
};
MIDIIn.noteOn = {
PyOnce("
pv = PhaseVocoder(hop)
");
};
)
(
c = Bus.control(s, 1);
{PlayBuf.kr(1, ~midi.bufnum, loop:1)}.play(s, c.index);
p = c.scope(bufsize:256)
)
s.freqscope
s.scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment