Audio engine #39
Replies: 1 comment 1 reply
-
So ideally what we want when we're introducing new systems is to make sure that those new systems don't introduce any licensing dependencies / fees / etc. and we want those systems to cover as many cases as possible. That being said, I'm going to go through these and apply some heuristics to this list so we know what we're looking for.
So the ideal libraries here are ones with everything checked, as well as a good FOSS license. That leaves miniaudio, libsoundio, PortAudio, OpenAL Soft, SoLoud, NWaves, KFR, Madronalib. That being said, FMOD already does all of the work.. however I would rather not introduce "license baggage" - if we add FMOD and someone wants to use the engine and sell their game, they would then have to worry about paying FMOD's license, which is something I want to avoid if possible. Perhaps in future we could separate the audio system out into two subsystems, one for miniaudio and one for FMOD - that way people that want to use FMOD's workflow can do so, and people that want to make a game without worrying about additional license fees can do so as well. |
Beta Was this translation helpful? Give feedback.
-
Currently, there's no audio engine in Mocha at all. We have a lot of building blocks to choose from, but most won't fill all of our needs, so we're probably gonna have to do some leg-work. I'll lay out what I see as the pros and cons to each, and give the combinations I like best at the end.
Assume available on vcpkg/nuget unless stated otherwise.
Brace yourself for a long post.
Low-level APIs
Cross-platform playback and recording backends.
SDL_audio.h - Docs, Native, zlib license
but...
PortAudio - Website, Docs, vcpkg, Native, MIT license
libsoundio - Website, Docs, vcpkg, Native, MIT license
miniaudio - Website, Docs, Header file, Native, Public domain / MIT license
NAudio - GitHub, nuget, Managed, MIT license
High-level APIs
I'm defining this as APIs that provide some level of abstraction for playing sounds, and 3D spatialization - a listener or multiple listeners with position, rotation and velocity, and the same for 3D sound sources. They all have support for callbacks called by dedicated audio threads, meaning we generally don't have to guess when audio needs to be supplied to the backend.
FMOD - Website, Docs, Download, Native, Proprietary
but...
OpenAL Soft - Website, Docs, vcpkg, Native, GPLv2 license
And to be clear it's OpenAL Soft, not OpenAL, which is different. Soft is forked from OpenAL 1.0 from the year 2000, before OpenAL went closed-source and stopped being truly maintained.
but...
miniaudio (cont.)
miniaudio has a high-level API as well. All of this stuff is optional. If we want to play audio directly and bypass it entirely, we can.
but...
SoLoud - Website, Docs, Download, Native, zlib license
but...
and also
I'm guessing most of the others are largely the same though? So I'm going to ignore this.
SDL_mixer - Website, Docs, vcpkg, Native, zlib licenseThe spatialization is... let's say, sub-par. Its
Mix_SetPosition()
function only takes a single angle (I assume between left/right stereo channels) and a distance, neither of them being floats, and in the documentation for it they even say:This library is worth mentioning because it's talked about often enough elsewhere, but it's clearly already off the table.
DSPs
Probably necessary if we don't go with FMOD, as even the DSPs included in the high-level libraries don't have some of the effects we'd want.
Quick glossary:
We want online processing.
NWaves - GitHub, Docs, nuget, Managed, MIT license
but...
KFR - Website, Docs, vcpkg, Native, GPLv2 license
but...
Madronalib - GitHub, Native, MIT license
but...
Other
Steam Audio - Website, Docs, GitHub Releases, Native, Proprietary license
Its announcement is a good overview, but here's an even quicker summary:
Within the realm of game audio, this could be considered middleware. It does not play audio for us. It's basically a big box of effects, with its focus being on 3D spatialization, including HRTF, reverb and reflections, occlusion, etc.
but...
Standalone codec libraries
These are the same ones used by miniaudio and SoLoud.
Summary & Thoughts
I feel there's a lot to think about here, hence why I putting this in a discussion and not an issue.
So, uh... what should we use?
If we don't care about it costing money for commercial projects, and we don't care about it maaaybe being overkill, I mean, wow, FMOD. It would take care of just... everything, and it can be paired with Steam Audio. It does mean that we wouldn't have a strictly VMix-like system, but it has equivalent features, so who cares.
Bar that, miniaudio with its built-in node graph system looks quite promising, although I don't know how difficult it would be to make a system around it that allows things to be changed on the fly. Worth looking into.
The low-level APIs all have slight tradeoffs in design and platform support, but they're generally all okay. If we don't go for anything else and we intend to roll our own audio engine, I say we try out libsoundio due to its self-purported resilience.
Why the bias towards native libraries?
For simple sound, managed libraries will work fine, but I'm concerned about how performance will scale. Think about it: Tens or perhaps even over a hundred sound sources in-game, at a sample rate of 44100hz, each with their own effects applied and mixed. I mean, just 30 simultaneous sounds works out to 1,323,000 samples per second. Perhaps it's unfounded but I start getting worried once we start getting into the range of millions of samples in managed code, especially once we involve VMix-like stuff which will have some slight overhead, scaling with how much processing it does.
Despite the extra complexity, I'd personally prefer to do stuff in native code. I think doing that has a chance of letting us throw more crap at it before it chokes - we can set higher limits on simultaneous sound events.
What about proprietary licenses?
I think distributing closed-source binaries alongside AGPLv3-licensed software (like Mocha) is allowed so long as it's dynamically linked (as is the case for FMOD and Steam Audio), but I suppose more research should be done here.
How would a VMix-like system work?
This assumes no FMOD, as that library would take care of equivalent things for us entirely.
We want something like VMix, but it's actually just one piece of the puzzle. Source 2's audio engine as a whole can be summarised as being done in five stages:
How would Steam Audio integrate into this?
In Source 2, Steam Audio nodes are available in sound stacks and VMix. This makes a lot of sense with the way Steam Audio is designed, I don't see why we'd do it any differently.
Woah, this is complicated.
Yeah.
From an engine developer perspective, I think FMOD and Source 2's audio engine are both really nice and things we should at least partially emulate. They're elegant solutions to a complicated problem, and from my experience a Source 2-like system isn't that hard to implement, structurally speaking. If we do it in native code, we may need to implement some basic form of C++ reflection.
From an end user perspective, this is slightly terrifying, and we should provide sane defaults so nobody has to touch it if they don't have to nor want to. Unlike some platforms though, we should still expose it.
Am I overthinking/overengineering this?
Maybe. Definitely. I don't know. What do you guys think?
Beta Was this translation helpful? Give feedback.
All reactions