kcat / openal-soft

OpenAL Soft is a software implementation of the OpenAL 3D audio API.
Other
2.21k stars 534 forks source link

OS X and Device Enumeration #179

Closed ghost closed 2 years ago

ghost commented 6 years ago

So I am currently using OpenALSoft (Latest stable) for a 2-D game engine I have been working on for the past few years, and it is all nicely integrated and working properly with no issue, even with cross-platforming it without any sort of hacks. However, I have one small issue with the Mac (Sierra 10.13.3) implementation which it can't enumerate all audio devices with ALC_ALL_DEVICES_SPECIFIER on the Mac compiled version of OpenALSoft and it just reports one device which is CoreAudio Default, but all the devices are enumerated properly when linked to the built-in OpenAL.framework supplied by Apple.

Now before I get to my main point, the problem with OpenAL and 2-D is that HRTF is a nightmare for me as I use some low quality sound effects which sound perfectly fine with HRTF disabled, but absolutely horrible with it enabled, so that is fine as I can completely disable HRTF with a call to alcResetDeviceSOFT() with the appropriate configuration which also works on Mac compiled version of OpenALSoft.

So then I thought of NOT using OpenALSoft on Mac and just linking with the built-in OpenAL.framework which works absolutely great as it lists all the device names properly. However, there doesn't appear to be a way to disable HRTF on the built-in OpenAL framework as there is no alcResetDeviceSOFT on that framework, so then I am stuck with horrible quality audio output because of HRTF, and I don't expect Apple to add any sort of function like that anytime soon.

For trying workarounds, I was wondering if it was possible to load the device names with OpenAL.framework and then share the opened device with OpenALSoft, or would that cause undefined behaviour? I want to try and find a sensible solution for this problem but I don't know what to do about it. Perhaps I even compiled OpenALSoft wrong on Mac as I just used the default settings in CMAKE? Or maybe I'm just doing something else wrong, but I am sure I am not. Again, no issues with Windows version what-so-ever.

I also get this error in the console on the Mac version of OpenALSoft but not OpenAL.framework, I don't know if it means anything. AL lib: (WW) GetProcPath: Failed to readlink /proc/self/file: No such file or directory.

In conclusion and TL:DR, I am stuck in the middle on my Mac executable of having no device names and good audio (no HRTF) in OpenALSoft and proper device names and bad audio (forced HRTF) in OpenAL.framework.

I hope someone can help me with this. Thank you and good work with the library.

kcat commented 6 years ago

However, I have one small issue with the Mac (Sierra 10.13.3) implementation which it can't enumerate all audio devices with ALC_ALL_DEVICES_SPECIFIER on the Mac compiled version of OpenALSoft and it just reports one device which is CoreAudio Default, but all the devices are enumerated properly when linked to the built-in OpenAL.framework supplied by Apple.

Currently OpenAL Soft doesn't do device enumeration on OSX, it just uses whatever the system has as the default. Since I don't have and can't directly test on OSX, I try to avoid doing anything to the OSX-specific code to inadvertently break it. I can try to implement it using whatever I can find on the APIs, and hope there are either no problems, and any mistakes can be spotted by Travis CI.

I also get this error in the console on the Mac version of OpenALSoft but not OpenAL.framework, I don't know if it means anything. AL lib: (WW) GetProcPath: Failed to readlink /proc/self/file: No such file or directory.

Can you provide the full trace output? Setting the ALSOFT_LOGLEVEL environment variable to 3 when you run the app should make it print a bunch more information along with those warnings. It might not be anything serious, but I'd like to make sure it's still finding the executable's directory another way.

ghost commented 6 years ago

Thanks for the reply, whatever you can try will be appreciated and I would be happy to help you test with my own software, at the end of the day I would like to give myself as much control and comfort as possible. I am afraid I hardly know anything about Objective-C in OS X though which is why I rely on libraries like yours. (C/C++ forever!).

Here is the output log of AL actions when running on Mac OpenALSoft from execution to termination (Latest stable with default cmake flags other than to create statically linked .lib/.a file). It doesn't appear to reveal anything useful to me, but none those .conf files exist on my system and none of them cross any symbolic directory links or files.

AL lib: (II) alc_initconfig: Initializing library v1.18.2-unknown UNKNOWN
AL lib: (II) alc_initconfig: Supported backends: core, null, wave
AL lib: (II) ReadALConfig: Loading config /etc/openal/alsoft.conf...
AL lib: (II) ReadALConfig: Loading config /etc/xdg/alsoft.conf...
AL lib: (II) ReadALConfig: Loading config /Users/me/.alsoftrc...
AL lib: (II) ReadALConfig: Loading config /Users/me/.config/alsoft.conf...
AL lib: (WW) GetProcPath: Failed to readlink /proc/self/file: No such file or directory
AL lib: (II) GetConfigValue: Key disable-cpu-exts not found
AL lib: (II) FillCPUCaps: Detected max CPUID function: 0xd (ext. 0x80000008)
AL lib: (II) FillCPUCaps: Vendor ID: ""
AL lib: (II) FillCPUCaps: Name: "        Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz"
AL lib: (II) FillCPUCaps: Extensions: +SSE +SSE2 +SSE3 +SSE4.1
AL lib: (II) GetConfigValue: Key rt-prio not found
AL lib: (II) GetConfigValue: Key resampler not found
AL lib: (II) GetConfigValue: Key trap-al-error not found
AL lib: (II) GetConfigValue: Key trap-alc-error not found
AL lib: (II) GetConfigValue: Key reverb/boost not found
AL lib: (II) GetConfigValue: Key reverb/emulate-eax not found
AL lib: (II) GetConfigValue: Key drivers not found
AL lib: (II) alc_initconfig: Initialized backend "core"
AL lib: (II) alc_initconfig: Added "core" for playback
AL lib: (II) alc_initconfig: Added "core" for capture
AL lib: (II) GetConfigValue: Key excludefx not found
AL lib: (II) GetConfigValue: Key default-reverb not found
AL lib: (II) GetConfigValue: Key channels not found
AL lib: (II) GetConfigValue: Key sample-type not found
AL lib: (II) GetConfigValue: Key frequency not found
AL lib: (II) GetConfigValue: Key periods not found
AL lib: (II) GetConfigValue: Key period_size not found
AL lib: (II) GetConfigValue: Key sources not found
AL lib: (II) GetConfigValue: Key slots not found
AL lib: (II) GetConfigValue: Key sends not found
AL lib: (II) GetConfigValue: Key ambi-format not found
AL lib: (II) alcOpenDevice: Created device 0x7fec6c033a00, "CoreAudio Default"
AL lib: (II) UpdateDeviceParams: ALC_HRTF_SOFT = 0
AL lib: (II) GetConfigValue: Key frequency not found
AL lib: (II) GetConfigValue: Key sources not found
AL lib: (II) GetConfigValue: Key sends not found
AL lib: (II) GetConfigValue: Key hrtf not found
AL lib: (II) UpdateDeviceParams: Pre-reset: Stereo, Float, 44100hz, 1024 update size x3
AL lib: (II) UpdateDeviceParams: Post-reset: Stereo, Float, 44100hz, 1024 update size x3
AL lib: (II) GetConfigValue: Key stereo-mode not found
AL lib: (II) aluInitRenderer: HRTF disabled
AL lib: (II) GetConfigValue: Key cf_level not found
AL lib: (II) aluInitRenderer: BS2B disabled
AL lib: (II) GetConfigValue: Key stereo-encoding not found
AL lib: (II) aluInitRenderer: UHJ disabled
AL lib: (II) UpdateDeviceParams: Channel config, Dry: 2, FOA: 0, Real: 0
AL lib: (II) UpdateDeviceParams: Allocating 2 channels, 16384 bytes
AL lib: (II) UpdateDeviceParams: Max sources: 256 (255 + 1), effect slots: 64, sends: 2
AL lib: (II) GetConfigValue: Key dither not found
AL lib: (II) GetConfigValue: Key dither-depth not found
AL lib: (II) UpdateDeviceParams: Dithering disabled
AL lib: (II) GetConfigValue: Key output-limiter not found
AL lib: (II) UpdateDeviceParams: Output limiter enabled
AL lib: (II) GetConfigValue: Key volume-adjust not found
AL lib: (II) alcCreateContext: Created context 0x7fec6b448550
AL lib: (II) FreeContext: 0x7fec6b448550
AL lib: (II) FreeContext: Freed 2 listener property objects
AL lib: (II) FreeDevice: 0x7fec6c033a00

Good luck!

kcat commented 6 years ago

The GetProcPath warning should be fixed with commit 3f071a90a4313749b348a7d98284c005e5d87537. Still looking into enumeration.

monaghanwashere commented 3 years ago

i know it's been a while, but any updates here? (related: https://github.com/kcat/openal-soft/issues/572)

also wondering if the strategy of passing a device name to openal works for device switching on mac os x (i.e. if i'm able to procure the device name from elsewhere and try to get openal soft to set it, would that work, given it can't enumerate them...?)

kcat commented 3 years ago

Commit 04a6e418d7c614e7ccab560d4f0084fa50587e26 adds enumeration to playback devices on OS X (really commit a7d2e2974f3d15d416754ad0b7dcb5598811ac07, but there were type errors that caused a build error). I'm unable to test if it's actually working as expected (provides correct names, uses the correct devices when any or no device name is specified, etc), If it does work as expected, I can extend it to capture fairly easily.

also wondering if the strategy of passing a device name to openal works for device switching on mac os x (i.e. if i'm able to procure the device name from elsewhere and try to get openal soft to set it, would that work, given it can't enumerate them...?)

Prior to now, no. OpenAL Soft will check against its own internal list to match which device is being requested. A couple backends (DSound, WASAPI) can be given a raw hardware ID, but that's still dependent on the backend being able to pass that to the system and select specific devices, which the CoreAudio backend couldn't do before the latest commits.

kcat commented 2 years ago

Closing since it's now implemented. If there's any issues with it, either this or #572 can be reopened, or a new issue created.