videolabs / libspatialaudio

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

Added automatic loading of preset coefficients #19

Closed peterStitt closed 4 years ago

peterStitt commented 4 years ago

Hello,

I noticed that the improved decoders for stereo, 5.1 and 7.1 were not actually being loaded in the library even though the coefficients were included. This commit adds a check so that if the loudspeaker array matches the layouts as defined in VLC then the presets will be loaded.

These presets are a significant improvement compared to the ones calculated by the library. For example, in VLC, with the current stereo decoder the sound decreases significantly in level when you turn the 360 to face the opposite direction to the sound source.

There is one small change to how the library should be used. In the case where a preset it loaded the shelf filters in AmbisonicProcessor.cpp should not be used. I have added an option to CAmbisonicProcessor to switch this off. Use case should now be something like:

    // Ambisonic processor for rotation and optional filtering
    CAmbisonicProcessor myProcessor;
    myProcessor.Configure(order, true, N_BLOCK_SIZE, 0);
    Orientation ori(DegreesToRadians(90.f), 0.f, 0.f);
    myProcessor.SetOrientation(ori);
    myProcessor.Refresh();

    // Ambisonic decoder
   CAmbisonicDecoder myDecoder;
   // Load a 5.1 loudspeaker configuration
   myDecoder.Configure(order, true, kAmblib_51, 6);

    // Ambisonic processor for rotation and optional filtering
    // If a preset is loaded in the decoder then we do not want the psychoacoustic filtering to be performed
    myProcessor.Process(&myBFormat, myBFormat.GetSampleCount(), !myDecoder.GetPresetLoaded());

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

It might be worth taking the shelf filters and putting them in their own class (CAmbisonicShelfFilters?) rather than having them in AmbisonicProcessing so it is clear that the filtering is happening.

It would be great if these changes (or something similar) could be included in the library to make sure it is doing the highest possible decoding possible to the most common loudspeaker array.

jbkempf commented 4 years ago

Thanks for the MR. We need to review that :)