« Return to Thread: Cropping buffer - Server.sync + best way

Re: Cropping buffer - Server.sync + best way

by thor-2 :: Rate this Message:

Reply to Author | View in Thread


Great comments Fredrik.

It turns out that the method is not working so well: I can only crop it once, 
the second time I try to crop the same buffer, the frames disappear for some
reason and it seems to happen when the this.updateInfo is called.

Check out the method here with the postlns. But I've implemented all your
suggestions in this class.

Test code:

b = Buffer.read(s, "sounds/a11wlk01.wav");
b.numFrames
b.play


b.crop(100000, 66666, false, {|buf| buf.numFrames.postln;})
b.numFrames
b.play


b.crop(10000, 6666, false, {|buf| buf.numFrames.postln;})
b.numFrames
b.play


+ Buffer {
crop {arg startFrame, numFrames, overwrite=false, action;
var cond, tempbuf, tempbufnum, newbuf;
cond = Condition.new;


Routine.run {


tempbuf = Buffer.alloc(server, numFrames, numChannels);
server.sync(cond);
this.copyData(tempbuf, 0, startFrame, numFrames);
tempbufnum = bufnum;
server.sync(cond);
this.free;
[\tempbuf, tempbuf].postln;

server.sync(cond);

newbuf = Buffer.alloc(server, tempbuf.numFrames, tempbuf.numChannels, bufnum:tempbufnum);
server.sync(cond);
tempbuf.copyData(newbuf);
server.sync(cond);


[\newbuf, newbuf].postln;

tempbuf.free;
tempbuf = nil;


if(overwrite, { newbuf.write(this.path, "AIFF", "int16") });

server.sync(cond);
[\newbuf2, newbuf].postln;
this.updateInfo(action); // update so the buffer object has the new buffer info
};
}
}




On 21 Jul 2008, at 02:01, Fredrik Olofsson wrote:

some minor suggestions...
i would avoid Server.default inside a method.  specially here since the Buffer object already knows which server it belongs to.
and this.numChannels and this.bufnum could be just numChannels and bufnum.
your argument numFrames you might want to rename just to make it different from Buffer.numFrames.
the first .sync should not be needed.
and perhaps add an action function?
_f


/*
b = Buffer.read(s, "sounds/a11wlk01.wav");
b.play
b.crop(100000, 66666, false)
b.play
b
*/

+ Buffer {
crop {arg startFrame, frames, overwrite=false, action;
var cond, tempbuf, newbuf;
cond = Condition.new;


Routine.run {
tempbuf = Buffer.alloc(server, frames, numChannels);
server.sync(cond);
this.copyData(tempbuf, 0, startFrame, frames);
server.sync(cond);
this.free;
server.sync(cond);

newbuf = Buffer.alloc(server, tempbuf.numFrames, tempbuf.numChannels, bufnum:bufnum);
server.sync(cond);
tempbuf.copyData(newbuf);
server.sync(cond);
tempbuf.free;
tempbuf = nil;


if(overwrite, { newbuf.write(this.path, "aiff", "int16") });


server.sync(cond);
this.updateInfo(action); // update so the buffer object has the new buffer info
};
}
}



21 jul 2008 kl. 01.04 skrev thor:


Thanks for all the replies. Right now I don't have time to investigate the bind issue
but I've implemented the crop method like this:

(still interested in improvements : )


b = Buffer.read(s, "sounds/a11wlk01.wav");
b.play
b.crop(100000, 66666, false)
b.play
b


+ Buffer {
crop {arg startFrame, numFrames, overwrite=false;
var s, cond, tempbuf, tempbufnum, newbuf, chNum;
cond = Condition.new;
s = Server.default;


Routine.run {
chNum = this.numChannels;
s.sync(cond);
tempbuf = Buffer.alloc(s, numFrames, chNum);
s.sync(cond);
this.copyData(tempbuf, 0, startFrame, numFrames);
tempbufnum = this.bufnum;
s.sync(cond);
this.free;
s.sync(cond);

newbuf = Buffer.alloc(s, tempbuf.numFrames, tempbuf.numChannels, bufnum:tempbufnum);
s.sync(cond);
tempbuf.copyData(newbuf);
s.sync(cond);
tempbuf.free;
tempbuf = nil;


if(overwrite, { newbuf.write(this.path, "aiff", "int16") });


s.sync(cond);
this.updateInfo; // update so the buffer object has the new buffer info
};
}
}



  #|
     fredrikolofsson.com     klippav.org     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list


 « Return to Thread: Cropping buffer - Server.sync + best way