[chuck-users] Modulation of parameters "by hand"? Does ChucK have a function reference data type?

Johnathan Bell enigma.0za at gmail.com
Thu Jun 9 08:21:25 EDT 2011


I'm trying to create a generic "modulation" function where I can give it some parameters to set up the modulation and a property to modulate. My current way of thinking would require passing a function object into the shred so that the parameter to be modulated can be chosen at the time of the function calling... Now I know already that I can't do something like the following:

--code--
// A failed attempt at tremolo

SinOsc osc1 => Gain master => dac;

440 => osc1.freq;

SinOsc lfo => master.gain;

5 => lfo.freq;
.3 => lfo.gain;
--/code--

So thus I set up this function:

--code--
fun void tremolo(Gain noteGain)
{
    SinOsc lfo => blackhole;
    5.75 => lfo.freq;
    .3 => lfo.gain;

    while (true)
    {
        1-lfo.last() => noteGain.gain;
        // Assume "resolution" is a dur such as 10::ms, it is the resolution of our modulation
        resolution => now;
    }
}
--/code--

And spork it with a gain object to modify... That works great, but I'll need to code a separate function for every single possible parameter that I'd want to modulate, so is there a way of specifying the specific parameter on the function call instead of the whole object, for instance, the prototype could be:

--code--
fun void modulate(FunctionObject param)
--/code--

And then the updated values would (in theory) be ChucK'ed directly to that "param" instead of object.parameter? I tried setting it up this way but I don't seem to know the object type for passing a function reference, if there is one. Or maybe someone else has a better idea that I haven't thought of?

- JB


More information about the chuck-users mailing list