kronihias / ambix

cross-platform Ambisonic VST, LV2 plug-ins with variable order for use in Digital Audio Workstations like Reaper or Ardour or as Jack standalone applications
GNU General Public License v2.0
235 stars 34 forks source link

"ambiX warp" crashes when ambi I/O order is set to zero #31

Open NilsSchreiber opened 3 years ago

NilsSchreiber commented 3 years ago

Hi,

after building the plug-in and loading it in Reaper the plug-in crashes Reaper when either the "Ambi In order" or "Ambi Out order" is set to 0. I think there is a bug in the "ShChebyshev.cpp" (for me line 52 and 53):

sinus(1) = -sin(phi); // for mtx_sph_h compatibility use -sin
cosinus(1) = cos(phi);

If order is 0 there will be no 1st but only the 0th element since sinus and cosinus are defined as an n_max+1 = 1-length-array:

Eigen::VectorXd sinus(n_max+1); // temporary storage
Eigen::VectorXd cosinus(n_max+1); 

Could I just wrap it inside a condition catching the case order 0 or will this change something dramatically in further computations? The code would be:

sinus(0) = 0.f;
cosinus(0) = 1.f;

if (n_max > 0){
    sinus(1) = -sin(phi); // for mtx_sph_h compatibility use -sin
    cosinus(1) = cos(phi);

    // chebyshev recursion for multiples of argument
    for (int i = 2; i <= n_max; i++) {

        cosinus(i) = 2 * cosinus(1) * cosinus(i-1) - cosinus(i-2);
        sinus(i) = 2 * cosinus(1) * sinus(i-1) - sinus(i-2);

    }
}

Thank you!

Best, Nils

PS: Crash report:

Thread 11 Crashed:: reaper/mediaafx
0   libsystem_kernel.dylib          0x00007fff641cbb66 __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff64396080 pthread_kill + 333
2   libsystem_c.dylib               0x00007fff641271ae abort + 127
3   libsystem_c.dylib               0x00007fff640ef1ac __assert_rtn + 320
<<< HERE IS THE INTERESTING PART  >>>
4   com.kronlachner.ambix_warp      0x000000010f1b74bc Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>::operator()(long) + 124 (DenseCoeffsBase.h:425)
5   com.kronlachner.ambix_warp      0x000000010f226ab3 ShChebyshev::Calc(int, double) + 339 (ShChebyshev.cpp:53)
6   com.kronlachner.ambix_warp      0x000000010f227b7a SphericalHarmonic::Init(int, bool, bool) + 218 (SphericalHarmonic.cpp:49)
7   com.kronlachner.ambix_warp      0x000000010f1b5fad Ambix_warpAudioProcessor::calcParams() + 3149
<<< BEGIN INTERESTING PART>>>
8   com.kronlachner.ambix_warp      0x000000010f1b77da void Ambix_warpAudioProcessor::compute<float>(juce::AudioBuffer<float>&, juce::MidiBuffer&) + 90 (PluginProcessor.cpp:571)
9   com.kronlachner.ambix_warp      0x000000010f1b776e Ambix_warpAudioProcessor::processBlock(juce::AudioBuffer<float>&, juce::MidiBuffer&) + 126 (PluginProcessor.cpp:556)
10  com.kronlachner.ambix_warp      0x000000010f1b1c27 void JuceVSTWrapper::internalProcessReplacing<float>(float**, float**, int, JuceVSTWrapper::VstTempBuffers<float>&) + 1303 (juce_VST_Wrapper.cpp:467)
11  com.kronlachner.ambix_warp      0x000000010f1b16e5 JuceVSTWrapper::processReplacing(float**, float**, int) + 149 (juce_VST_Wrapper.cpp:525)
12  com.kronlachner.ambix_warp      0x000000010f1a7e73 JuceVSTWrapper::processReplacingCB(VstEffectInterface*, float**, float**, int) + 51 (juce_VST_Wrapper.cpp:530)
13  com.cockos.reaper               0x000000010609d6af VST_HostedPlugin::ProcessSamples(int, double*, int, int, int, double, midi_List*, bool*, double, double, double, bool) + 10191
14  com.cockos.reaper               0x00000001060c5abd FxDsp::processSamples(int, double*, int, int, int, double*, midi_List*, double, bool, double) + 4621
15  com.cockos.reaper               0x00000001060db205 FxChain::ProcessSamples(int, double*, int, int, int, int, double, midi_List*, double, bool) + 549
16  com.cockos.reaper               0x0000000105dc8b35 MediaTrack::RenderSamples_nocache(double, long long, double*, int, int, double, MediaTrack* const*, int, int*, bool, int, int, bool*, SyncSMP_Context*) + 22517
17  com.cockos.reaper               0x0000000105dcefc0 MediaTrack::RenderSamples(double, long long, int, Track_RS_Output*, int, double, MediaTrack* const*, int, midi_List*, int, int, int, int, int, MediaTrack::Track_SendRec*, bool*, SyncSMP_Context*) + 864
18  com.cockos.reaper               0x0000000105dd5e1e MediaTrack::RunWorkThread(int, double, MediaTrack* const*, int) + 2094
19  com.cockos.reaper               0x0000000105e3ec92 WorkerThreadInst::threadProc(void*) + 1026
20  com.cockos.reaper               0x0000000106271c20 __threadproc(void*) + 32
21  libsystem_pthread.dylib         0x00007fff64393661 _pthread_body + 340
22  libsystem_pthread.dylib         0x00007fff6439350d _pthread_start + 377
23  libsystem_pthread.dylib         0x00007fff64392bf9 thread_start + 13