Author |
Message |
gibbles
Joined: Jun 05, 2007 Posts: 7 Location: dublin
|
Posted: Tue Jun 05, 2007 1:09 pm Post subject:
Sample Slicer |
 |
|
Hey all,
Having trouble with clicks when I use the following code, not sure if this is perhaps the best method to achieve what I'm after? I basically want to be able to cut up and rearrange a buffer, the result being read back through final bufrd. Sorry if this post is a little incoherent, long day at work!
~index = Buffer.alloc(s,512,bufnum:1); //index buffer
~steps = Array.fill(16,{16.rand}) //array of steps
~steps.plot; //take a peek
(
~scramble = { //function scrambles array further and fills buffer with steps
~size = 512/16;
~steps = ~steps.scramble;
~steps.do({|item,i|
item = item.min(16);
~index.setn(i*(~size), Array.fill(~size,{|j| ((item*~size) + j/512)}))
});
}
)
~scramble.value;
~index.plot;
~sound = Buffer.read(s,"sounds/a11wlk01.wav",bufnum:2)
(SynthDef(\phizzing,{|index_buf,sound_buf,rate=2.5|
var index_frames,snd_frames,phasor,bufrd,sound;
index_frames = BufFrames.kr(index_buf);
snd_frames = BufFrames.kr(2);
phasor = Phasor.ar(0,index_frames/(rate*BufSampleRate.kr(1)),0,index_frames);
bufrd = BufRd.ar(1,index_buf,phasor,1,4);
sound = BufRd.ar(1,sound_buf,bufrd*snd_frames);
Out.ar(0,(sound*2.5).dup);
}).play(s,[\index_buf,~index.bufnum,\sound_buf,~sound.bufnum])
)
thanks,
gibb |
|
Back to top
|
|
 |
dewdrop_world

Joined: Aug 28, 2006 Posts: 858 Location: Guangzhou, China
Audio files: 4
|
Posted: Thu Jun 07, 2007 4:47 am Post subject:
|
 |
|
Clicks and pops are probably the result of jumping from one part of the sound buffer to another without managing the transitions.
I don't have time this morning to rewrite the code, but the way I would handle the transitions is to use a trigger UGen (Impulse) to trigger the change from one sample to another and use that to trigger BOTH restarting sample playback from a new buffer location AND an envelope to fade in and out quickly.
The transitions can be seamless if you split the stream of triggers into two streams, which is easy using PulseDivider.
PulseDivider.kr(Impulse.kr(freq), 2, (0..1))
Then, one envelope is fading out while the other is fading in... no break for the listener.
This is probably hard for you to visualize now... tonight I can rewrite your example to illustrate what I mean.
hjh _________________ ddw online: http://www.dewdrop-world.net
sc3 online: http://supercollider.sourceforge.net |
|
Back to top
|
|
 |
gibbles
Joined: Jun 05, 2007 Posts: 7 Location: dublin
|
Posted: Thu Jun 07, 2007 10:02 am Post subject:
|
 |
|
dewdrop_world wrote: |
This is probably hard for you to visualize now... tonight I can rewrite your example to illustrate what I mean.
hjh |
this would be really helpful thanks! |
|
Back to top
|
|
 |
dewdrop_world

Joined: Aug 28, 2006 Posts: 858 Location: Guangzhou, China
Audio files: 4
|
Posted: Thu Jun 07, 2007 8:14 pm Post subject:
|
 |
|
Weird... I posted this earlier with more comments in the code, but somehow it disappeared from the thread.
This might be confusing at first read, but ask questions and I'll try to explain.
Code: | ~steps = Array.fill(16,{16.rand}) //array of steps
~index = Buffer.alloc(s,~steps.size, 1, { |buf| buf.setnMsg(0, ~steps) }); //index buffer
(
~scramble = { //function scrambles array further and fills buffer with steps
~steps = ~steps.scramble;
~index.setn(0, ~steps);
}
)
~scramble.value;
~index.plot;
~sound = Buffer.read(s,"sounds/a11wlk01.wav");
(
a = SynthDef(\phizzing,{|index_buf,sound_buf,slicetime = 0.125|
var trig = Impulse.kr(slicetime.reciprocal),
// divide the stream into alternating triggers
trigs = PulseDivider.kr(trig, 2, (0..1)),
envelopes = EnvGen.kr(Env.linen(0.02, 0.96, 0.02), trigs, timeScale: slicetime),
index_frames = BufFrames.kr(index_buf),
snd_frames = BufFrames.kr(sound_buf),
bufindex = PulseCount.kr(trig).wrap(0, index_frames - 1),
startpos = Index.kr(index_buf, bufindex) * snd_frames / index_frames,
sound = PlayBuf.ar(1, sound_buf, BufRateScale.kr(sound_buf), trigs, startpos)
* envelopes;
Out.ar(0,(Mix(sound)*2.5).dup);
}).play(s,[\index_buf,~index.bufnum,\sound_buf,~sound.bufnum])
)
a.free;
|
James _________________ ddw online: http://www.dewdrop-world.net
sc3 online: http://supercollider.sourceforge.net |
|
Back to top
|
|
 |
gibbles
Joined: Jun 05, 2007 Posts: 7 Location: dublin
|
Posted: Mon Jun 11, 2007 10:07 am Post subject:
|
 |
|
thanks, that works really quite well. I have a few questions though, if you don't mind! I haven't seen or used PulseDivider before, my understanding is that this splits my trigger into two seperate triggers each at half the time of the orignal; this is then used to trigger the envelope, right? The part I'm unsure about is how both envelopes get triggered, if I pass an array(PulseDivider) into the trigger arg of the env does this create two env's as a result of multichannel expansion? Also not quite sure what the PulseCount is doing.
Thanks again for the help on this one!
g. |
|
Back to top
|
|
 |
dewdrop_world

Joined: Aug 28, 2006 Posts: 858 Location: Guangzhou, China
Audio files: 4
|
Posted: Tue Jun 12, 2007 7:04 pm Post subject:
|
 |
|
OK...
PulseDivider passes through every x triggers, starting with the y'th one. If you have trig = Impulse.kr(1), PulseDivider.kr(trig, 2) outputs every other trigger starting with the first one. PulseDivider.kr(trig, 2, 1) outputs every other trigger starting with the second.
Because of multichannel expansion, PulseDivider.kr(trig, 2, (0..1)) creates a pair of PulseDividers:
Code: | trigs = PulseDivider.kr(trig, 2, (0..1)) |
is really
Code: | trigs = PulseDivider.kr(trig, 2, [0, 1]) |
which becomes
Code: | trigs = [PulseDivider.kr(trig, 2, 0), PulseDivider.kr(trig, 2, 1)] |
The first trigger comes out of the first array element, the second from the second, the third bounces back to the first etc. Pingpong.
Multichannel expansion then applies to the EnvGen too:
Code: | EnvGen.kr(Env.linen(...), trigs, timeScale: slicetime)
EnvGen.kr(Env.linen(...), [PulseDivider.kr(trig, 2, 0), PulseDivider.kr(trig, 2, 1)], timeScale: slicetime)
[EnvGen.kr(Env.linen(...), PulseDivider.kr(trig, 2, 0), timeScale: slicetime), EnvGen.kr(Env.linen(...), PulseDivider.kr(trig, 2, 1), timeScale: slicetime)] |
And PlayBuf too!
Code: | PlayBuf.ar(1, sound_buf, BufRateScale.kr(sound_buf), trigs, startpos)
[PlayBuf.ar(1, sound_buf, BufRateScale.kr(sound_buf), PulseDivider.kr(trig, 2, 0), startpos), PlayBuf.ar(1, sound_buf, BufRateScale.kr(sound_buf), PulseDivider.kr(trig, 2, 1), startpos)] |
And when you multiply the pair of PlayBufs by the pair of envelopes, you get the alternating pairs.
Code: | [PlayBuf.ar(1, sound_buf, BufRateScale.kr(sound_buf), PulseDivider.kr(trig, 2, 0), startpos), PlayBuf.ar(1, sound_buf, BufRateScale.kr(sound_buf), PulseDivider.kr(trig, 2, 1), startpos)]
*
[EnvGen.kr(Env.linen(...), PulseDivider.kr(trig, 2, 0), timeScale: slicetime), EnvGen.kr(Env.linen(...), PulseDivider.kr(trig, 2, 1), timeScale: slicetime)]
=
[PlayBuf.ar(1, sound_buf, BufRateScale.kr(sound_buf), PulseDivider.kr(trig, 2, 0), startpos) * EnvGen.kr(Env.linen(...), PulseDivider.kr(trig, 2, 0), timeScale: slicetime), PlayBuf.ar(1, sound_buf, BufRateScale.kr(sound_buf), PulseDivider.kr(trig, 2, 1), startpos) * EnvGen.kr(Env.linen(...), PulseDivider.kr(trig, 2, 1), timeScale: slicetime)] |
Multichannel expansion is really powerful but it takes awhile to get really comfortable with reading it. You can see how the explicit arrays get really cumbersome to read but the original code, exploiting m-c expansion, is streamlined and expresses the idea very concisely. Hope this helps.
Oh yeah, PulseCount does exactly what it says... it increases the counter by 1 every time a trigger comes in (counts the # of pulses). So we move to the next index_buf position with each trigger.
James _________________ ddw online: http://www.dewdrop-world.net
sc3 online: http://supercollider.sourceforge.net |
|
Back to top
|
|
 |
gibbles
Joined: Jun 05, 2007 Posts: 7 Location: dublin
|
Posted: Wed Jun 13, 2007 9:51 am Post subject:
|
 |
|
thanks, thats really fantastic! This is what I love about SuperCollider and what keeps me up far too late every weeknight! |
|
Back to top
|
|
 |
|