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? 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; -- peace, love & harmony Atte http://atte.dk | http://myspace.com/attejensen http://anagrammer.dk | http://modlys.dk
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
On 11/3/07, Martin Ahnelöv
if it doesn't work, it's a bug).
Wait.... I just woke up which has been shown to be a bad time to post to the list, but isn't FilterBasic a sort of utility class that the other filters and (some?) delays inherit from but which shouldn't be instantiated on it's own? At any rate, I'm fairly sure FilterBasic is one of the filters that doesn't come with a ready-made .freq() and instead needs coefficients to be set, If that's what you want that would indeed be a very good use of functions but get "Filter" (or one like PoleZero, BiQuad.....) instead. You may also want to get a serious text on DSP, read that until your head hurts, get your local friendly mathematician and get him coffee, listen to him until your head hurts.... ....then most likely decide you are very happy there are people like Ge and Perry who can sort such matters for you ;¬). In the meantime I looked it up; FilterBasic isn't in the Ugen list but "Filter" is and "Filter" is as versatile and open-ended as they come so there is no actual need to instantiate "FilterBasic" at all. Hope that helps, Kas.
lör 2007-11-03 klockan 16:12 +0100 skrev Kassen:
On 11/3/07, Martin Ahnelöv
wrote: If FilterBasic doesn't work, try the more inflexible BPF, instead (But if it doesn't work, it's a bug).
Wait.... I just woke up which has been shown to be a bad time to post to the list, but isn't FilterBasic a sort of utility class that the other filters and (some?) delays inherit from but which shouldn't be instantiated on it's own?
At any rate, I'm fairly sure FilterBasic is one of the filters that doesn't come with a ready-made .freq() and instead needs coefficients to be set, If that's what you want that would indeed be a very good use of functions but get "Filter" (or one like PoleZero, BiQuad.....) instead. You may also want to get a serious text on DSP, read that until your head hurts, get your local friendly mathematician and get him coffee, listen to him until your head hurts....
....then most likely decide you are very happy there are people like Ge and Perry who can sort such matters for you ;¬).
In the meantime I looked it up; FilterBasic isn't in the Ugen list but "Filter" is and "Filter" is as versatile and open-ended as they come so there is no actual need to instantiate "FilterBasic" at all.
Oh, that's right. Thought Filter and FilterBasic were the same thing· Dumb of me. And yes, I'm very glad that Perry and Ge does the serious DSP-work for me :p Gasten
Kassen wrote:
Wait.... I just woke up which has been shown to be a bad time to post to the list, but isn't FilterBasic a sort of utility class that the other filters and (some?) delays inherit from but which shouldn't be instantiated on it's own?
Well, I agree it shouldn't be instantiated (which I didn't do in my example), but isn't the whole idea of a superclass that it can be used for things like this: Allowing interchangeable use of either subclass (in this case BPF, LPF and friends)?
....then most likely decide you are very happy there are people like Ge and Perry who can sort such matters for you ;¬).
I think (hope:-)) you misunderstand my intentions. I just wanted to write a function that changes BPF.freq with call by reference and that also can be used on LPF (and friends)... An I can assure you that I'm extremely happy for LPF, which partly was implemented due to my whining and inability to get predictable results from the biquads. And I've been dancing ever since! I admit that I don't understand much about real, hard-core filter design, so something like BPF is exactly what I need :-)
In the meantime I looked it up; FilterBasic isn't in the Ugen list but "Filter" is and "Filter" is as versatile and open-ended as they come so there is no actual need to instantiate "FilterBasic" at all.
Fortunately I didn't instantiate it, I defined a function that takes one parameter "f" which is of type BasicFilter so that the function can be called with an instance any of BasicFilter's subclasses. Am I right? -- peace, love & harmony Atte http://atte.dk | http://myspace.com/attejensen http://anagrammer.dk | http://modlys.dk
On 11/3/07, Atte André Jensen
write a function that changes BPF.freq with call by reference and that also can be used on LPF (and friends)...
Ah! See? I shouldn't post before having drunk the complete cup of coffee.
Fortunately I didn't instantiate it, I defined a function that takes one parameter "f" which is of type BasicFilter so that the function can be called with an instance any of BasicFilter's subclasses. Am I right?
This makes total and perfect sense as far as I can see, yes.
-- peace, love & harmony
And coffee! :¬) Yours, Kas.
Martin Ahnelöv wrote:
Sure it works! I do it all the time!
Ok, I meant to say that the commented-out line "spork ~ changer2(f.freq)" doesn't work. At least it throws an error here...
If FilterBasic doesn't work, try the more inflexible BPF, instead (But if it doesn't work, it's a bug).
FilterBasic works great as shown in changer(), but I'd like to write a function like changer2() that can takes as parameter a pointer to an Ugens parameter (like "f.freq") and modifies that. Or are we speaking of different things? -- peace, love & harmony Atte http://atte.dk | http://myspace.com/attejensen http://anagrammer.dk | http://modlys.dk
lör 2007-11-03 klockan 20:37 +0100 skrev Atte André Jensen:
Martin Ahnelöv wrote:
Sure it works! I do it all the time!
Ok, I meant to say that the commented-out line "spork ~ changer2(f.freq)" doesn't work. At least it throws an error here...
If FilterBasic doesn't work, try the more inflexible BPF, instead (But if it doesn't work, it's a bug).
FilterBasic works great as shown in changer(), but I'd like to write a function like changer2() that can takes as parameter a pointer to an Ugens parameter (like "f.freq") and modifies that.
Or are we speaking of different things?
I don't realy understand what the problem is, but is this the solution you are looking for? function void changer2(FilterBasic f, float min, float max){ while(true){ Std.rand2f(min,max) => f.freq; 400::ms => now; } } spork ~ changer2(f, 200., 1000.); Hope that helps, Gasten
Martin Ahnelöv wrote:
I don't realy understand what the problem is, but is this the solution you are looking for?
function void changer2(FilterBasic f, float min, float max){ while(true){ Std.rand2f(min,max) => f.freq; 400::ms => now; } }
spork ~ changer2(f, 200., 1000.);
Nah, not really. more like: SndBuf sample => BPF filter => dac; SinOsc sine => dac. function void changer2(float value){ while(true){ Std.rand2f(200,1000) => value; 400::ms => now; } } spork ~ changer2(filter.freq); spork ~ changer2(sine.freq); So a generic function that can be called on an arbitrary property on any ugen, and modify it by call by reference. It would work on any property be it SndBuf.rate or Pitch.shift or SinOsc.freq. I hope this makes my intentions a little more clear. I apologize if my initial posting was unclear :-( -- peace, love & harmony Atte http://atte.dk | http://myspace.com/attejensen http://anagrammer.dk | http://modlys.dk
Hi,
So a generic function that can be called on an arbitrary property on any ugen, and modify it by call by reference. It would work on any property be it SndBuf.rate or Pitch.shift or SinOsc.freq.
Sorry I didn't tune into this thread earlier, as I know exactly the problem.. Chuck does not currently support references to primitives, which makes it impossible to solve this problem. I wrote about it a while ago on the Chuck wiki, and I put it on the Ongoing Feature Request list.. http://wiki.cs.princeton.edu/index.php/References_for_primitives. cheers, Steve
Stephen Sinclair wrote:
Sorry I didn't tune into this thread earlier, as I know exactly the problem.. Chuck does not currently support references to primitives, which makes it impossible to solve this problem. I wrote about it a while ago on the Chuck wiki, and I put it on the Ongoing Feature Request list..
Ok, thanks. I'll solve the problem in other ways (I can think of few) for now. I was just nor sure it it could be done and I was missing something. -- peace, love & harmony Atte http://atte.dk | http://myspace.com/attejensen http://anagrammer.dk | http://modlys.dk
lör 2007-11-03 klockan 20:37 +0100 skrev Atte André Jensen:
Martin Ahnelöv wrote:
Sure it works! I do it all the time!
Ok, I meant to say that the commented-out line "spork ~ changer2(f.freq)" doesn't work. At least it throws an error here...
If FilterBasic doesn't work, try the more inflexible BPF, instead (But if it doesn't work, it's a bug).
FilterBasic works great as shown in changer(), but I'd like to write a function like changer2() that can takes as parameter a pointer to an Ugens parameter (like "f.freq") and modifies that.
Or are we speaking of different things?
Ah, wait! Don't care about my last message. I didn't read carefully enough. I don't believe it's possible to do the thing that you are looking for that way. You best shot is o create a getValue()-function that do all the calculation, and then create value2freq(), value2q(), value2gain etc (that calls getValue()) when you need them. Something that could make this easier is a way to insert arbitrary code into spork-statement: spork ~ { /*mycode*/ }; but that's probably not here in the next few releases. Gasten
participants (4)
-
Atte André Jensen
-
Kassen
-
Martin Ahnelöv
-
Stephen Sinclair