Csound Csound-dev Csound-tekno Search About

[Csnd] if then else behavior

Date2012-04-26 14:29
FromAnders Genell
Subject[Csnd] if then else behavior
Hi all!

I am, for different reasons, using 'if' statements to create gate
values for sound output.
I have now had some strange behavior.

First I do

gk_eng_gate init 0
gk_noise_gate init 0

then I do

if (gkrpm < 10) then
	gk_eng_gate = 0
else
	gk_eng_gate = 1
endif

if (gkvel < 0.5) then
	gk_noise_gate = 0
else
	gk_noise_gate = 1
endif

and in order to avoid bumps i add glissando

k_eng_gate lineto gk_eng_gate, 0.05
k_noise_gate lineto gk_noise_gate, 0.05

but when I print values (the _gain_ variables are also wrong, and
maybe it's related...?)

printks "engine level = %f road level = %f\n", 0.5, kenglevel, knoiselevel
printks "engine gate = %f noise gate = %f\n", 0.5,  k_gain_eng,
k_gain_noise, k_eng_gate, k_noise_gate

I sometimes get gate values of -1 and sometimes of 2 (see below) which
I should think was not possible when using the above 'if then else'
statements?

Im using
Csound version 5.16 (float samples) Mar 20 2012
libsndfile-1.0.21
on
Linux 2.6.31-11-rt #154-Ubuntu SMP PREEMPT RT

Does anybody have an idea what's going on?

Regards,
Anders
-----------------------------------------------------------------
engine level = 0.000000 road level = 0.000000
engine gain = 0.000000 road gain = 0.000000 engine gate = 0.000000
noise gate = 0.000000
engine level = 0.000000 road level = 0.000000
engine gain = 0.000000 road gain = 0.000000 engine gate = 0.000000
noise gate = 0.000000
engine level = 0.000000 road level = 0.000000
engine gain = 0.000000 road gain = 0.000000 engine gate = 0.000000
noise gate = 0.000000
engine level = 0.009717 road level = 0.022906
engine gain = 1.000000 road gain = 0.960000 engine gate = 1.000000
noise gate = 1.000000
engine level = 0.075190 road level = 0.086570
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.071015 road level = 0.130085
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.057981 road level = 0.100595
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.059968 road level = 0.116614
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.063069 road level = 0.127063
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.052938 road level = 0.125648
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.054821 road level = 0.113054
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.070257 road level = 0.105138
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.063930 road level = 0.099203
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.061472 road level = 0.170036
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.064142 road level = 0.085783
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000
engine level = 0.012797 road level = 0.806097
engine gain = 0.000000 road gain = 1.920000 engine gate = 0.000000
noise gate = 0.000000
engine level = 0.000000 road level = 63.930271
engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
noise gate = -1.000000
engine level = 0.000000 road level = 121.419861
engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
noise gate = -1.000000
engine level = 0.000000 road level = 181.655899
engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
noise gate = -1.000000
engine level = 0.000000 road level = 239.156204
engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
noise gate = -1.000000
engine level = 0.000000 road level = 299.395569
engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
noise gate = -1.000000
engine level = 0.000000 road level = 356.897278
engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
noise gate = -1.000000
engine level = 0.000000 road level = 417.137421
engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
noise gate = -1.000000
engine level = 0.008876 road level = 109.707466
engine gain = 1.000000 road gain = 1.920000 engine gate = 1.000000
noise gate = 1.000000
engine level = 0.057584 road level = 0.080495
engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
noise gate = 2.000000

Date2012-04-26 15:22
FromAnders Genell
Subject[Csnd] Re: if then else behavior
Just an update:
It seems to have to do with the lineto opcode. Without the glissando
the values are ok.
Is there a reason for why lineto would give values larger than the input?
Regards,
Anders

On 4/26/12, Anders Genell  wrote:
> Hi all!
>
> I am, for different reasons, using 'if' statements to create gate
> values for sound output.
> I have now had some strange behavior.
>
> First I do
>
> gk_eng_gate init 0
> gk_noise_gate init 0
>
> then I do
>
> if (gkrpm < 10) then
> 	gk_eng_gate = 0
> else
> 	gk_eng_gate = 1
> endif
>
> if (gkvel < 0.5) then
> 	gk_noise_gate = 0
> else
> 	gk_noise_gate = 1
> endif
>
> and in order to avoid bumps i add glissando
>
> k_eng_gate lineto gk_eng_gate, 0.05
> k_noise_gate lineto gk_noise_gate, 0.05
>
> but when I print values (the _gain_ variables are also wrong, and
> maybe it's related...?)
>
> printks "engine level = %f road level = %f\n", 0.5, kenglevel, knoiselevel
> printks "engine gate = %f noise gate = %f\n", 0.5,  k_gain_eng,
> k_gain_noise, k_eng_gate, k_noise_gate
>
> I sometimes get gate values of -1 and sometimes of 2 (see below) which
> I should think was not possible when using the above 'if then else'
> statements?
>
> Im using
> Csound version 5.16 (float samples) Mar 20 2012
> libsndfile-1.0.21
> on
> Linux 2.6.31-11-rt #154-Ubuntu SMP PREEMPT RT
>
> Does anybody have an idea what's going on?
>
> Regards,
> Anders
> -----------------------------------------------------------------
> engine level = 0.000000 road level = 0.000000
> engine gain = 0.000000 road gain = 0.000000 engine gate = 0.000000
> noise gate = 0.000000
> engine level = 0.000000 road level = 0.000000
> engine gain = 0.000000 road gain = 0.000000 engine gate = 0.000000
> noise gate = 0.000000
> engine level = 0.000000 road level = 0.000000
> engine gain = 0.000000 road gain = 0.000000 engine gate = 0.000000
> noise gate = 0.000000
> engine level = 0.009717 road level = 0.022906
> engine gain = 1.000000 road gain = 0.960000 engine gate = 1.000000
> noise gate = 1.000000
> engine level = 0.075190 road level = 0.086570
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.071015 road level = 0.130085
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.057981 road level = 0.100595
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.059968 road level = 0.116614
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.063069 road level = 0.127063
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.052938 road level = 0.125648
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.054821 road level = 0.113054
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.070257 road level = 0.105138
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.063930 road level = 0.099203
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.061472 road level = 0.170036
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.064142 road level = 0.085783
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
> engine level = 0.012797 road level = 0.806097
> engine gain = 0.000000 road gain = 1.920000 engine gate = 0.000000
> noise gate = 0.000000
> engine level = 0.000000 road level = 63.930271
> engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
> noise gate = -1.000000
> engine level = 0.000000 road level = 121.419861
> engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
> noise gate = -1.000000
> engine level = 0.000000 road level = 181.655899
> engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
> noise gate = -1.000000
> engine level = 0.000000 road level = 239.156204
> engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
> noise gate = -1.000000
> engine level = 0.000000 road level = 299.395569
> engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
> noise gate = -1.000000
> engine level = 0.000000 road level = 356.897278
> engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
> noise gate = -1.000000
> engine level = 0.000000 road level = 417.137421
> engine gain = -1.000000 road gain = 1.920000 engine gate = -1.000000
> noise gate = -1.000000
> engine level = 0.008876 road level = 109.707466
> engine gain = 1.000000 road gain = 1.920000 engine gate = 1.000000
> noise gate = 1.000000
> engine level = 0.057584 road level = 0.080495
> engine gain = 2.000000 road gain = 1.920000 engine gate = 2.000000
> noise gate = 2.000000
>