calf-studio-gear / calf

Developers repository of Calf Studio Gear. Expect some issues when using it for production.
http://calf-studio-gear.org
GNU Lesser General Public License v2.1
689 stars 95 forks source link

Analyzer/BassEnhancer crash if 2nd audio output is not connected #278

Closed JohannesLorenz closed 10 months ago

JohannesLorenz commented 4 years ago

Hello,

CALF Analyzer (current master, 4e699444ac19f741781c8978b0bbb513a6a12ea7) seems to write on the second audio output even if that one is not connected:

Thread 13 "Mixer::fifoWrit" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffd9cea640 (LWP 498077)]
0x00007fffbde90f3a in calf_plugins::analyzer_audio_module::process (this=0x55555cd974d0, offset=0, numsamples=256, inputs_mask=4294967295, 
    outputs_mask=4294967295) at modules_tools.cpp:516
516             outs[1][i] = R;
(gdb) bt
#0  0x00007fffbde90f3a in calf_plugins::analyzer_audio_module::process(unsigned int, unsigned int, unsigned int, unsigned int)
    (this=0x55555cd974d0, offset=0, numsamples=256, inputs_mask=4294967295, outputs_mask=4294967295) at modules_tools.cpp:516
#1  0x00007fffbde98386 in calf_plugins::audio_module<calf_plugins::analyzer_metadata>::process_slice(unsigned int, unsigned int)
    (this=0x55555cd974d0, offset=0, end=256) at ./calf/giface.h:628
#2  0x00007fffbde7b872 in calf_plugins::lv2_instance::run(unsigned int, bool) (this=0x55555cc6d780, SampleCount=256, has_simulate_stereo_input_flag=true)
    at lv2wrap.cpp:164
#3  0x00007fffbdf3345c in calf_plugins::lv2_wrapper<calf_plugins::analyzer_audio_module>::cb_run(void*, unsigned int)
    (Instance=0x55555cc6d780, SampleCount=256) at ./calf/lv2wrap.h:225
#4  0x0000555555819007 in lilv_instance_run(LilvInstance*, uint32_t) (instance=0x55555cc5ce30, sample_count=256) at /usr/include/lilv-0/lilv/lilv.h:1705

In that backtrace, outs[1] was a nullptr, because the second audio output was lv2:connectionOptional - see the generated Analyzer.ttl:

[
        a lv2:OutputPort ;
        a lv2:AudioPort ;
        lv2:index 3 ;
        lv2:symbol "out_r" ;
        lv2:name "Out R" ;
        lv2:portProperty lv2:connectionOptional ;
        lv2:designation pg:right ;
        pg:group :out ;
]

In our case, we got a segmentation fault. Can you please check if you can fix it?

Thanks to @zonkmachine from LMMS for testing Analyzer.

zonkmachine commented 3 years ago

All modules from modules_dist have the same issue: Bass Enhancer Crusher Exciter Saturator Tape Simulator Vinyl

These modules also share this problem: Stereo Tools Transient Designer Compensation Delay Line

JohannesLorenz commented 3 years ago

Some research: outs[1] occurs 109 times. Instead of making an if around each of those (and hope that future PRs will also do that), I would rather recommend to initialize outs[0], outs[1], etc. to point to some dummy buffers. What do you think @boomshop ?

zonkmachine commented 1 year ago

CALF Analyzer (current master, 4e69944) seems to write on the second audio output even if that one is not connected:

But I can load this, and the other pluggins mentioned here, just fine on Ardour.

JohannesLorenz commented 1 year ago

But I can load this, and the other pluggins mentioned here, just fine on Ardour.

Does Ardour load it as 2 mono processors or 1 stereo processor?

zonkmachine commented 1 year ago

Looks like one stereo processor to me. This is what the pinouts look like with a dedicated monoeffect (GxAmplifier-X) for comparison. ardourpinout

JohannesLorenz commented 1 year ago

That's why the bug report mentions that it happens when the second port is not connected.

My plan is to fix this in a few weeks and then we can test if they all work with LMMS.

zonkmachine commented 1 year ago

That's why the bug report mentions that it happens when the second port is not connected.

Sorry, I didn't get that. My point is, if it doesn't crash in Ardour but it does in LMMS, then maybe LMMS could be fixed to not crash in these cases? Whether or not there is an error in Calf. There could very well be other plugins out there with the same issue.

JohannesLorenz commented 1 year ago

We can fix it in LMMS to let LMMS open the stereo version instead of 2 mono versions. But we can also fix it in calf (to not write stereo if used as mono). Both will be done.