videolabs / libspatialaudio

Ambisonic encoding / decoding and binauralization library in C++
Other
192 stars 37 forks source link

SIGSEGV when running the example provided in the Readme #37

Open jrialland opened 1 year ago

jrialland commented 1 year ago

Using the tag 0.3.0, I have extracted this example and tried to run it :

#include <catch2/catch_all.hpp>
#include <AmbisonicEncoder.h>
#include <AmbisonicDecoder.h>

// Just some demo code from https://github.com/videolabs/libspatialaudio
TEST_CASE("libspatialaudio smoke test", "[libspatialaudio]")
{
    float sinewave[512];
    for(int ni = 0; ni < 512; ni++)
        sinewave[ni] = (float)sin((ni / 128.f) * (M_PI * 2));

    // CBFormat as 1st order 3D, and 512 samples
    CBFormat myBFormat;

    // Ambisonic encoder, also 3rd order 3D
    CAmbisonicEncoder myEncoder;
    myEncoder.Configure(1, true, 0);

    // Set test signal's position in the soundfield
    PolarPoint position;
    position.fAzimuth = 0;
    position.fElevation = 0;
    position.fDistance = 5;
    myEncoder.SetPosition(position);
    myEncoder.Refresh();

    // Encode test signal into BFormat buffer
    myEncoder.Process(sinewave, 512, &myBFormat);

    // Ambisonic decoder, also 1st order 3D, for a 5.0 setup
    CAmbisonicDecoder myDecoder;
    myDecoder.Configure(1, true, kAmblib_50, 5);

    // Allocate buffers for speaker feeds
    float** ppfSpeakerFeeds = new float*[5];
    for(int niSpeaker = 0; niSpeaker < 5; niSpeaker++)
        ppfSpeakerFeeds[niSpeaker] = new float[512];

    // Decode to get the speaker feeds
    myDecoder.Process(&myBFormat, 512, ppfSpeakerFeeds);

    // De-allocate speaker feed buffers
    for(int niSpeaker = 0; niSpeaker < 5; niSpeaker++)
        delete [] ppfSpeakerFeeds[niSpeaker];
    delete [] ppfSpeakerFeeds;
}

When I run this test, It segfaults. A gdb session tells me that it crashed here :

    at _deps/libspatialaudio-src/source/AmbisonicEncoder.cpp:48
48              pfDst->m_ppfChannels[niChannel][niSample] = pfSrc[niSample] * m_pfCoeff[niChannel];
jbkempf commented 1 year ago

Which pointer is NULL?

jrialland commented 1 year ago

(gdb) p pfDst->m_ppfChannels $4 = std::unique_ptr<float *[]> = {get() = 0x0}

SongLi89 commented 1 year ago

I have same issues when running example code. is there a lack of reserve the memory? can some help to fix the issue?