heuermh / lick

LiCK, Library for ChucK
GNU General Public License v3.0
147 stars 21 forks source link

EnvelopeFollower last() method #53

Open boonier opened 6 months ago

boonier commented 6 months ago

There seems to be some problem with naming the method:

fun float last() (line 48)

When I try to plug the value from that method into a ugen, I get an instance VM crash.

When renaming to lastT() for example, the EnvelopeFollower class functions as normal. Perhaps there is a conflict with the inherited Chugraph class' last() method?

adc => EnvelopeFollower env => blackhole;
SinOsc s => dac;

while (true)
{
    100::ms => now;
   env.last() => s.gain;
    <<<env.last()>>>;
}
boonier commented 6 months ago

So as to make this easy to test, the following will crash ChucK (for me).

Seems like a seg fault

class EnvelopeFollower extends Chugraph
{
    20::ms => dur _rate;

    Gain _gain;
    OnePole _pole;
    Step _step;

    inlet => _gain;
    inlet => _gain;
    _gain => _pole => blackhole;
    _step => outlet;

    {
        3 => _gain.op;
        0.99 => _pole.pole;

        spork ~ _updateAtRate();
    }

    fun float last()
    {
        return _step.last();
    }

    fun dur rate()
    {
        return _rate;
    }

    fun dur rate(dur d)
    {
        d => _rate;
        return d;
    }

    fun void _updateAtRate()
    {
        while (true)
        {
            _pole.last() => _step.next;
            _rate => now;
        }
    }
}

adc => EnvelopeFollower env => blackhole;
SinOsc s => dac;

while (true)
{
    100::ms => now;
    env.last() * 200 => s.freq;
    <<<env.last()>>>;
}
heuermh commented 6 months ago

Thank you for the follow up, @boonier! I can reproduce on my end

$ chuck crash.ck
Assertion failed: (func->native_func_kind == ae_fp_mfun), function execute,
file chuck_instr.cpp, line 5299.
Abort trap: 6

Since _step => outlet in your example I suppose there is no need to override last()? If I comment out the method declaration it runs fine

$ chuck fixed.ck
0.004344 :(float)
0.022559 :(float)
0.000005 :(float)
0.000015 :(float)
0.000000 :(float)
...
heuermh commented 6 months ago

Odd the EnvelopeFollower example in LiCK does not crash for me

$ chuck --loop
...
[chuck]: (VM) sporking incoming shred: 1 (envFollowerExample.ck)...
0.000001 :(float)
0.000000 :(float)
0.000000 :(float)
0.000002 :(float)
0.000000 :(float)
...
$ chuck + import.ck
$ chuck + examples/envFollowerExample.ck
boonier commented 6 months ago

hmm I have no idea...

I have a question, what does the Step do in this class - is it like a sample and hold?

heuermh commented 5 months ago

Yep, exactly like a sample and hold.