Csound Csound-dev Csound-tekno Search About

[Csnd] Problem with control signals (k-cycle evaluation?)

Date2019-02-28 21:30
From"Jeanette C."
Subject[Csnd] Problem with control signals (k-cycle evaluation?)
Hey hey,
I am experimenting with vdel_k to test a strategy for random triggering.

The idea: set a delay time, delay a trigger, if delayed trigger is active, 
execute code, set new delay time, active trigger again...

Where's the logic fault in the code below? I'm sure it's got something to do 
with execution/evaluation of code and k-cycles.

This is the code:
*** delayed_trigger.csd ***


-o dac

; ==============================================


sr	=	48000
ksmps	=	1
nchnls	=	2
0dbfs	=	1

instr 1
 	ktrig init 1 ; trigger impulse to be delayed
 	kdel init 0 ; delayed impulse/trigger
 	ktim init 2 ; delay time
 	if kdel == 1 then ; if delayed trigger is active
 		krand2 rand 1 ; random component of next delay time
 		ktim = 2 + krand2 ; delay time (should be between 1 and 3?)
 		;ktim = 2 ; this works
 		kdel = 0 ; set delayed trigger back to 0, so we don't execute in the next
 			; control cycle
 		ktrig = 1 ; Set trigger to 1 so it can be delayed
 		krand rand 200 ; random frequency componenet for played sound
 		kfreq = 200 + abs(krand) ; final frequency for sound
 		event "i", 2, 0, 1, kfreq ; play sound, so we can hear the effect or
 			; behaviour of the random trigger
 	endif

 	kdel vdel_k ktrig, ktim, 3 ; delay trigger impulse
 	ktrig = 0 ; set trigger impulse to 0, so it doesn't get delayed in the next
 		; control cycle
endin

instr 2 ; play a sound
 	ifreq = p4
 	kenv line 1, p3, 0 ; a simple envelope
 	aout oscil kenv, ifreq, 1 ; sine oscillator
 	outs aout, aout
endin


; ==============================================

f1 0 32768 10 1 ; sine wave for instr 2

i1 0 20
e



*** delayed_trigger.csd ***

Best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * SoundCloud: https://soundcloud.com/jeanette_c
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * GitHub: https://github.com/jeanette-c
  * Twitter: https://twitter.com/jeanette_c_s

I'm so curious, what do you think of me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2019-02-28 22:12
FromOeyvind Brandtsegg
SubjectRe: [Csnd] Problem with control signals (k-cycle evaluation?)
Just a quick guess. The delay seems to be interpolated, so perhaps the delayed signal does not actually reach 1. Also, it will not be as crisp and clean as the original. A more robust trigger, like >0.1 or something might work better.

Den tor. 28. feb. 2019, 10:30 p.m. skrev Jeanette C. <julien@mail.upb.de>:
Hey hey,
I am experimenting with vdel_k to test a strategy for random triggering.

The idea: set a delay time, delay a trigger, if delayed trigger is active,
execute code, set new delay time, active trigger again...

Where's the logic fault in the code below? I'm sure it's got something to do
with execution/evaluation of code and k-cycles.

This is the code:
*** delayed_trigger.csd ***
<CsoundSynthesizer>
<CsOptions>
-o dac
</CsOptions>
; ==============================================
<CsInstruments>

sr      =       48000
ksmps   =       1
nchnls  =       2
0dbfs   =       1

instr 1
        ktrig init 1 ; trigger impulse to be delayed
        kdel init 0 ; delayed impulse/trigger
        ktim init 2 ; delay time
        if kdel == 1 then ; if delayed trigger is active
                krand2 rand 1 ; random component of next delay time
                ktim = 2 + krand2 ; delay time (should be between 1 and 3?)
                ;ktim = 2 ; this works
                kdel = 0 ; set delayed trigger back to 0, so we don't execute in the next
                        ; control cycle
                ktrig = 1 ; Set trigger to 1 so it can be delayed
                krand rand 200 ; random frequency componenet for played sound
                kfreq = 200 + abs(krand) ; final frequency for sound
                event "i", 2, 0, 1, kfreq ; play sound, so we can hear the effect or
                        ; behaviour of the random trigger
        endif

        kdel vdel_k ktrig, ktim, 3 ; delay trigger impulse
        ktrig = 0 ; set trigger impulse to 0, so it doesn't get delayed in the next
                ; control cycle
endin

instr 2 ; play a sound
        ifreq = p4
        kenv line 1, p3, 0 ; a simple envelope
        aout oscil kenv, ifreq, 1 ; sine oscillator
        outs aout, aout
endin

</CsInstruments>
; ==============================================
<CsScore>
f1 0 32768 10 1 ; sine wave for instr 2

i1 0 20
e
</CsScore>
</CsoundSynthesizer>

*** delayed_trigger.csd ***

Best wishes,

Jeanette

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * SoundCloud: https://soundcloud.com/jeanette_c
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * GitHub: https://github.com/jeanette-c
  * Twitter: https://twitter.com/jeanette_c_s

I'm so curious, what do you think of me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2019-02-28 22:33
From"Jeanette C."
SubjectRe: [Csnd] Problem with control signals (k-cycle evaluation?)
Feb 28 2019, Oeyvind Brandtsegg has written:

> Just a quick guess. The delay seems to be interpolated, so perhaps the
> delayed signal does not actually reach 1. Also, it will not be as crisp and
> clean as the original. A more robust trigger, like >0.1 or something might
> work better.
If I understand correctly, you mean that I should change the if
condition to something like:
if kdel > x then
or:
if kdel >= x then
I tried with the original code (ktrig 1 or 0) and kdel >=1. No luck.

Of course, the issue is that instr 2 is triggered far too often. As the
time of instr 1 (the triggering instrument) progresses, more and more
notes get triggered with overlap. I also tried using trigger with an
appropriate threshold and mode 0 (only trigger when value crosses from
below threshold to above).

Best wishes,

Jeanette
>
> Den tor. 28. feb. 2019, 10:30 p.m. skrev Jeanette C. :
>
>> Hey hey,
>> I am experimenting with vdel_k to test a strategy for random triggering.
>>
>> The idea: set a delay time, delay a trigger, if delayed trigger is active,
>> execute code, set new delay time, active trigger again...
>>
>> Where's the logic fault in the code below? I'm sure it's got something to
>> do
>> with execution/evaluation of code and k-cycles.
>>
>> This is the code:
>> *** delayed_trigger.csd ***
>> 
>> 
>> -o dac
>> 
>> ; ==============================================
>> 
>>
>> sr      =       48000
>> ksmps   =       1
>> nchnls  =       2
>> 0dbfs   =       1
>>
>> instr 1
>>         ktrig init 1 ; trigger impulse to be delayed
>>         kdel init 0 ; delayed impulse/trigger
>>         ktim init 2 ; delay time
>>         if kdel == 1 then ; if delayed trigger is active
>>                 krand2 rand 1 ; random component of next delay time
>>                 ktim = 2 + krand2 ; delay time (should be between 1 and 3?)
>>                 ;ktim = 2 ; this works
>>                 kdel = 0 ; set delayed trigger back to 0, so we don't
>> execute in the next
>>                         ; control cycle
>>                 ktrig = 1 ; Set trigger to 1 so it can be delayed
>>                 krand rand 200 ; random frequency componenet for played
>> sound
>>                 kfreq = 200 + abs(krand) ; final frequency for sound
>>                 event "i", 2, 0, 1, kfreq ; play sound, so we can hear the
>> effect or
>>                         ; behaviour of the random trigger
>>         endif
>>
>>         kdel vdel_k ktrig, ktim, 3 ; delay trigger impulse
>>         ktrig = 0 ; set trigger impulse to 0, so it doesn't get delayed in
>> the next
>>                 ; control cycle
>> endin
>>
>> instr 2 ; play a sound
>>         ifreq = p4
>>         kenv line 1, p3, 0 ; a simple envelope
>>         aout oscil kenv, ifreq, 1 ; sine oscillator
>>         outs aout, aout
>> endin
>>
>> 
>> ; ==============================================
>> 
>> f1 0 32768 10 1 ; sine wave for instr 2
>>
>> i1 0 20
>> e
>> 
>> 
>>
>> *** delayed_trigger.csd ***
>>
>> Best wishes,
>>
>> Jeanette
>>
>> --
>>   * Website: http://juliencoder.de - for summer is a state of sound
>>   * SoundCloud: https://soundcloud.com/jeanette_c
>>   * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
>>   * GitHub: https://github.com/jeanette-c
>>   * Twitter: https://twitter.com/jeanette_c_s
>>
>> I'm so curious, what do you think of me <3
>> (Britney Spears)
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>         https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>>
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * SoundCloud: https://soundcloud.com/jeanette_c
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * GitHub: https://github.com/jeanette-c
  * Twitter: https://twitter.com/jeanette_c_s

I'm so curious, what do you think of me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2019-03-01 07:46
FromOeyvind Brandtsegg
SubjectRe: [Csnd] Problem with control signals (k-cycle evaluation?)
Yes, I was thinking you need the trigger, in the manner you describe.
But it is unclear to me if you solved the problem or not(?).
Thinking a bit more about it, the delay of trigger impulses is not a neat way to go about this, I think.
Perhaps better to use event with a delay (positive p2),
and then you can also recursively let the control instr trigger itself for repeated action.
Pseudocode:

idel = (random delay amount)
gistop = (a global flag indicating if the process should continue)
if gistop == 0 then
event_i "i", p1+1, idel, p3, p4 ...
event_i "i", p1, idel, p3, p4 ...
endif


Den tor. 28. feb. 2019 kl. 23:33 skrev Jeanette C. <julien@mail.upb.de>:
Feb 28 2019, Oeyvind Brandtsegg has written:

> Just a quick guess. The delay seems to be interpolated, so perhaps the
> delayed signal does not actually reach 1. Also, it will not be as crisp and
> clean as the original. A more robust trigger, like >0.1 or something might
> work better.
If I understand correctly, you mean that I should change the if
condition to something like:
if kdel > x then
or:
if kdel >= x then
I tried with the original code (ktrig 1 or 0) and kdel >=1. No luck.

Of course, the issue is that instr 2 is triggered far too often. As the
time of instr 1 (the triggering instrument) progresses, more and more
notes get triggered with overlap. I also tried using trigger with an
appropriate threshold and mode 0 (only trigger when value crosses from
below threshold to above).

Best wishes,

Jeanette
>
> Den tor. 28. feb. 2019, 10:30 p.m. skrev Jeanette C. <julien@mail.upb.de>:
>
>> Hey hey,
>> I am experimenting with vdel_k to test a strategy for random triggering.
>>
>> The idea: set a delay time, delay a trigger, if delayed trigger is active,
>> execute code, set new delay time, active trigger again...
>>
>> Where's the logic fault in the code below? I'm sure it's got something to
>> do
>> with execution/evaluation of code and k-cycles.
>>
>> This is the code:
>> *** delayed_trigger.csd ***
>> <CsoundSynthesizer>
>> <CsOptions>
>> -o dac
>> </CsOptions>
>> ; ==============================================
>> <CsInstruments>
>>
>> sr      =       48000
>> ksmps   =       1
>> nchnls  =       2
>> 0dbfs   =       1
>>
>> instr 1
>>         ktrig init 1 ; trigger impulse to be delayed
>>         kdel init 0 ; delayed impulse/trigger
>>         ktim init 2 ; delay time
>>         if kdel == 1 then ; if delayed trigger is active
>>                 krand2 rand 1 ; random component of next delay time
>>                 ktim = 2 + krand2 ; delay time (should be between 1 and 3?)
>>                 ;ktim = 2 ; this works
>>                 kdel = 0 ; set delayed trigger back to 0, so we don't
>> execute in the next
>>                         ; control cycle
>>                 ktrig = 1 ; Set trigger to 1 so it can be delayed
>>                 krand rand 200 ; random frequency componenet for played
>> sound
>>                 kfreq = 200 + abs(krand) ; final frequency for sound
>>                 event "i", 2, 0, 1, kfreq ; play sound, so we can hear the
>> effect or
>>                         ; behaviour of the random trigger
>>         endif
>>
>>         kdel vdel_k ktrig, ktim, 3 ; delay trigger impulse
>>         ktrig = 0 ; set trigger impulse to 0, so it doesn't get delayed in
>> the next
>>                 ; control cycle
>> endin
>>
>> instr 2 ; play a sound
>>         ifreq = p4
>>         kenv line 1, p3, 0 ; a simple envelope
>>         aout oscil kenv, ifreq, 1 ; sine oscillator
>>         outs aout, aout
>> endin
>>
>> </CsInstruments>
>> ; ==============================================
>> <CsScore>
>> f1 0 32768 10 1 ; sine wave for instr 2
>>
>> i1 0 20
>> e
>> </CsScore>
>> </CsoundSynthesizer>
>>
>> *** delayed_trigger.csd ***
>>
>> Best wishes,
>>
>> Jeanette
>>
>> --
>>   * Website: http://juliencoder.de - for summer is a state of sound
>>   * SoundCloud: https://soundcloud.com/jeanette_c
>>   * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
>>   * GitHub: https://github.com/jeanette-c
>>   * Twitter: https://twitter.com/jeanette_c_s
>>
>> I'm so curious, what do you think of me <3
>> (Britney Spears)
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>         https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>>
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * SoundCloud: https://soundcloud.com/jeanette_c
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * GitHub: https://github.com/jeanette-c
  * Twitter: https://twitter.com/jeanette_c_s

I'm so curious, what do you think of me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


--
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2019-03-01 08:03
From"Jeanette C."
SubjectRe: [Csnd] Problem with control signals (k-cycle evaluation?)
Hi Oeyvind,
thanks again for your support. Due to my final requirements, I opted for a 
solution using timek and a random interval:
know = timek
kinterval init 2
knext init 2 * kr
if know == knext then
   ...
   krandom rand 1
   kinterval = round((krandom + 2) * kr)
   knext = know + kinterval
endif

This yields good results and looks efficient enough, I guess. :)

Best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * SoundCloud: https://soundcloud.com/jeanette_c
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * GitHub: https://github.com/jeanette-c
  * Twitter: https://twitter.com/jeanette_c_s

You know I'm one of a kind,
There'll never be another me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2019-03-01 08:38
FromOeyvind Brandtsegg
SubjectRe: [Csnd] Problem with control signals (k-cycle evaluation?)
That looks good too!

Den fre. 1. mar. 2019 kl. 09:03 skrev Jeanette C. <julien@mail.upb.de>:
Hi Oeyvind,
thanks again for your support. Due to my final requirements, I opted for a
solution using timek and a random interval:
know = timek
kinterval init 2
knext init 2 * kr
if know == knext then
   ...
   krandom rand 1
   kinterval = round((krandom + 2) * kr)
   knext = know + kinterval
endif

This yields good results and looks efficient enough, I guess. :)

Best wishes,

Jeanette

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * SoundCloud: https://soundcloud.com/jeanette_c
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * GitHub: https://github.com/jeanette-c
  * Twitter: https://twitter.com/jeanette_c_s

You know I'm one of a kind,
There'll never be another me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


--
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here