-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement environmental audio using OpenAL EFX #3182
base: master
Are you sure you want to change the base?
Conversation
gcc requires this due to how the struct is initialized in AddonPartFileFormat.cpp
OpenAL 1.1 changed the way how the doppler effect is handled from OpenAL 1.0. Using the old way did not break the build as demanded by the spec but disabled the effect for at least the OpenAL Soft implementation.
update variable names to follow coding style and prefer local variables over method calls
this also allows to disable the effect by setting the doppler factor to 0
This design has less coupling and allows for setting more environmental properties of the listener in the future
Looks fantastic so far. I'll test on friday. |
This is considered WIP since the parameters are configurable, but they get currently overwritten at each frame dependent on the environment of the listener
I'd like to have the reverb presets as well as the air absorption related parameter to be scriptable, manually overridable or to automatically change depending on whether the listener is underwater or not (and perhaps they are in a cockpit or not). I haven't decided how to bring all this together yet. Might be necessary to implement a state machine to track where the parameters are allowed to be set from. |
This should be considered an incomplete implementation. The line of sight checks/collision detection need to be improved. It does not detect trucks and some meshes on the terrain while it sometimes detects invisible walls
Since somewhere in the OpenAL docs it was suggested to implement occlusion and obstruction effects alongside reverb effects to put more emphasize on the latter, I added a basic obstruction filter. |
I appreciate your focus on scripting, some notes to hopefully make life easier for you:
Improving sounds including terrain/object interference has been on my mind for years, but there's always too much other stuff, regarding scripting try in console 'loadscript demo_script.as', it showcases the current basic audio bindings. There's plenty more examples in repo under /resources/scripts. Also come hang around other Devs in Discord #dev https://discord.com/channels/136544456244461568/189904947649708032 |
The AL_EFFECT_EAXREVERB engine is a superset of the AL_EFFECT_REVERB engine. Not all OpenAL implementations might support it. At least the Creative AL driver and OpenAL Soft support this reverb engine and there is a noticable difference in some of the reverb presets. Some of the features it provides might be useful for a more realistic audio experience as well.
This allows the user to set environmental audio parameters from console or scripts without fearing they get overwritten by the engine
This is necessary to change the AIR_ABSORPTION_GAIN_HF property once a preset has been made active. It will also be necessary for panning of reflection and late reverb.
With 100ms some pop sounds were still audible for some preset changes, 333ms seems like a better choice.
* No longer expose corresponding CVars since internal handling should suffice * the previous calculation for the air absorption factor for underwater environments incorrectly targeted 5 MHz instead of 5 kHz * AirAbsorptionGainHF is no longer adjusted since it should be determined by the preset
Sounds like a lot of awesome changes. I'm just saying, didn't test yet. Will see if that can be merged in SR3, since I based new audio on RoR's. |
I'm thrilled, there hasn't been this much focus on audio in last 10 years. I'd like to know some test scenarios to observe and enjoy these effects. I'll try to explore myself for now. |
Sorry for the belated response, I was on vacation. Thanks for your kind words. After reading the OpenAL Effects Extensions Guide, I got really motivated to try out many of the features the API provides. The PR has grown quite large and in terms of features, I think it has almost reached a viable state. I still intend to do some minor refactoring. As far as scripting support goes, I think the most important thing is that reverb presets can be defined for meshes and terrains and that custom presets can be loaded into the audio engine. The first is made possible via the @cryham I would be very happy to see the code being used in SR3. The OpenAL Soft implementation always fascinated me with the high quality audio it provides through EFX, binaural audio and Ambisonics and I would welcome more games using the advanced features the OpenAL API provides. Looking at the PR, there is still room for improvements, of course:
Reflection panning is still marked as an experimental feature because:
Here is what you can currently listen for:@ohlidalp
For the underwater effects, you would have to use another map, though. Simply move the camera between above water and underwater and notice how the audio changes as well as the smooth transitions between the effects. Some other features that would theoretically possible with OpenAL that I don't see within the scope of this PR:
|
Wow, thanks for the elaborate write-up and don't worry about responsiveness, I myself react very irregularly. ODEFs can omit mesh if you set mesh name to "none", see
Unfortunately, there's currently no way to scale ODEFs from TOBJ. I was going to add this functionality anyway, for i.e. varied vegetation. Either way, an usable terrain editor would be a tremendous help here. We have a crude terrain editing mode, but it currently only writes a logfile insted of actually editing terrain files. I have an active WIP branch where I added this missing piece: https://github.com/ohlidalp/rigs-of-rods/tree/terrn_export |
I'll create a pull request with the new terrain editor during the coming week, then we can work the reverb and obstruction feats into an editor UI, which will both showcase and document it visually. |
Neat trick, I didn't notice this. Thanks for the info, this makes using collision boxes much more viable.
Sounds great. |
… actor The implementation did not differentiate whether the actor had an open or closed cabin. For instace, it incorrectly applied the obstruction effect when the listener was in actors with open cabins, e.g. buggies. There does not seem to be an easy way to determine whether an actor has an open or closed cabin. An expensive(?) alternative might be to check against collisions with the mesh of an actor.
The console command was largely redundant to working with the audio_doppler_factor CVar. Instead of the previous way of triggering updates of the doppler factor via the message queue, the doppler factor is now updated each frame from the audio_doppler_factor CVar.
Hi. I have a few comments, about this PR's code style. Obviously, I'm not a RoR developer, so it's up to you.
I fixed all those and more in this stuntrally/stuntrally3@3588cad |
Great to see it being tried out in SR3 already and I appreciate your feedback. I still intend to do some cleanup and refactoring before gettings this merged. Onto your suggestions:
I should fix that.
All code I added should follow the RoR coding style guidelines, which say
I'll take a look if it can be improved. I'll probably just copy your improvement.
The coding style guidelines have an example of this, which I followed since I like it for simple getters: int GetMemberValue() { return m_private_member_variable; } //STYLE: Getter function -> `Get` in name
The mentioned functions aren't part of this PR and cleaning them up should be left for another PR.
I prefer long variable/function names over adding comments to prevent comments getting outdated and make the code read more like natural language (see also clean code principles). I could change it, if desired. |
Cool. I am not a developer here, just went through the code BTW. Definitely ohlidalp has the say, and I forgot there is coding style guidelines, so better to keep to it. Anyways I'm not sure I will use this code, it seems buggy right now, not sure why. |
Can you elaborate? I didn't notice any bugs in RoR.
I see buffer management as a different topic. For this PR I only want to focus on environmental audio implemented via OpenAL EFX. I didn't pay too much attention to the already existing buffer management but I think your assessment is correct and that there is room for improvement, especially for ambient sounds. |
No I meant it's buggy in SR3, after my somewhat reworked version. And different code in SR3 compared to RoR. I don't have such setup as in RoR with all SoundTriggers, ModulationSources in ActorSpawner.cpp, I don't have that and I just set gain and pitch myself in update. Could be something bad with this in SR3. |
…Manager class and rename it to UpdateListenerEnvironment
While the current implementation could be improved in terms of filter parameters and line of sight checks against actors, it is solid enough to no longer be considered experimental.
…tor's unit This behavior more closely resembles that of Ogre's intersects methods.
Return the default efx preset not just for the listener position but for any position in the game that has no other efx preset set
This is a WIP PR for implementing reverb support using the OpenAL EFX extensions. To make it easier for me, this PR is currently based on #3180 and #3181.
The basic foundation is already there. If the listener (camera) is underwater, an underwater effect becomes active.
The preset can be changed to ones listed here using the console command
(see #3182 (comment)). Resetting the preset is currently not possible via console.set audio_listener_efx_preset
There is still some work to do:
automatically activate an in-cockpit preset when appropriate?-> not easy to know whether a truck has a closed cabin or notdo not enable it if the listener is very close but outside of the truck (happens because there is a check whether the listener is inside the BB of the driven vehicle, but certain vehicles provide outside camera views)