grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.53k stars 319 forks source link

Crash in smartkeyboard Android app with amp_follower_ar in DSP #319

Open Apisov opened 5 years ago

Apisov commented 5 years ago

Here is the code of dsp that crashes

declare options "[midi:on][nvoices:12]";
declare interface "SmartKeyboard{
    'Number of Keyboards':'2',
    'Max Keyboard Polyphony':'12',
    'Keyboard 0 - Number of Keys':'4',
    'Keyboard 1 - Number of Keys':'4',
    'Keyboard 0 - Lowest Key':'60',
    'Keyboard 1 - Lowest Key':'67',
    'Keyboard 0 - Scale':'2',
    'Keyboard 1 - Scale':'2',
    'Rounding Mode':'0'
}";
import("stdfaust.lib");
freq = hslider("freq",440,50,1000,0.01);
gain = an.amp_follower_ar(0.02,0.02);
gate = button("gate") : en.adsr(0.01,0.01,0.9,0.1);
timbre(f) = os.lf_saw(f/3)*0.5 + os.triangle(f+2)*0.25 + os.square(f+6)*0.125;
process = gain*gate*timbre(freq)*0.5 <: _,_;
effect = dm.zita_light;

If you change gain = an.amp_follower_ar(0.02,0.02); to hslider("gain",0.5,0,1,0.01); it work okay.

Sometimes it crashes after granting permission to the microphone here: https://github.com/grame-cncm/faust/blob/8ae953a7630b362f059e6ae9223cc6c682f9e4f8/architecture/smartKeyboard/android/app/src/main/java/com/ccrma/faust/MainActivity.java#L109

But the main issue I have is over here: https://github.com/grame-cncm/faust/blob/8ae953a7630b362f059e6ae9223cc6c682f9e4f8/architecture/smartKeyboard/android/app/src/main/java/com/ccrma/faust/MultiKeyboard.java#L629

I don't know why but because of the an.amp_follower_ar it doesn't see dsp as polyphonic so it returns 0 here:

        /*
         * newVoice()
         * Instantiate a new voice and returns the corresponding mapUI.
         */
        MapUI* newVoice()
        {
            if (fPolyDSP) {
                return fPolyDSP->newVoice();
            } else {
                return 0;
            }
        }

I couldn't find any easy reason so I'm leaving for you all my notes and things that I've found.

sletz commented 5 years ago

Can you check if replacing declare options "[midi:on][nvoices:12]"; by declare voices "12" helps?