Csound Csound-dev Csound-tekno Search About

[Csnd] how to set a timer...

Date2010-09-10 03:48
Fromvictor
Subject[Csnd] how to set a timer...
Dear list

I'd like to ask advice for a time problem

Thanks to some help i got here, i could make a dynamic filter : high pass
filter when a certain amplitude of a .wav file is reached, and a low pass
when the amplitude is under the amplitude threshold; furthermore i added a
small 20 msec delay between the the threshold and the shift of the filters; 

my question is : i'd like to add something that "freezes" the filter for a
few time (say 0.5 sec for exeample) after its change, to prevent constant
changes of filter when the music has an amplitude close to the threshold...
in other words, when a filter i set, i want it to stay in place for at least
0.5 sec (even if the amplitude threslhold is reached)

i couldn't figure out ho to make it; as far s i understood, neither delay or
delayk, or clockon, or time, ou timeinsts were helpfull; i've also
considered loops... but i couldn't succeed; a possible way could be, in my
case to update the value of krms (obtained via rms opcode) every half
second, but i could loose some precicion regarding the shift of the filters;
regarding clockon, after "clockon 1", and "readclock 1", the only value i
get is 0.0000 every time....

thank you

victor



-odac ; For Non-realtime ouput leave only the line below:
; -o dispfft.wav -W ;;; for file output any platform



sr = 44100
ksmps = 32
nchnls = 2

instr 1
asig diskin2 "/home/victor/Bureau/violin_mono.wav", 1, 0, 1, 0, 32
krms rms asig
clockon 1
ithreshold init 1500
icutoffh init 8000
icutoffl init 2000
krmsdelay vdelayk krms, 0.2, 5
if (krmsdelay > ithreshold && krms > ithreshold) then
		aout2 butterhp  asig, icutoffh
		aout3 butterhp  aout2, icutoffh
		aout4 balance aout3, asig
else
	aout3 butterlp  asig, icutoffl
	aout4 balance aout3, asig
endif 
continue:
outs aout4, aout4
dispfft aout4, 0.1, 512
printk 0.5, krms
printk 0.5, itime
endin


; Play Instrument #1 for three seconds.
i 1 0 481
e


Date2010-09-10 04:48
FromSteven Yi
Subject[Csnd] Re: how to set a timer...
Hi Victor,

You may want to try using two variables, one for state and one for
count. The state variable would be to designate if you should be using
a high-pass or a low-pass filter, and the counter could be used to
designate if it's been x amount of time to wait.  So something like:

kstate init 0
kcounter init 0

itimethreshold = (.5 * sr) / ksmps ; calculate number of ksmps in time
the threshold should be

if([insert logic here to detect amplitude threshold] && (kcounter >
itimthreshold)) then
  kstate = 1
  kcounter = 0 ; reset counter on state change
else if(kcounter > itimethreshold) then
  kstate = 0
  kcounter = 0 ; reset counter on state change
endif

if (kstate == 0) then
  ...high pass...
else
  ...low pass...
endif

kcount = kcount + 1

I think the above should work should delay changing of state for .5
seconds after a state change. (Haven't tested, but hopefully this
helps.)

Good luck!
steven


On Thu, Sep 9, 2010 at 10:48 PM, victor  wrote:
>
> Dear list
>
> I'd like to ask advice for a time problem
>
> Thanks to some help i got here, i could make a dynamic filter : high pass
> filter when a certain amplitude of a .wav file is reached, and a low pass
> when the amplitude is under the amplitude threshold; furthermore i added a
> small 20 msec delay between the the threshold and the shift of the filters;
>
> my question is : i'd like to add something that "freezes" the filter for a
> few time (say 0.5 sec for exeample) after its change, to prevent constant
> changes of filter when the music has an amplitude close to the threshold...
> in other words, when a filter i set, i want it to stay in place for at least
> 0.5 sec (even if the amplitude threslhold is reached)
>
> i couldn't figure out ho to make it; as far s i understood, neither delay or
> delayk, or clockon, or time, ou timeinsts were helpfull; i've also
> considered loops... but i couldn't succeed; a possible way could be, in my
> case to update the value of krms (obtained via rms opcode) every half
> second, but i could loose some precicion regarding the shift of the filters;
> regarding clockon, after "clockon 1", and "readclock 1", the only value i
> get is 0.0000 every time....
>
> thank you
>
> victor
>
> 
> 
> -odac ; For Non-realtime ouput leave only the line below:
> ; -o dispfft.wav -W ;;; for file output any platform
> 
> 
>
> sr = 44100
> ksmps = 32
> nchnls = 2
>
> instr 1
> asig diskin2 "/home/victor/Bureau/violin_mono.wav", 1, 0, 1, 0, 32
> krms rms asig
> clockon 1
> ithreshold init 1500
> icutoffh init 8000
> icutoffl init 2000
> krmsdelay vdelayk krms, 0.2, 5
> if (krmsdelay > ithreshold && krms > ithreshold) then
>                aout2 butterhp  asig, icutoffh
>                aout3 butterhp  aout2, icutoffh
>                aout4 balance aout3, asig
> else
>        aout3 butterlp  asig, icutoffl
>        aout4 balance aout3, asig
> endif
> continue:
> outs aout4, aout4
> dispfft aout4, 0.1, 512
> printk 0.5, krms
> printk 0.5, itime
> endin
> 
> 
> ; Play Instrument #1 for three seconds.
> i 1 0 481
> e
> 
> 
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/how-to-set-a-timer-tp2834447p2834447.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Date2010-09-10 12:32
Fromvictor
Subject[Csnd] Re: how to set a timer...
thank you Steven, that helped!

i'm sure filter shift is "frozen" for exactly 0.5 sec, but it stabilizes the
whole thing a lot, which is what i was looking for; i'll try to measure more
precisely if i can

here is the complete code; and thanks again

vic




-odac ; For Non-realtime ouput leave only the line below:
; -o dispfft.wav -W ;;; for file output any platform



sr = 44100
ksmps = 32
nchnls = 2

instr 1
asig diskin2 "/home/victor/Bureau/violin_mono.wav", 1, 0, 1, 0, 32
p3 filelen "/home/victor/Bureau/violin_mono.wav"
krms rms asig
ithreshold init 1500 ; cutoff amplitude
icutoffh init 8000 ; cutoff high pass filter
icutoffl init 2000 ;cutoff low pass filter
kstate init 0
kcounter init 0

itimethreshold = (1 * sr)/ksmps ; 
kretard init 0.2
krmsdelay vdelayk krms, kretard, 5 

if (krmsdelay > ithreshold && kcounter > itimethreshold) then
	kstate = 1
	kcounter = 0
elseif (kcounter > itimethreshold) then
	kstate = 0
	kcounter = 0
endif

if (kstate == 1) then ; high pass filter
	aout2 butterhp  asig, icutoffh
	aout3 butterhp  aout2, icutoffh
	aout4 balance aout3, asig
else ; low pass filter
	aout3 butterlp  asig, icutoffl
	aout4 balance aout3, asig
endif
kcounter = kcounter + 1
outs aout4, aout4
dispfft aout4, 0.1, 512
printk 0.5, krms
endin


; Play Instrument #1 for three seconds.
i 1 0 "p3"
e