Browse Source

Enable OpenAL-Soft extensions for non-framework builds and add config for disabling HRTF (#1620)

gabe 1 year ago
parent
commit
ad97e88a54

+ 1 - 1
.github/workflows/ci.yml

@@ -475,7 +475,7 @@ jobs:
     - name: Setup emsdk
       uses: mymindstorm/setup-emsdk@v14
       with:
-        version: 3.1.51
+        version: 3.1.65
         actions-cache-folder: 'emsdk-cache'
 
     - name: Build for Emscripten

+ 2 - 1
makepanda/makepanda.py

@@ -2508,7 +2508,8 @@ def WriteConfigSettings():
         dtool_config["PYTHON_FRAMEWORK"] = 'Python'
         dtool_config["PHAVE_MALLOC_H"] = 'UNDEF'
         dtool_config["PHAVE_SYS_MALLOC_H"] = '1'
-        dtool_config["HAVE_OPENAL_FRAMEWORK"] = '1'
+        if not os.path.isdir(GetThirdpartyDir() + "openal"):
+            dtool_config["HAVE_OPENAL_FRAMEWORK"] = '1'
         dtool_config["HAVE_X11"] = 'UNDEF'  # We might have X11, but we don't need it.
         dtool_config["IS_LINUX"] = 'UNDEF'
         dtool_config["HAVE_VIDEO4LINUX"] = 'UNDEF'

+ 7 - 0
panda/src/audio/config_audio.cxx

@@ -75,6 +75,13 @@ ConfigVariableInt audio_preload_threshold
           "practical to stream multiple sound-files from disk at the same "
           "time - the hard drive seek time makes it stutter."));
 
+ConfigVariableBool audio_want_hrtf
+("audio-want-hrtf", true,
+ PRC_DESC("This determines whether OpenAL-Soft should activate HRTF in "
+          "certain hardware configurations. Set it to true to cause "
+          "OpenAL to automatically apply HRTF processing to all output "
+          "audio when headphones are used for playback."));
+
 // Unknown
 
 ConfigVariableInt audio_min_hw_channels

+ 1 - 0
panda/src/audio/config_audio.h

@@ -67,6 +67,7 @@ extern EXPCL_PANDA_AUDIO ConfigVariableDouble audio_distance_factor;
 extern EXPCL_PANDA_AUDIO ConfigVariableDouble audio_drop_off_factor;
 extern EXPCL_PANDA_AUDIO ConfigVariableDouble audio_buffering_seconds;
 extern EXPCL_PANDA_AUDIO ConfigVariableInt    audio_preload_threshold;
+extern EXPCL_PANDA_AUDIO ConfigVariableBool   audio_want_hrtf;
 
 #ifdef NOTIFY_DEBUG //[
   // Non-release build:

+ 16 - 1
panda/src/audiotraits/openalAudioManager.cxx

@@ -155,7 +155,22 @@ OpenALAudioManager() {
     if (_device != nullptr) {
       // We managed to get a device open.
       alcGetError(_device); // clear errors
-      _context = alcCreateContext(_device, nullptr);
+
+      ALCboolean is_hrtf_present = alcIsExtensionPresent(_device, "ALC_SOFT_HRTF");
+
+      ALCint attrs[3] = {0};
+
+#ifndef HAVE_OPENAL_FRAMEWORK
+      if (is_hrtf_present) {
+        attrs[0] = ALC_HRTF_SOFT;
+        attrs[1] = audio_want_hrtf.get_value() ? ALC_TRUE : ALC_FALSE;
+        attrs[2] = 0; // end of list
+      } else {
+        attrs[0] = 0; // end of list
+      }
+#endif // HAVE_OPENAL_FRAMEWORK
+
+      _context = alcCreateContext(_device, attrs);
       alc_audio_errcheck("alcCreateContext(_device, NULL)", _device);
       if (_context != nullptr) {
         _openal_active = true;

+ 1 - 0
panda/src/audiotraits/openalAudioManager.h

@@ -29,6 +29,7 @@
 #else
   #include <AL/al.h>
   #include <AL/alc.h>
+  #include <AL/alext.h>
 #endif
 
 class OpenALAudioSound;

+ 1 - 0
panda/src/audiotraits/openalAudioSound.h

@@ -27,6 +27,7 @@
 #else
   #include <AL/al.h>
   #include <AL/alc.h>
+  #include <AL/alext.h>
 #endif
 
 class EXPCL_OPENAL_AUDIO OpenALAudioSound final : public AudioSound {