Skip to content

Instantly share code, notes, and snippets.

@catfact
Last active August 20, 2024 21:56
Show Gist options
  • Save catfact/541242cf516e4fe7c90ab9054176a71e to your computer and use it in GitHub Desktop.
Save catfact/541242cf516e4fe7c90ab9054176a71e to your computer and use it in GitHub Desktop.
~nfftpoints = 2048;
~nfftbands = (~nfftpoints / 2) + 1;
s = Server.default;
s.waitForBoot {
SynthDef.new(\freeze_smear_magbands_stereo, {
var input = In.ar(\in.kr, 2);
var chain = FFT(LocalBuf(~nfftpoints.dup, 1), input);
var frozen = PV_MagFreeze(chain, \freeze.kr(0));
// var output =IFFT.ar(frozen);
//*/
var smeared = PV_MagSmear(frozen, \smear.kr(0));
var shifted = PV_MagShift(smeared, \stretch.kr(1), \shift.kr(0));
var threshold = \threshold.kr(0.5);
var above = PV_MagAbove(PV_Copy(shifted, LocalBuf(~nfftpoints.dup, 1)), threshold);
var below = PV_MagBelow(PV_Copy(shifted, LocalBuf(~nfftpoints.dup, 1)), threshold);
var output = XFade2.ar(IFFT.ar(below), IFFT.ar(above), \balance.kr(0.5));
//*/
Out.ar(\out.kr(0), output * \amp.kr(1));
}).send(s);
~b_in = Bus.audio(s, 2);
{ ~b_in.scope; }.defer;
~z_in = { Out.ar(~b_in.index, SoundIn.ar([0, 1])) }.play(s);
s.sync;
~z_fsmbs = Synth.new(\freeze_smear_magbands_stereo,
[\in, ~b_in.index],
target: ~z_in,
addAction: \addAfter
);
{
w = Window("frzpltmg");
w.front;
l = w.addFlowLayout(4@4, 4@4);
// ~valviz = StaticText(w, 200@20);
// l.nextLine;
StaticText(w.view, 80@20).string_("freeze: ");
Button(w.view, 20@20).states_([
["-", Color.black, Color.white],
["+", Color.white, Color.grey]
]).action_({ arg bt;
~z_fsmbs.set(\freeze, bt.value.postln);
});
l.nextLine;
StaticText(w.view, 80@20).string_("smear: ");
Slider(w.view, 120@20).action_({ arg sl; sl.value;
~z_fsmbs.set(\smear, sl.value.linlin(0, 1, 0, ~nfftbands/16).postln);
});
l.nextLine;
StaticText(w.view, 80@20).string_("stretch: ");
Slider(w.view, 120@20).action_({ arg sl; sl.value;
~z_fsmbs.set(\stretch, (2 ** (sl.value.linlin(0, 1, -2, 2))).postln);
});
l.nextLine;
StaticText(w.view, 80@20).string_("shift: ");
Slider(w.view, 120@20).action_({ arg sl; sl.value;
~z_fsmbs.set(\shift, sl.value.linlin(0, 1, -1*(~nfftbands/4), ~nfftbands/4).postln);
});
l.nextLine;
StaticText(w.view, 80@20).string_("threshold: ");
Slider(w.view, 120@20).action_({ arg sl; sl.value;
// NB: this scaling a bit arbitrary, should be sort of statistically expected summed bin mags
~z_fsmbs.set(\threshold, (sl.value.linlin(0, 1, -90, 0).dbamp * ~nfftbands / 16).postln);
});
l.nextLine;
StaticText(w.view, 80@20).string_("balance: ");
Slider(w.view, 120@20).action_({ arg sl; sl.value;
~z_fsmbs.set(\balance, sl.value.linlin(0, 1, -1, 1).postln);
});
}.defer;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment