love2d / love

LÖVE is an awesome 2D game framework for Lua.
https://love2d.org
Other
4.87k stars 389 forks source link

add hrtf support to love.audio #1699

Open lilmike opened 3 years ago

lilmike commented 3 years ago

I'd like to request hrtf support using openAL in love.audio. The usage for this feature for me is that I plan to write mostly audio specific games, and without hrtf support openAL doesn't do a good job of placing sounds behind versus in front of the user (especially when the user cannot see what's on screen or there is intensionally nothing on screen to begin with which is often true of audio only games). If I remember correctly there is a quick code snippet on the openAL site, or it might have been in the mailing list, but changing hrtf settings in code didn't seem that hard last time I looked at it. Let me know if I can help anyway with this issue, or if I'm missing something. Thanks! -Michael.

MikuAuahDark commented 3 years ago

First, you need to create your alsoftrc.ini file, then set environment variable ALSOFT_CONF to point to absolute, OS-dependent path of the alsoftrc.ini (love.filesystem.getSaveDirectory().."/alsoftrc.ini" for example).

You need to do that before the love.audio module is loaded. Either by delay-load it by t.modules.audio = false at conf.lua then require("love.audio") at main.lua or do everything in love.conf.

The relevant HRTF setting can be found at https://github.com/kcat/openal-soft/blob/openal-soft-1.19.1/alsoftrc.sample#L122-L133

bjornbytes commented 3 years ago

I quickly sketched out support for the OpenAL ALC_HRTF_SOFT extension here. It enables HRTFs when supported and adds love.audio.isSpatialized to check if audio is being spatialized with HRTFs. It has some serious flaws in its current state:

Solutions to the first issue could include adding a conf.lua flag (wasn't sure how to plumb this through so I didn't do it) and/or love.audio.setSpatializationEnabled (this would require resetting the device which may not be desirable).

lilmike commented 3 years ago

That sounds nice. I would like to mention, however, that you can load a different hrtf file at runtime. This could be used, for example, to allow users to hear an example of the hrtf using the game, and then pick their prefered one which would then be loaded. Just food for thought. -Michael.

-- Michael Taboada, Creator of Games. Does that make me a god, well, sorta. My pgp key: 79BC390E8864CD71305D4DD606CD2197A6EE5ED7 My website: https://michaels.world 2MB website: https://2mb.games Don't believe everything you read on the internet. I might not be real, you might not be real, and this email certainly isn't real. Sent from my hall closet... stationary bicycle

lilmike commented 10 months ago

I found this issue while planning to request hrtf support, and I'm wondering if there's been any more interest or work on this? I'd like to use hrtf in some games, and I would ideally have the following features:

  1. The ability to turn hrtf on/off at runtime. I know this would require resetting the device, but as long as this is noted I think it shouldn't be too much of an issue.
  2. The ability to load hrtfs at runtime, for example to allow users to trial the different hrtf profiles shipped with the application to determine which is best for them.
  3. No need to enable or disable hrtf in a config file. This might sound obvious, but if my users have to go mucking around with the olasoft config files, I might as well not have the feature.

Let me know if there's anything I can do to test or anything else. I know I've got some c++ code for this very purpose in my game-kit collection of c++ stuff, maybe it could be a good reference: https://git.2mb.codes/~lilmike/game-kit (under the allegro-stuff/sound3d folder) doesn't require allegro, not sure why I put it there...

-Michael.