[sc-users] Properly allocating multiple buffers?
Eduard Resina Bertran
eduard_resina at hotmail.com
Wed Apr 16 02:10:37 PDT 2008
Hi,
as far as I can see you are defining a couple of routines in the actions of two buttons, but these routines (r and w) are never called, so those buffers are never created.
If the reason of using a routine is to have it played later (somewhere else in your code) and have the buffer re-recorded continuously there is no reason to free and allocate it on every run.
If that's not what you want just create each buffer with the start buttons and use the other buttons to record on it everytime you wish. In that case you don't need a routine:
StartBut.action_{|v| var bufdur1 = 3;
b.free;
b = Buffer.alloc(s, bufdur1*44100);
b.updateInfo({| buf | Synth("recbuffer1", [\bufnum, buf])});
};
From: ctesta at wesleyan.eduTo: sc-users at create.ucsb.eduDate: Wed, 16 Apr 2008 00:08:16 -0400Subject: [sc-users] Properly allocating multiple buffers?Hello Everyone,
I am having trouble recording multiple buffers and using them in an interface that I built using Josh and Eduard's help with using RecordBuf and GrainBuf. Right now I have 2 buffers that I am recording into. Could someone run this code to see what is happening? Basically when I try to record over a single buffer it changes both of my buffers instead of affecting each one independently. What I want to have is 4 channels of buffers that I can feed live input into independently and mix live.
Here is the code, I can't figure what is wrong. Is there a problem with how I am allocating the buffers. I would really appreciate any help on this one. The code is not clean, but it is a work in progress.
Thanks,
Carl
//interface for duo
//carl testa 2008
(
//SynthDefs
SynthDef("recbuffer1", {arg bufnum;
FreeSelfWhenDone.kr(RecordBuf.ar(AudioIn.ar(1), bufnum, loop: 0));
}).send(s);
SynthDef("recbuffer2", {arg bufnum;
FreeSelfWhenDone.kr(RecordBuf.ar(AudioIn.ar(1), bufnum, loop: 0));
}).send(s);
SynthDef("buffergrain1", {arg bufnum, trig=1, rate = 1, pos = 2, gSize = 0.5, amp;
Out.ar(0, GrainBuf.ar(2, Impulse.kr(trig), gSize, bufnum, rate, MouseX.kr(0, 1), 2, 0, -1, amp));
}).send(s);
SynthDef("buffergrain2", {arg bufnum, trig=1, rate = 1, posRate = 2, gSize = 0.5, amp;
Out.ar(0, GrainBuf.ar(2, Impulse.kr(trig), gSize, bufnum, rate, LFDNoise3.ar(0.5), 2, 0, -1, amp));
}).send(s);
)
//GUI
//READ THIS!
/*Hit first start button (on the left), then the live granulation button on the Conductor, then press the right hand start button followed by live granulation 2. Hit re-record to re-record the buffer. Each button affects both buffers instead of acting independently.*/
(
var window = SCWindow.new("live granulation",Rect(124, 300, 300, 225)).front;
//Button 1
SCButton.new(window,Rect(30, 30, 100, 20))
.states_([ [ "start", Color(0.0, 0.0, 0.0, 1.0), Color(1.0, 0.0, 0.0, 1.0) ], [ "running", Color(1.0, 1.0, 1.0, 1.0), Color(0.0, 0.0, 1.0, 1.0) ] ])
.action_{|v|
r = Routine{ var bufdur1 = 3;
p.free;
b.free;
b = Buffer.alloc(s, bufdur1*44100);
b.updateInfo({| buf | Synth("recbuffer1", [\bufnum, buf])});
bufdur1.yield;
};
};
/* The problem seems to be here. When I hit the re-record button it updates both buffers instead
of updating just the single buffer. I want to be able to update buffers with live sounds
independently. */
a = SCButton.new(window,Rect(30, 130, 100, 20))
.states_([ [ "re-record", Color(0.0, 0.0, 0.0, 1.0), Color(1.0, 0.0, 0.0, 1.0) ], [ "re-recording", Color(1.0, 1.0, 1.0, 1.0), Color(0.0, 0.0, 1.0, 1.0) ] ])
.action_{|v|
Synth("recbuffer1", [\bufnum, b,]);
a.value = 0;
};
//Button Set 2
SCButton.new(window,Rect(150, 30, 100, 20))
.states_([ [ "start", Color(0.0, 0.0, 0.0, 1.0), Color(1.0, 0.0, 0.0, 1.0) ], [ "running", Color(1.0, 1.0, 1.0, 1.0), Color(0.0, 0.0, 1.0, 1.0) ] ])
.action_{|v|
w = Routine{ var bufdur2 = 8;
o.free;
c.free;
c = Buffer.alloc(s, bufdur2*44100);
c.updateInfo({| buf | Synth("recbuffer2", [\bufnum, buf])});
bufdur2.yield;
};
};
/* The problem seems to be here. When I hit the re-record button it updates both buffers instead
of updating just the single buffer. I want to be able to update buffers with live sounds
independently. */
n = SCButton.new(window,Rect(150, 130, 100, 20))
.states_([ [ "re-record", Color(0.0, 0.0, 0.0, 1.0), Color(1.0, 0.0, 0.0, 1.0) ], [ "re-recording", Color(1.0, 1.0, 1.0, 1.0), Color(0.0, 0.0, 1.0, 1.0) ] ])
.action_{|v|
Synth("recbuffer2", [\bufnum, c,]);
n.value = 0;
};
)
//Conductor
(
Conductor.make {| con, con2 = \Conductor, trig1, rate1, gSize1, trig2, rate2, gSize2, amp1, amp2 |
con.name_("live granulation");
con2.name_("live granulation 2");
trig1 .sp(10, 0.1, 20, 0.1, \linear);
rate1 .sp(1, -10, 10, 0.01, \linear);
gSize1 .sp(0.5, 0.1, 2, 0.01, \linear);
amp1 .spec_(\amp, 0);
trig2 .sp(10, 0.1, 20, 0.1, \linear);
rate2 .sp(1, -10, 10, 0.01, \linear);
gSize2 .sp(0.5, 0.1, 2, 0.01, \linear);
amp2 .spec_(\amp, 0);
MIDIClient.init(1, 1);
MIDIIn.connect;
MIDIIn.control = { | src, chan, num, val |
x = case
{ num == 26 } {trig1.input_(val/127)}
{ num == 18 } {rate1.input_(val/127)}
{ num == 10 } {gSize1.input_(val/127)}
{ num == 27 } {trig2.input_(val/127)}
{ num == 19 } {rate2.input_(val/127)}
{ num == 11 } {gSize2.input_(val/127)}
};
con.action_(
{
p = Synth.controls("buffergrain1", [\bufnum, b, \rate, rate1, \trig, trig1, \gSize, gSize1, \amp, amp1]);
});
con2.action_(
{
o = Synth.controls("buffergrain2", [\bufnum, c, \rate, rate2, \trig, trig2, \gSize, gSize2, \amp, amp2]);
});
}.show;
)
_________________________________________________________________
La vida de los famosos al desnudo en MSN Entretenimiento
http://entretenimiento.es.msn.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.create.ucsb.edu/pipermail/sc-users/attachments/20080416/f709c853/attachment-0001.html
More information about the sc-users
mailing list