Csound Csound-dev Csound-tekno Search About

simple if

Date2015-08-18 08:10
FromRichard
Subjectsimple if
I wonder why this does not work as I expect it:

gkInLvl        init     0.5
gkDuration    init    10
gaI            init    0

instr 1
gaI     inch      1
kAI        rms    gaI
;printk2    kAI
         if kAI > gkInLvl then
             printk2    kAI
             turnon    4
         endif
endin


I see that instrument 4 is always activated, but kAI after the if is not 
printed, and in fact the if should not be executed, since the signal 
level is much to low...

Richard

------------------------------------------------------------------------------
_______________________________________________
Csound-users mailing list
Csound-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-users
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2015-08-18 08:25
Frommskala@ansuz.sooke.bc.ca
SubjectRe: simple if
On Tue, 18 Aug 2015, Richard wrote:
>          if kAI > gkInLvl then
>              printk2    kAI
>              turnon    4
>          endif

turnon runs at i-time, and putting it inside a k-time if statement is
probably not going to have the effect you want.  You may be able to make
it work using event or scoreline instead of turnon, but you'll have to
give some attention to making sure it doesn't start a new note on *every*
k-cycle for which the condition holds.  It looks like you want it to only
start a new note on the first such k-cycle.

Date2015-08-18 08:59
FromRichard
SubjectRe: simple if
Yes, it must be something like this. Changed it accoring a McCurdy 
sample, but still not doing what I want.
Instrument 4 is always started.
Here's the csd

;
;    autoRec: automatically record a sound file when signal is above a 
treshold
;


;CHANGE YOUR INPUT AND OUTPUT DEVICE NUMBER HERE IF NECESSARY!
-i adc0 -o dac0 -B 1024 -b 512


sr = 11025 ;set sample rate
ksmps = 32 ;number of samples per control cycle
nchnls = 1 ;use one audio channel
0dbfs = 1 ;set maximum level as 1

gkInLvl        init     0.05
gkDuration    init    10
gaI            init    0

instr 1
     gaI     inch    1
     gkAI    rms        gaI
endin

instr 2
     if gkAI > gkInLvl then
         printk2    gkAI
         ;SCHEDKWHEN     KTRIGGER, KMINTIM, KMAXNUM, KINSNUM, KWHEN, KDUR
         schedkwhen        1,          0,       1,       4, 0,    -1    
;TRIGGER RECORD
         turnoff
     endif
endin

instr    4    ;RECORD
     ain    inch    1            ;READ AUDIO FROM MONO INPUT
     fout "out.wav", 4, ain    ;WRITE MONO AUDIO TO A 16 BIT WAV (TYPE:4)
     gkrecdur    line    0,1,1        ;REGISTER THE DURATION OF THE 
CURRENTLY RECORDED FILE
     ;printk2    gkrecdur
     if gkrecdur >gkDuration then
         turnoff
     endif
endin



i 1 0 30
i 2 0 30



On 18/08/15 09:25, mskala@ansuz.sooke.bc.ca wrote:
> On Tue, 18 Aug 2015, Richard wrote:
>>           if kAI > gkInLvl then
>>               printk2    kAI
>>               turnon    4
>>           endif
> turnon runs at i-time, and putting it inside a k-time if statement is
> probably not going to have the effect you want.  You may be able to make
> it work using event or scoreline instead of turnon, but you'll have to
> give some attention to making sure it doesn't start a new note on *every*
> k-cycle for which the condition holds.  It looks like you want it to only
> start a new note on the first such k-cycle.
>


------------------------------------------------------------------------------
_______________________________________________
Csound-users mailing list
Csound-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-users
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2015-08-18 09:23
FromVictor Lazzarini
SubjectRe: simple if
Did you try event as suggested? There might be a chance that schedkwhen is running at both i and k time.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

> On 18 Aug 2015, at 08:59, Richard  wrote:
> 
> Yes, it must be something like this. Changed it accoring a McCurdy 
> sample, but still not doing what I want.
> Instrument 4 is always started.
> Here's the csd
> 
> ;
> ;    autoRec: automatically record a sound file when signal is above a 
> treshold
> ;
> 
> 
> ;CHANGE YOUR INPUT AND OUTPUT DEVICE NUMBER HERE IF NECESSARY!
> -i adc0 -o dac0 -B 1024 -b 512
> 
> 
> sr = 11025 ;set sample rate
> ksmps = 32 ;number of samples per control cycle
> nchnls = 1 ;use one audio channel
> 0dbfs = 1 ;set maximum level as 1
> 
> gkInLvl        init     0.05
> gkDuration    init    10
> gaI            init    0
> 
> instr 1
>     gaI     inch    1
>     gkAI    rms        gaI
> endin
> 
> instr 2
>     if gkAI > gkInLvl then
>         printk2    gkAI
>         ;SCHEDKWHEN     KTRIGGER, KMINTIM, KMAXNUM, KINSNUM, KWHEN, KDUR
>         schedkwhen        1,          0,       1,       4, 0,    -1    
> ;TRIGGER RECORD
>         turnoff
>     endif
> endin
> 
> instr    4    ;RECORD
>     ain    inch    1            ;READ AUDIO FROM MONO INPUT
>     fout "out.wav", 4, ain    ;WRITE MONO AUDIO TO A 16 BIT WAV (TYPE:4)
>     gkrecdur    line    0,1,1        ;REGISTER THE DURATION OF THE 
> CURRENTLY RECORDED FILE
>     ;printk2    gkrecdur
>     if gkrecdur >gkDuration then
>         turnoff
>     endif
> endin
> 
> 
> 
> i 1 0 30
> i 2 0 30
> 
> 
> 
>> On 18/08/15 09:25, mskala@ansuz.sooke.bc.ca wrote:
>>> On Tue, 18 Aug 2015, Richard wrote:
>>>          if kAI > gkInLvl then
>>>              printk2    kAI
>>>              turnon    4
>>>          endif
>> turnon runs at i-time, and putting it inside a k-time if statement is
>> probably not going to have the effect you want.  You may be able to make
>> it work using event or scoreline instead of turnon, but you'll have to
>> give some attention to making sure it doesn't start a new note on *every*
>> k-cycle for which the condition holds.  It looks like you want it to only
>> start a new note on the first such k-cycle.
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> Csound-users mailing list
> Csound-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-users
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

------------------------------------------------------------------------------
_______________________________________________
Csound-users mailing list
Csound-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-users
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2015-08-18 10:11
FromRichard
SubjectRe: simple if
Yes, tried it with event_i too now. Instrument 4 is always started 
(should not happen), but

printk2    gkAI

is only executed when the level is exceeded.
It's a mystery to me....

Richard



On 18/08/15 10:23, Victor Lazzarini wrote:
> Did you try event as suggested? There might be a chance that schedkwhen is running at both i and k time.
>
> Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy
> Maynooth University
> Ireland
>
>> On 18 Aug 2015, at 08:59, Richard  wrote:
>>
>> Yes, it must be something like this. Changed it accoring a McCurdy
>> sample, but still not doing what I want.
>> Instrument 4 is always started.
>> Here's the csd
>>
>> ;
>> ;    autoRec: automatically record a sound file when signal is above a
>> treshold
>> ;
>> 
>> 
>> ;CHANGE YOUR INPUT AND OUTPUT DEVICE NUMBER HERE IF NECESSARY!
>> -i adc0 -o dac0 -B 1024 -b 512
>> 
>> 
>> sr = 11025 ;set sample rate
>> ksmps = 32 ;number of samples per control cycle
>> nchnls = 1 ;use one audio channel
>> 0dbfs = 1 ;set maximum level as 1
>>
>> gkInLvl        init     0.05
>> gkDuration    init    10
>> gaI            init    0
>>
>> instr 1
>>      gaI     inch    1
>>      gkAI    rms        gaI
>> endin
>>
>> instr 2
>>      if gkAI > gkInLvl then
>>          printk2    gkAI
>>          ;SCHEDKWHEN     KTRIGGER, KMINTIM, KMAXNUM, KINSNUM, KWHEN, KDUR
>>          schedkwhen        1,          0,       1,       4, 0,    -1
>> ;TRIGGER RECORD
>>          turnoff
>>      endif
>> endin
>>
>> instr    4    ;RECORD
>>      ain    inch    1            ;READ AUDIO FROM MONO INPUT
>>      fout "out.wav", 4, ain    ;WRITE MONO AUDIO TO A 16 BIT WAV (TYPE:4)
>>      gkrecdur    line    0,1,1        ;REGISTER THE DURATION OF THE
>> CURRENTLY RECORDED FILE
>>      ;printk2    gkrecdur
>>      if gkrecdur >gkDuration then
>>          turnoff
>>      endif
>> endin
>>
>> 
>> 
>> i 1 0 30
>> i 2 0 30
>> 
>> 
>>
>>> On 18/08/15 09:25, mskala@ansuz.sooke.bc.ca wrote:
>>>> On Tue, 18 Aug 2015, Richard wrote:
>>>>           if kAI > gkInLvl then
>>>>               printk2    kAI
>>>>               turnon    4
>>>>           endif
>>> turnon runs at i-time, and putting it inside a k-time if statement is
>>> probably not going to have the effect you want.  You may be able to make
>>> it work using event or scoreline instead of turnon, but you'll have to
>>> give some attention to making sure it doesn't start a new note on *every*
>>> k-cycle for which the condition holds.  It looks like you want it to only
>>> start a new note on the first such k-cycle.
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Csound-users mailing list
>> Csound-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-users
>> Send bugs reports to
>>         https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
> ------------------------------------------------------------------------------
> _______________________________________________
> Csound-users mailing list
> Csound-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-users
> Send bugs reports to
>          https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here


------------------------------------------------------------------------------
_______________________________________________
Csound-users mailing list
Csound-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-users
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2015-08-18 10:20
Frommskala@ansuz.sooke.bc.ca
SubjectRe: simple if
On Tue, 18 Aug 2015, Richard wrote:
> Yes, tried it with event_i too now. Instrument 4 is always started
> (should not happen), but

event_i is another i-time opcode.  Try just event.

Date2015-08-18 10:23
FromRichard
SubjectRe: simple if
Yes of course! Anyhow it is solved now, I am also using a flag...

On 18/08/15 11:20, mskala@ansuz.sooke.bc.ca wrote:
> On Tue, 18 Aug 2015, Richard wrote:
>> Yes, tried it with event_i too now. Instrument 4 is always started
>> (should not happen), but
> event_i is another i-time opcode.  Try just event.
>


------------------------------------------------------------------------------
_______________________________________________
Csound-users mailing list
Csound-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-users
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2015-08-18 10:25
FromVictor Lazzarini
SubjectRe: simple if
No, not event_i, that one is i-time only.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 18 Aug 2015, at 10:11, Richard  wrote:
> 
> Yes, tried it with event_i too now. Instrument 4 is always started 
> (should not happen), but
> 
> printk2    gkAI
> 
> is only executed when the level is exceeded.
> It's a mystery to me....
> 
> Richard
> 
> 
> 
> On 18/08/15 10:23, Victor Lazzarini wrote:
>> Did you try event as suggested? There might be a chance that schedkwhen is running at both i and k time.
>> 
>> Victor Lazzarini
>> Dean of Arts, Celtic Studies, and Philosophy
>> Maynooth University
>> Ireland
>> 
>>> On 18 Aug 2015, at 08:59, Richard  wrote:
>>> 
>>> Yes, it must be something like this. Changed it accoring a McCurdy
>>> sample, but still not doing what I want.
>>> Instrument 4 is always started.
>>> Here's the csd
>>> 
>>> ;
>>> ;    autoRec: automatically record a sound file when signal is above a
>>> treshold
>>> ;
>>> 
>>> 
>>> ;CHANGE YOUR INPUT AND OUTPUT DEVICE NUMBER HERE IF NECESSARY!
>>> -i adc0 -o dac0 -B 1024 -b 512
>>> 
>>> 
>>> sr = 11025 ;set sample rate
>>> ksmps = 32 ;number of samples per control cycle
>>> nchnls = 1 ;use one audio channel
>>> 0dbfs = 1 ;set maximum level as 1
>>> 
>>> gkInLvl        init     0.05
>>> gkDuration    init    10
>>> gaI            init    0
>>> 
>>> instr 1
>>>     gaI     inch    1
>>>     gkAI    rms        gaI
>>> endin
>>> 
>>> instr 2
>>>     if gkAI > gkInLvl then
>>>         printk2    gkAI
>>>         ;SCHEDKWHEN     KTRIGGER, KMINTIM, KMAXNUM, KINSNUM, KWHEN, KDUR
>>>         schedkwhen        1,          0,       1,       4, 0,    -1
>>> ;TRIGGER RECORD
>>>         turnoff
>>>     endif
>>> endin
>>> 
>>> instr    4    ;RECORD
>>>     ain    inch    1            ;READ AUDIO FROM MONO INPUT
>>>     fout "out.wav", 4, ain    ;WRITE MONO AUDIO TO A 16 BIT WAV (TYPE:4)
>>>     gkrecdur    line    0,1,1        ;REGISTER THE DURATION OF THE
>>> CURRENTLY RECORDED FILE
>>>     ;printk2    gkrecdur
>>>     if gkrecdur >gkDuration then
>>>         turnoff
>>>     endif
>>> endin
>>> 
>>> 
>>> 
>>> i 1 0 30
>>> i 2 0 30
>>> 
>>> 
>>> 
>>>> On 18/08/15 09:25, mskala@ansuz.sooke.bc.ca wrote:
>>>>> On Tue, 18 Aug 2015, Richard wrote:
>>>>>          if kAI > gkInLvl then
>>>>>              printk2    kAI
>>>>>              turnon    4
>>>>>          endif
>>>> turnon runs at i-time, and putting it inside a k-time if statement is
>>>> probably not going to have the effect you want.  You may be able to make
>>>> it work using event or scoreline instead of turnon, but you'll have to
>>>> give some attention to making sure it doesn't start a new note on *every*
>>>> k-cycle for which the condition holds.  It looks like you want it to only
>>>> start a new note on the first such k-cycle.
>>> 
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Csound-users mailing list
>>> Csound-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-users
>>> Send bugs reports to
>>>        https://github.com/csound/csound/issues
>>> Discussions of bugs and features can be posted here
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Csound-users mailing list
>> Csound-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-users
>> Send bugs reports to
>>         https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> Csound-users mailing list
> Csound-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-users
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here


------------------------------------------------------------------------------
_______________________________________________
Csound-users mailing list
Csound-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-users
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2015-08-19 23:10
Fromjoachim heintz
SubjectRe: simple if
i tried to give some examples at the beginning of this chapter:
http://floss.booktype.pro/csound/c-control-structures/

best -
	joachim


Am 18.08.2015 um 11:23 schrieb Richard:
> Yes of course! Anyhow it is solved now, I am also using a flag...
>
> On 18/08/15 11:20, mskala@ansuz.sooke.bc.ca wrote:
>> On Tue, 18 Aug 2015, Richard wrote:
>>> Yes, tried it with event_i too now. Instrument 4 is always started
>>> (should not happen), but
>> event_i is another i-time opcode.  Try just event.
>>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Csound-users mailing list
> Csound-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-users
> Send bugs reports to
>          https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

------------------------------------------------------------------------------
_______________________________________________
Csound-users mailing list
Csound-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-users
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here