JiT-NMF-classifier: now with static drums, and a gui.

nix
Pierre Alexandre Tremblay 6 years ago
parent 95220d455a
commit b3b8f9bb83

@ -19,24 +19,98 @@ SynthDef(\JITcircular,{arg bufnum = 0, input = 0, env = 0;
BufWr.ar(audioin,bufnum,head+duration,0);
// cue the calculations via the language
SendReply.ar(FluidOnsetSlice.ar(audioin,9,0.1,5), '/attack',head);
SendReply.ar(FluidOnsetSlice.ar(audioin,9,0.2,5), '/attack',head);
Out.ar(0,[audioin, FluidOnsetSlice.ar(audioin,9,0.1,5)]);
}).add;
)
x = {Impulse.ar(0.3)}.play(s,g.index)
// drum sounds modified from original code by snappizz
// https://sccode.org/1-523
SynthDef(\fluidbd, {
|out = 0, pan = 0, amp = 0.3|
var body, bodyFreq, bodyAmp;
var pop, popFreq, popAmp;
var click, clickAmp;
var snd;
// body starts midrange, quickly drops down to low freqs, and trails off
bodyFreq = EnvGen.ar(Env([261, 120, 51], [0.035, 0.08], curve: \exp));
bodyAmp = EnvGen.ar(Env.linen(0.005, 0.1, 0.3), doneAction: 2);
body = SinOsc.ar(bodyFreq) * bodyAmp;
// pop sweeps over the midrange
popFreq = XLine.kr(750, 261, 0.02);
popAmp = EnvGen.ar(Env.linen(0.001, 0.02, 0.001)) * 0.15;
pop = SinOsc.ar(popFreq) * popAmp;
// click is spectrally rich, covering the high-freq range
// you can use Formant, FM, noise, whatever
clickAmp = EnvGen.ar(Env.perc(0.001, 0.01)) * 0.15;
click = LPF.ar(Formant.ar(910, 4760, 2110), 3140) * clickAmp;
snd = body + pop ; //+ click;
snd = snd.tanh;
Out.ar(out, Pan2.ar(snd, pan, amp));
}).add;
SynthDef(\fluidsn, {
|out = 0, pan = 0, amp = 0.3|
var pop, popAmp, popFreq;
var noise, noiseAmp;
var snd;
// pop makes a click coming from very high frequencies
// slowing down a little and stopping in mid-to-low
popFreq = EnvGen.ar(Env([3261, 410, 160], [0.005, 0.01], curve: \exp));
popAmp = EnvGen.ar(Env.perc(0.001, 0.11)) * 0.7;
pop = SinOsc.ar(popFreq) * popAmp;
// bandpass-filtered white noise
noiseAmp = EnvGen.ar(Env.perc(0.001, 0.15), doneAction: 2);
noise = BPF.ar(WhiteNoise.ar, 810, 1.6) * noiseAmp;
snd = (pop + noise) * 1.3;
Out.ar(out, Pan2.ar(snd, pan, amp));
}).add;
SynthDef(\fluidhh, {
|out = 0, pan = 0, amp = 0.3|
var click, clickAmp;
var noise, noiseAmp;
var snd;
// noise -> resonance -> expodec envelope
noiseAmp = EnvGen.ar(Env.perc(0.001, 0.3, curve: -8), doneAction: 2);
noise = Mix(BPF.ar(ClipNoise.ar, [4010, 4151], [0.15, 0.56], [1.0, 0.6])) * 0.7 * noiseAmp;
snd = noise;
Out.ar(out, Pan2.ar(snd, pan, amp));
}).add;
)
(
// instantiate the JIT-circular-buffer
y = Synth(\JITcircular,[\bufnum, b.bufnum, \input, g.index], x, 'addAfter');
x = Synth(\JITcircular,[\bufnum, b.bufnum, \input, g.index]);
// instantiate the listener to cue the processing from the language side
(
w = OSCFunc({ arg msg;
r = OSCFunc({ arg msg;
msg.postln;
}, '/attack', s.addr);
)
// stop it all
b.free;g.free;w.clear;x.free; y.free;
(
w = Window("Control", Rect(100,100,360,100)).front;
Button(w, Rect(10,10,80, 80)).states_([["bd",Color.black,Color.white]]).mouseDownAction_({Synth(\fluidbd, [\out, g.index], x, \addBefore)});
Button(w, Rect(100,10,80, 80)).states_([["sn",Color.black,Color.white]]).mouseDownAction_({Synth(\fluidsn, [\out, g.index], x, \addBefore)});
Button(w, Rect(190,10,80, 80)).states_([["hh",Color.black,Color.white]]).mouseDownAction_({Synth(\fluidhh, [\out, g.index], x,\addBefore)});
StaticText(w, Rect(280,7,70,25)).string_("Select").align_(\center);
c = PopUpMenu(w, Rect(280,32,70,25)).items_(["train","guess"]);
d = PopUpMenu(w, Rect(280,65,70,25)).items_(["classA","classB","classC"]);
w.onClose_({b.free;g.free;r.clear;x.free; y.free;});
)
Loading…
Cancel
Save