I am trying to have a sound file play, detect the onsets, then use those onsets to record into different smaller buffers to have multiple chunks of sound. Like take a sound file that has 4 drum hits, detect the drum hits and allocate those individual hits to seperate buffers for later use. I see a similar idea in another thread where someone suggested: SoX tutorial: Split by silence :: Mads Kjeldgaard — Composer and developer
But I’m trying to do this all in SC, and I can’t even get to the point of detecting the onsets, and then trying to use those onsets to trigger a RecordBuf or something:
~b = Buffer.readChannel(s, "C:/Users/melas/Samples/4_rand_perc.wav", channels:[0]);
(
SynthDef.new(\onsetBuf, {
arg buffer=~b, rate=1, trig=1, loop=0, da=2, amp=0.7, out=0;
var sig, chain, onsets, read;
sig = PlayBuf.ar(1, ~b, rate, trig, 0, loop, da);
chain = FFT(LocalBuf(1024), sig).poll;
onsets = Onsets.kr(chain, 0.5);
//read = BufWr.ar(sig, buffer, Phasor.ar(onsets, BufRateScale.kr(0) * rate, 0, BufFrames.kr(0)));
sig = Pan2.ar(sig,0);
sig = sig * amp;
Out.ar(out, sig);
}).add;
)
I know the above example is probably not even on the right path, but I’ve been going through example codes for things like loopers and such in hopes of finding insight for weeks now and I just can’t win.
Any help greatly appreciated. For my mental health, ha.
-p0