videolabs / libspatialaudio

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

2nd order Binauralizer + MIT HRTF #28

Open joshkopecek opened 3 years ago

joshkopecek commented 3 years ago

Using the CAmbisonicBinauralizer, it works fine with 1st order. However, when I come to configure 2nd order, it fails because in AmbisonicLib.cpp, the speakers are initialised like this - note the Elevation of Loudspeaker 1 as -69.1º.

case kAmblib_Dodecahedron:
        // This arrangement is used for second and third orders
        m_nSpeakers = 20;
        m_pAmbSpeakers = new CAmbisonicSpeaker[m_nSpeakers];
        // Loudspeaker 1
        polPosition.fElevation = DegreesToRadians(-69.1f);
        polPosition.fAzimuth = DegreesToRadians(90.f);
        m_pAmbSpeakers[0].Configure(m_nOrder, m_b3D, 0);
        m_pAmbSpeakers[0].SetPosition(polPosition);
        // Loudspeaker 2
        polPosition.fAzimuth = DegreesToRadians(-90.f);
        m_pAmbSpeakers[1].Configure(m_nOrder, m_b3D, 0);
        m_pAmbSpeakers[1].SetPosition(polPosition);
        …

then when loading the MIT HRTF in mit_hrtf_lib.c:

unsigned int mit_hrtf_availability(int azimuth, int elevation, unsigned int samplerate)
{
    if(elevation > 90 || elevation < -40)
        return 0;

    if(azimuth > 180 || azimuth < -180)
        return 0;

    if(samplerate == 44100)
        return MIT_HRTF_44_TAPS;
    else if(samplerate == 48000)
        return MIT_HRTF_48_TAPS;
    else if(samplerate == 88200)
        return MIT_HRTF_88_TAPS;
    else if(samplerate == 96000)
        return MIT_HRTF_96_TAPS;

    return 0;
}

It fails because the Elevation of the speaker is below -40º, which seems like it is intended for MIT HRTF.

If I disable this check, it fails further down because the filters/taps are not available for below -40º.

The speaker arrangement is automatically configured as a kAmblib_Dodecahedron because of 2nd order in CAmbisonicBinauralizer.

Any help here or pointers as to how to set up 2nd (or 3rd?) order would be greatly appreciated.

joshkopecek commented 3 years ago

FYI, I'm going to try using SOFA instead with some data from York Uni's SADIE database

joshkopecek commented 3 years ago

Just to let you know I've had success with SOFA.

It might be good to put some info into the readme detailing that:

  1. MIT HRTF does not work with > FOA with the Binauralizer.
  2. libmysofa is required to use the SOFA files (along with a .sofa file, although libmysofa includes one).

Happy to PR the readme, if needed.

jbkempf commented 3 years ago

@joshkopecek yes, more documentation and information would be nice.