[chuck-users] changing a value with a function

Martin Ahnelöv operagasten at gmail.com
Sat Nov 3 06:55:45 EDT 2007


fre 2007-11-02 klockan 17:07 +0100 skrev Atte André Jensen:
> Hi
> 
> I'm trying to change a value of something (in this case BPF.freq with a 
> function. I'd like to write a function that can be sporked on just aout 
> any value, but I can't figure out how.
> 
> Below changer() works, but only works on filters freq parameter. 
> changer2() obviously doesn't work. Can something like this be done? 
> Could the parameter for a ugen be passed by reference?

Sure it works! I do it all the time!


> SndBuf s => BPF f => dac;
> s.read("beat.wav");
> 10 => f.Q;
> 4200 => f.freq;
> 5 => f.gain;
> function void loop(SndBuf s){
>      while(true){
>          0 => s.pos;
>          s.samples()::samp => now;
>      }
> }
> function void changer(FilterBasic f){
>      while(true){
>          Std.rand2f(200,1000) => f.freq;
>          400::ms => now;
>      }
> }
> function void changer2(float value){
>      while(true){
>          Std.rand2f(200,1000) => value;
>          400::ms => now;
>      }
> }
> spork ~ loop(s);
> spork ~ changer(f);
> //spork ~ changer2(f.freq);
> 1::week => now;
> 

If FilterBasic doesn't work, try the more inflexible BPF, instead (But
if it doesn't work, it's a bug). 

Gasten



More information about the chuck-users mailing list