Skip to content

Instantly share code, notes, and snippets.

@catfact
Last active September 18, 2016 20:55
Show Gist options
  • Save catfact/241b31c0b7ae7463b261e0fc0a995d4f to your computer and use it in GitHub Desktop.
Save catfact/241b31c0b7ae7463b261e0fc0a995d4f to your computer and use it in GitHub Desktop.
// testing audible differences between VOsc.ar and Osc.ar under frequency/phase modulation
// press '1' to hear VOsc, '2' to hear Osc
// drag mouse on window to change mod hz and depth
// VOsc is set to interpolate between identical sine buffers
Routine {
SynthDef.new(\vosc_test, {
arg out=0, buf=0, amp=0.25, hz_car=240, hz_mod=60, mod_idx=1.0, fade=0.0;
var mod, car;
mod = SinOsc.ar(hz_mod) * mod_idx;
car = XFade2.ar(
/*
VOsc.ar(buf, hz_car, mod*pi/2),
Osc.ar(buf, hz_car, mod*pi/2),
*/
// same effect using frequency
VOsc.ar(buf, hz_car * ( 1.0 + mod)),
Osc.ar(buf + 0.5, hz_car * ( 1.0 + mod)),
fade
);
// sanity check
// car = SinOsc.ar(hz_car, mod*pi);
Out.ar(out, car * amp);
}).send(s);
// just 2 identical buffers, both sines
n = 2;
b = Buffer.allocConsecutive(n, s, 4096, 1, { |buf, i|
buf.sine1Msg([1.0])
});
s.sync;
z = Synth.new(\vosc_test, [\buf, b[0].bufnum]);
{
w = Window("test", Rect(0, 0, 400, 400));
t = StaticText(w, w.bounds);
t.align = \center;
~refresh = {
var str = "";
[\hz_car, \hz_mod, \mod_idx, \fade].do({|key|
z.get(key, {|val|
str = str ++ key ++ " : " ++ val ++ "\r\n";
{t.string = str;}.defer;
});
});
};
w.view.mouseMoveAction_{|v,x,y,mod|
var mod_idx = (x / v.bounds.width * 4.0).max(0.0);
var hz_mod= ((y / v.bounds.height).max(0.0) * 60.0).midicps;
z.set(\mod_idx, mod_idx);
z.set(\hz_mod, hz_mod);
~refresh.value;
};
w.view.keyDownAction = { |v, char, mod, uni, key, qt|
[char,qt].postln;
switch(qt,
49, { z.set(\fade, -1.0); ~refresh.value; },
50, { z.set(\fade, 1.0); ~refresh.value; },
)};
w.onClose = { z.free; b.free; };
w.front;
~refresh.value;
s.scope;
}.defer;
}.play;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment