[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] BinaryOpUGen (instead of ==) confusion



James,

thanks for expanding ... I've got it now. I'm going to spell it out with examples for other googlers ... (hope there's no mistakes):

SynthDef("hello",  { arg someArg = 0; var baba;
    baba = if ( someArg == 1, {66}, {99})

The above doesn't work as expected. This if condition is executed only once, at compile time ... and so baba will always be 99. This is so because the curly brackets indicate a function, and that causes the if condition to be "inlined" at compile time.

SynthDef("hello",  { arg someArg = 0; var baba;
    baba = if ( BinaryOpUGen('==', 1, someArg), {66}, {99})

Doesn't work, because the BinaryOpUgen spits its result out as a signal ... and the curly brackets (functions) means that the comparison is expected to be a Boolean ... if you do this you will get "ERROR: Non Boolean in test.".

SynthDef("hello",  { arg someArg = 0; var baba;
    baba = if ( BinaryOpUGen('==', 1, someArg), 66, 99)

Works ... I assume that 66 and 99 are spat out as kr signals. Here, baba is a kr signal (correct?)

SynthDef("hello",  { arg someArg = 0; var baba;
    baba = if ( BinaryOpUGen('==', 1, someArg), In.ar(0))

Doesn't work ... you cant have a fork, in signal land, where one side of the fork is nothing ... there has to be a signal pipe ... so the answer would be have a pipe that has 0 in it.

SynthDef("hello",  { arg someArg = 0; var baba;
    baba = if ( BinaryOpUGen('==', 1, someArg), In.ar(0), Silent.ar(0))

works ... there's a signal at either end of the fork.

have I made any errors?

Etienne


On Tue, Jun 16, 2009 at 10:55 PM, James Harkins <jamshark70@xxxxxxxxx> wrote:
"if(condition, { true }, { false })" evaluates either the true or false branch once, at the time the SynthDef is compiled. Then the result is hardcoded into the SynthDef.

ah... I get it. That's what is meant by "inlining" isn't?.... the if condition is just executed once when the compiler creates the executable code .. and the result is then hard coded into that executable compiled synthdef ... which explains why I always get the same result.
 

For that to happen, the Boolean value of the condition has to be known when the SynthDef is compiled. But the condition depends on values that don't exist until the Synth is played. By wrapping true and false in functions, you're inadvertently asking the language to evaluate a condition now for values to be calculated later, which is impossible.

BinaryOpUGen('==', doppler, 1) is not a Boolean -- it's a signal that will be 0 for false and 1 for true. You can use this with if, but as noted in the earlier post, if you do that, the true and false branches must both be signals, not functions or any other kind of object.

So, take out the curly braces :)
 
...AHA ! ... I see. I see two things now (my pea is getting bigger). I see that curly brackets means a function (ok, I should have known that). So the following will work because the two branches are signals.

var audioOutput = if ( BinaryOpUGen('==', 1, doppler), DelayL.ar( air_attenuated_input, maxDelayTime , delayTime ) , air_attenuated_input );

The second thing I see is that I have an other if condition that involves control messages:

var aziD = if (doppler == 1, { DelayL.kr( azi_smoothed , maxDelayTime , delayTime ) }, {azi_smoothed});



 
hjh


On Jun 16, 2009, at 8:28 AM, e deleflie wrote:

Hi James,

yeah, that's the post I was referring to that I read .... unfortunately for my pea sized brain, it was just too much ... I thought I'd understood from that post that all I needed to do was use:

BinaryOpUGen('==', doppler, 1)

but that just creates an "ERROR: Non Boolean in test."

Etienne

On Tue, Jun 16, 2009 at 10:20 PM, James Harkins <jamshark70@xxxxxxxxx> wrote:
Perennial topic - I wrote a bedtime story about it once :)


(You're still writing if(condition, { true }, { false }) which is not valid inside a SynthDef.)



: H. James Harkins
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman