Re: Cropping buffer - Server.sync + best way
...Just to tag on to this I have a quick query relating to copying buffer data.
Should Buffer.copyData not wrap when the end of the source buffer is reached?
I'd imagine one fairly common usage of .copyData is to grab stuff out of a circling buffer into smaller buffers on the fly?
It's straightforward to just composite around the end of the source buffer but not altogether that pretty.
Below is how I've done it but is there a more elegant way?
(
var source,dest,start,size,firstHalf,secondHalf;
fork{
source = Buffer.read(s,"sounds/a11wlk01.wav");
s.sync;
dest = Buffer.alloc(s,source.sampleRate*2,source.numChannels);
start = source.numFrames * 0.95;
size = dest.numFrames;
if((start+size) > source.numFrames,{
firstHalf = start - source.numFrames;
secondHalf = size - firstHalf;
source.copyData(dest,0,start,firstHalf);
source.copyData(dest,firstHalf,0,secondHalf);
s.sync;
dest.play;
},{
source.copyData(dest,0,start,size);
s.sync;
dest.play;
});
}
)
best,
piaras