List of Buffers Problem

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

List of Buffers Problem

jemfiner
Hello,

In the code below each time some audio is recorded it is copied into a new
buffer which is added to an initially empty list of buffers, the idea being
that one can then play multiple loops.
It works except for an odd bug:

If one executes ~buffers.at(3); before that buffer has been created the post
is nil, as would be expected.
But if one then executes ~playback4 = Synth(\player,[\sample,
~buffers.at(3)]); it doesn't post nil, it will playback the buffer inot
which audio is recorded before being copied.

Any idea why ? I don't want this to happen !

Thanks,

Jem


//synth defs
(//new recorder with trigger argument reset record to start of buffer
SynthDef(\recordSimple, { arg out = 0, buffer = 0, startFrame = 0, trig,
stopGo = 1, overdub = 0;
    var soundIn;
    soundIn= SoundIn.ar(0);
        RecordBuf.ar(soundIn, bufnum: buffer, offset: startFrame, preLevel:
overdub, run: stopGo, doneAction: 2, loop: 1, trigger: Changed.kr(trig));
}).add;
);

//simple playback
(
SynthDef(\player,{arg sample, pitch = 1; var play;~buffers.size;
~buffers;
~buffers.last;
~buffers.at(3);
play = PlayBuf.ar(1,sample,pitch,1,0,1);
Out.ar(0,Pan2.ar(play));
}).add;
);

//triggers
(
SynthDef(\recordTrig,{arg trigOn = 0, trigOff = 0; var on , off, time;
on = Trig1.kr(Changed.kr(trigOn));
off = Trig1.kr(Changed.kr(trigOff));
time = Line.kr(0, 1000000 ,1000000);
SendTrig.kr(on,1,time);
SendTrig.kr(off,2,time);
}).add;
);

(
~dur = 32;
~buf1 = Buffer.alloc(s,44100 * ~dur,1);
~buffers = List[];
~trig = -1;
~trigCount = 1;
~timer = Line.kr(0, 1000000 ,1000000);

//record
~c = Synth(\recordSimple, [\buffer: ~buf1, \loop: 1, \stopGo: 0]);
~triggers = Synth(\recordTrig,[\trigOn: 0, \trigOff: 0]);
~stopwatch = OSCresponderNode(s.addr,'/tr',{ arg time,responder,msg;
              [time, responder, msg].postln;
                  msg[2].switch(
                1, {~startTime = msg[3];["start time ",~startTime].postln},
                2, {~endTime = msg[3]; ["end time ",~endTime].postln;
                        ~dur = ~endTime - ~startTime;
                        ["duration ",~dur].postln;
                    ~buffers.add(Buffer.alloc(s, 44100*~dur, 1) );
            ~buf1.copyData(~buffers.last, 0, 0, 44100*~dur);
                    if(~buffers.size > 8,{~buffers.first.zero;~buffers.removeAt(0)},0);
        });
}).add;
);


(//click inside brackets to record
~c.set(\trig,1);
~c.set(\stopGo, 1);
~triggers.set(\trigOn,~trigCount);
~trigCount = ~trigCount + 1;
);

(//click inside brackets to stop recording
~c.set(\stopGo, 0);
~triggers.set(\trigOff,~trigCount);
~trigCount = ~trigCount + 1;
~c.set(\trig,-1);
);

//playback last buffer
~playback = Synth(\player,[\sample, ~buffers.last]);
//playback each buffer
//BUG they will all playback regardless as to whether buffer exists or
not.They all playback ~buf1
~playback1 = Synth(\player,[\sample, ~buffers.at(0)]);
~playback2 = Synth(\player,[\sample, ~buffers.at(1)]);
~playback3 = Synth(\player,[\sample, ~buffers.at(2)]);
~playback4 = Synth(\player,[\sample, ~buffers.at(3)]);
~playback5 = Synth(\player,[\sample, ~buffers.at(4)]);
~playback6 = Synth(\player,[\sample, ~buffers.at(5)]);
~playback7 = Synth(\player,[\sample, ~buffers.at(6)]);
~playback8 = Synth(\player,[\sample, ~buffers.at(7)]);


~playback.free;
~playback1.free;
~playback2.free;
~playback3.free;
~playback4.free;
~playback5.free;
~playback6.free;
~playback7.free;
~playback8.free;

~buffers.size;
~buffers;
~buffers.last;
~buffers.at(3);







--
Sent from: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SuperCollider-Users-New-Use-this-f2676391.html

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: List of Buffers Problem

spluta
Hi Jem,

An easy solution to make this not happen is to add an if statement to the play:

if(~buffers[0]!=nil,{~playback1 = Synth(\player,[\sample, ~buffers.at(0)]);});

I don’t know for sure, but I think what is happening is when the Synth receives nil, it is reverting to buffer 0, which happens to be, in this case, your first buffer. For instance, just after you load the server, and before you load any buffers, run this:

 (
SynthDef(\player,{arg sample, pitch = 1; var play;~buffers.size;
sample.poll;
play = PlayBuf.ar(1,sample,pitch,1,0,1);
Out.ar(0,Pan2.ar(play));
}).play;
);

It should post 0 to the post window. Proves my point.

Buffers are allocated on the Server sequentially, so the first one you load will be Buffer 0, and this will be played if you don’t have an if statement.

Sam
Reply | Threaded
Open this post in threaded view
|

Re: List of Buffers Problem

Scott Wilson-3
You’re exactly right Sam. If you pass nil as a control to a Synth you get the default value. If this is not specified then it’s 0.

S.

On 9 Feb 2018, at 14:09, <[hidden email]> <[hidden email]> wrote:

Hi Jem,

An easy solution to make this not happen is to add an if statement to the play:

if(~buffers[0]!=nil,{~playback1 = Synth(\player,[\sample, ~buffers.at(0)]);});

I don’t know for sure, but I think what is happening is when the Synth receives nil, it is reverting to buffer 0, which happens to be, in this case, your first buffer. For instance, just after you load the server, and before you load any buffers, run this:

 (
SynthDef(\player,{arg sample, pitch = 1; var play;~buffers.size;
sample.poll;
play = PlayBuf.ar(1,sample,pitch,1,0,1);
Out.ar(0,Pan2.ar(play));
}).play;
);

It should post 0 to the post window. Proves my point.

Buffers are allocated on the Server sequentially, so the first one you load will be Buffer 0, and this will be played if you don’t have an if statement.

Sam
Reply | Threaded
Open this post in threaded view
|

Re: List of Buffers Problem

julian.rohrhuber
would be nice, but isn’t the case:

SynthDef(\x, { |zz=99| zz.poll }).add;

Synth(\x, [\zz, nil]);

UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0


> On 09.02.2018, at 15:25, Scott Wilson <[hidden email]> wrote:
>
> You’re exactly right Sam. If you pass nil as a control to a Synth you get the default value. If this is not specified then it’s 0.
>
> S.
>
> On 9 Feb 2018, at 14:09, <[hidden email]> <[hidden email]> wrote:
>
>> Hi Jem,
>>
>> An easy solution to make this not happen is to add an if statement to the play:
>>
>> if(~buffers[0]!=nil,{~playback1 = Synth(\player,[\sample, ~buffers.at(0)]);});
>>
>> I don’t know for sure, but I think what is happening is when the Synth receives nil, it is reverting to buffer 0, which happens to be, in this case, your first buffer. For instance, just after you load the server, and before you load any buffers, run this:
>>
>>  (
>> SynthDef(\player,{arg sample, pitch = 1; var play;~buffers.size;
>> sample.poll;
>> play = PlayBuf.ar(1,sample,pitch,1,0,1);
>> Out.ar(0,Pan2.ar(play));
>> }).play;
>> );
>>
>> It should post 0 to the post window. Proves my point.
>>
>> Buffers are allocated on the Server sequentially, so the first one you load will be Buffer 0, and this will be played if you don’t have an if statement.
>>
>> Sam


signature.asc (849 bytes) Download Attachment
i
Reply | Threaded
Open this post in threaded view
|

Re: List of Buffers Problem

i
Hmm. That’s interesting. Did that change at some point?

This is still 0:

SynthDef(\x, { |zz| zz.poll }).add;

Synth(\x);

UGen(OutputProxy): 0
UGen(OutputProxy): 0
UGen(OutputProxy): 0


> On 9 Feb 2018, at 15:43, [hidden email] wrote:
>
> would be nice, but isn’t the case:
>
> SynthDef(\x, { |zz=99| zz.poll }).add;
>
> Synth(\x, [\zz, nil]);
>
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
> UGen(OutputProxy): 0
>
>
>> On 09.02.2018, at 15:25, Scott Wilson <[hidden email]> wrote:
>>
>> You’re exactly right Sam. If you pass nil as a control to a Synth you get the default value. If this is not specified then it’s 0.
>>
>> S.
>>
>> On 9 Feb 2018, at 14:09, <[hidden email]> <[hidden email]> wrote:
>>
>>> Hi Jem,
>>>
>>> An easy solution to make this not happen is to add an if statement to the play:
>>>
>>> if(~buffers[0]!=nil,{~playback1 = Synth(\player,[\sample, ~buffers.at(0)]);});
>>>
>>> I don’t know for sure, but I think what is happening is when the Synth receives nil, it is reverting to buffer 0, which happens to be, in this case, your first buffer. For instance, just after you load the server, and before you load any buffers, run this:
>>>
>>> (
>>> SynthDef(\player,{arg sample, pitch = 1; var play;~buffers.size;
>>> sample.poll;
>>> play = PlayBuf.ar(1,sample,pitch,1,0,1);
>>> Out.ar(0,Pan2.ar(play));
>>> }).play;
>>> );
>>>
>>> It should post 0 to the post window. Proves my point.
>>>
>>> Buffers are allocated on the Server sequentially, so the first one you load will be Buffer 0, and this will be played if you don’t have an if statement.
>>>
>>> Sam
>


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: List of Buffers Problem

ddw_music
i wrote
> Hmm. That’s interesting. Did that change at some point?

No, it hasn't changed, it's been wrong forever.

https://github.com/supercollider/supercollider/issues/1993

hjh



--
Sent from: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SuperCollider-Users-New-Use-this-f2676391.html

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
i
Reply | Threaded
Open this post in threaded view
|

Re: List of Buffers Problem

i

> On 9 Feb 2018, at 16:37, [hidden email] wrote:
>
> i wrote
>> Hmm. That’s interesting. Did that change at some point?
>
> No, it hasn't changed, it's been wrong forever.
>
> https://github.com/supercollider/supercollider/issues/1993

Ah forgot about that. As I said, I can write the fix, (though not in the immediate future), but the Unit Tests could be done in advance (assuming they haven’t been)

S.


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|

Re: List of Buffers Problem

jemfiner
In reply to this post by spluta