OpenAL not playing stereo audio file content properly

I was doing tests between the fmod and openal audio libs, and found that openal playback sounded notably muddier (worse) than fmod playback (which sounded exactly like the source audio file).

I couldn’t change any settings available in the panda3d config (I even tried some things in the panda OpenAL audio manager c++ source files) to fix this, but I did concretely determine that stereo playback using OpenAL is messed up.

I created a music file with only samples in the left channel. Playing back the audio with the fmod lib loaded produces the expected result: I only hear sound coming out of the left headphone speaker, and none on the right. But playing back with openal loaded, I hear sound from both speakers, but it’s slightly quieter in the right channel (where there should be no audio).

I’m not familiar enough with OpenAL to know if this is just a limitation with the library or how Panda3D is implementing it, but I would assume OpenAL could perform the basic function of playing back a stereo file properly.

I have already tried setting the output channels config to 2 and I can verify with debug prints that the openal audio manager class does recognize that the file uses 2 channels.

Does anyone have any more insight on this, and how to maybe get openal to play the file back properly?

Thanks

Update: I compiled OpenAL-Soft latest source and found the same messed up behavior when using their sample playback executable. So it seems to not be a problem with panda! stereo audio file playback does not properly match input file · Issue #825 · kcat/openal-soft · GitHub

You didn’t specify how you are using the audio file. I guess you need to use loadSfx()

For me, it works as expected.

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        base.accept("p", self.play)
        self.sound = base.loader.loadSfx("test.ogg")

    def play(self):
        self.sound.play()

app = MyApp()
app.run()

test.zip (79.8 KB)

I can only hear the sound in the left speaker.

Hmm… On the contrary, trying the example posted by serega just above, I am hearing some of the audio in my right earbud.

(And a quick check of the audio-file by playing it in an external application does confirm that it plays only on the left.)

Could it be a platform-specific bug? I’m using Ubuntu Linux 18.04.6.

Check the github link in my above post. It has to do with HRTF being enabled by default, which only affects output when OpenAL detects that the output device is headphones.

1 Like

Aaah, I see! (The answer given there wasn’t present when I looked earlier, I think.)

I will admit, the way that it played did sound good.

Well, fair! That pretty much clears it up, I think! :slight_smile:

I am using Windows 10 and there is no difference in headphones or without headphones. Maybe the thing is, I have an external sound card.

1 Like

Interesting, do you think you could change your notify-level-audio and see if it outputs that you’re using OpenAL-Soft still instead of maybe the hardware implementation? Or maybe because your sound card is the device, it can’t tell through the sound card that you’re using headphones versus speakers. The latter sounds more plausible but I’m just guessing here lol.

Either way, I’m thinking of making the argument that HRTF should be disabled in openal soft by default, as it’s an extra layer of processing that is not exactly expected (and therefore, not anticipated when creating/mixing music in a specific way for a game). I’m also struggling to find a way to disable HRTF at all through panda. I will be digging more into this soon.

1 Like
:audio(debug): create_AudioManager()
  audio_library_name="p3openal_audio"
:audio(debug):   dl_name="libp3openal_audio.so"
:audio(debug): symbol of get_audio_manager_func_openal_audio = 00007FF818A6FF60
:audio(debug): Create_OpenALAudioManager()
:audio(debug): All OpenAL devices:
:audio(debug):   OpenAL Soft on Line (Steinberg UR22mkII ) [default]
:audio(debug): OpenAL drivers:
:audio(debug):   OpenAL Soft [default]
:audio: Using default OpenAL device
:audio(debug): ALC_DEVICE_SPECIFIER:OpenAL Soft
:audio(debug): AL_RENDERER:OpenAL Soft
:audio(debug): AL_VENDOR:OpenAL Community
:audio(debug): AL_VERSION:1.1 ALSOFT 1.19.1
:audio(debug): create_AudioManager()
  audio_library_name="p3openal_audio"
:audio(debug): Create_OpenALAudioManager()
:audio(debug): ALC_DEVICE_SPECIFIER:OpenAL Soft
:audio(debug): AL_RENDERER:OpenAL Soft
:audio(debug): AL_VENDOR:OpenAL Community
:audio(debug): AL_VERSION:1.1 ALSOFT 1.19.1
:audio(debug): Creating: test.ogg
:audio(debug):   - Rate: 44100
:audio(debug):   - Channels: 2
:audio(debug):   - Length: 5.53846
:audio(debug): test.ogg: loading as sample
:audio(debug): Decrementing: test.ogg 0

Here you can see what you are interested in.

:audio(debug): create_AudioManager()
  audio_library_name="p3openal_audio"
:audio(debug):   dl_name="libp3openal_audio.so"
:audio(debug): symbol of get_audio_manager_func_openal_audio = 00007FF8162EFF60
:audio(debug): Create_OpenALAudioManager()
:audio(debug): All OpenAL devices:
:audio(debug):   OpenAL Soft on ╨Ф╨╕╨╜╨░╨╝╨╕╨║╨╕ (Bloody Gaming Audio Device) [default]
:audio(debug):   OpenAL Soft on Line (Steinberg UR22mkII )
:audio(debug): OpenAL drivers:
:audio(debug):   OpenAL Soft [default]
:audio: Using default OpenAL device
:audio(debug): ALC_DEVICE_SPECIFIER:OpenAL Soft
:audio(debug): AL_RENDERER:OpenAL Soft
:audio(debug): AL_VENDOR:OpenAL Community
:audio(debug): AL_VERSION:1.1 ALSOFT 1.19.1
:audio(debug): create_AudioManager()
  audio_library_name="p3openal_audio"
:audio(debug): Create_OpenALAudioManager()
:audio(debug): ALC_DEVICE_SPECIFIER:OpenAL Soft
:audio(debug): AL_RENDERER:OpenAL Soft
:audio(debug): AL_VENDOR:OpenAL Community
:audio(debug): AL_VERSION:1.1 ALSOFT 1.19.1
:audio(debug): Creating: test.ogg
:audio(debug):   - Rate: 44100
:audio(debug):   - Channels: 2
:audio(debug):   - Length: 5.53846
:audio(debug): test.ogg: loading as sample
:audio(debug): Decrementing: test.ogg 0
:audio(debug): Incrementing: test.ogg 1
:audio(debug): playing. Rate=1
:audio(debug): Decrementing: test.ogg 0
:audio(debug): Expiring: test.ogg
:audio(debug): Going to try to close openAL
:audio(debug): openAL Closed

I plugged cheap gaming headphones into USB, and there is no difference, the sound is always in the left speaker.

I would imagine that the HRTF is controlled by the openal-soft configuration file, not by Panda, but I’m happy to add a Panda config switch for this if you find something.

Yes sorry that’s what I meant, a Panda configuration to disable HRTF. That would be great. I’ll look into how this could be done

@rdb So the openal-soft config we’re looking for is stereo-encoding, with this blurb in the official openal-soft sample config file:

basic is what I want to change it to (and what I think the default should be).
Edit: Above is wrong, I was looking at latest, but Panda3D is using version 1.19.1. For this version, what we want is this config, hrtf:

And the preferred setting here would be false.

Edit 2: Third time’s the charm… turning off hrtf doesn’t completely disable this “spatialization” effect. To completely disable it, gotta set stereo-mode to speakers (which is exactly what kcat recommended… I gotta read more carefully next time)

I’m not exactly sure how panda deals with configuring openal, as normal operation would just be to put an alsoft.(conf|ini) next to the application for openal to look for, with this value set. I see in the C++ there is a config_openalAudio.cxx file, but I’m not sure how it relates exactly. Do you think you could point me in the right direction for this?

This code would have to be in panda/src/audiotraits/openalAudioManager.cxx, I imagine, which is where the OpenAL device is set up.