|
Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
|
Binaural HRTF spatialization backend built on Steam Audio. More...
#include <SteamAudioBackend.h>
Public Types | |
| using | SourceId = std::uint32_t |
| using | ReadFramesCallback = std::function<std::uint64_t(float* pFramesOut, std::uint64_t frameCount)> |
| Reads interleaved PCM frames in the source's native channel layout. | |
| using | DestroyCallback = std::function<void()> |
| Frees the source PCM backend (e.g. a miniaudio buffer). Invoked on the audio thread when the source is finally released. | |
Public Member Functions | |
| SteamAudioBackend () | |
| ~SteamAudioBackend () | |
| SteamAudioBackend (const SteamAudioBackend &)=delete | |
| SteamAudioBackend & | operator= (const SteamAudioBackend &)=delete |
| bool | init (std::uint32_t sampleRate, std::uint32_t frameSize) |
| Initialize Steam Audio with the built-in HRTF. | |
| bool | init (std::uint32_t sampleRate, std::uint32_t frameSize, const char *sofaFilePath) |
| Initialize Steam Audio with an individualized HRTF from a SOFA file. | |
| void | shutdown () |
| Shut down Steam Audio and release all sources and effects. Must not run concurrently with render() (call after the device stopped). | |
| bool | isInitialized () const |
| Returns whether init() succeeded and shutdown() has not been called. | |
| void | setListener (const glm::vec3 &position, const glm::quat &orientation) |
| Set the listener pose (headset position and world orientation). | |
| SourceId | addSource (ReadFramesCallback readFrames, DestroyCallback onDestroy, std::uint32_t channels, const glm::vec3 &position, float volume, bool loop) |
| Register a spatialized source. | |
| void | updateSourcePosition (SourceId source, const glm::vec3 &position) |
| Move an existing source to a new world position. | |
| void | updateSourceVolume (SourceId source, float volume) |
| Change the base gain of an existing source. | |
| bool | isSourceFinished (SourceId source) const |
| Check whether a source reached the end of its audio. | |
| void | removeSource (SourceId source) |
| Release a source. The read backend is destroyed asynchronously on the audio thread; the source stops contributing immediately. | |
| void | render (float *pFramesOutInterleavedStereo, std::uint32_t frameCount) |
| Accumulate the spatialized mix into an interleaved stereo buffer. | |
Static Public Attributes | |
| static constexpr SourceId | INVALID_SOURCE = 0 |
Private Attributes | |
| std::unique_ptr< Impl > | impl_ |
| bool | initialized_ = false |
Binaural HRTF spatialization backend built on Steam Audio.
Owns a Steam Audio context, an HRTF (built-in or loaded from a SOFA file), and one binaural effect per active source. Gameplay updates the listener pose and the per-source world positions on the game thread; render() is invoked from the audio thread (miniaudio engine onProcess hook) and accumulates the spatialized output into the final mix.
All sources are mixed down to mono and rendered with the binaural effect. Distance attenuation is applied with a gentle curve that keeps a floor so localized cues stay audible regardless of distance.
Definition at line 23 of file SteamAudioBackend.h.
| using Engine::Core::SteamAudioBackend::DestroyCallback = std::function<void()> |
Frees the source PCM backend (e.g. a miniaudio buffer). Invoked on the audio thread when the source is finally released.
Definition at line 38 of file SteamAudioBackend.h.
| using Engine::Core::SteamAudioBackend::ReadFramesCallback = std::function<std::uint64_t(float* pFramesOut, std::uint64_t frameCount)> |
Reads interleaved PCM frames in the source's native channel layout.
Definition at line 32 of file SteamAudioBackend.h.
| using Engine::Core::SteamAudioBackend::SourceId = std::uint32_t |
Definition at line 25 of file SteamAudioBackend.h.
| Engine::Core::SteamAudioBackend::SteamAudioBackend | ( | ) |
| Engine::Core::SteamAudioBackend::~SteamAudioBackend | ( | ) |
|
delete |
| SourceId Engine::Core::SteamAudioBackend::addSource | ( | ReadFramesCallback | readFrames, |
| DestroyCallback | onDestroy, | ||
| std::uint32_t | channels, | ||
| const glm::vec3 & | position, | ||
| float | volume, | ||
| bool | loop ) |
Register a spatialized source.
| readFrames | Callback that fills interleaved PCM frames in the source's channel layout. |
| onDestroy | Callback invoked on the audio thread when the source is released. |
| channels | Number of interleaved channels produced by readFrames. |
| position | Initial world position. |
| volume | Base gain (0.0 - 1.0) before distance attenuation. |
| loop | Whether readFrames loops automatically. |
| bool Engine::Core::SteamAudioBackend::init | ( | std::uint32_t | sampleRate, |
| std::uint32_t | frameSize ) |
Initialize Steam Audio with the built-in HRTF.
| sampleRate | Shared engine sample rate (see Audio::SAMPLE_RATE). |
| frameSize | Fixed processing frame size (see Audio::FRAME_SIZE). |
| bool Engine::Core::SteamAudioBackend::init | ( | std::uint32_t | sampleRate, |
| std::uint32_t | frameSize, | ||
| const char * | sofaFilePath ) |
Initialize Steam Audio with an individualized HRTF from a SOFA file.
| sofaFilePath | Path to a SOFA HRTF dataset, or nullptr for the built-in HRTF. |
|
inlinenodiscard |
Returns whether init() succeeded and shutdown() has not been called.
Definition at line 67 of file SteamAudioBackend.h.
References initialized_.
|
nodiscard |
Check whether a source reached the end of its audio.
|
delete |
| void Engine::Core::SteamAudioBackend::removeSource | ( | SourceId | source | ) |
Release a source. The read backend is destroyed asynchronously on the audio thread; the source stops contributing immediately.
| void Engine::Core::SteamAudioBackend::render | ( | float * | pFramesOutInterleavedStereo, |
| std::uint32_t | frameCount ) |
Accumulate the spatialized mix into an interleaved stereo buffer.
| pFramesOut | Interleaved stereo buffer (2 channels) to add into. |
| frameCount | Number of stereo frames. |
| void Engine::Core::SteamAudioBackend::setListener | ( | const glm::vec3 & | position, |
| const glm::quat & | orientation ) |
Set the listener pose (headset position and world orientation).
| position | World position of the headset. |
| orientation | World orientation of the headset. |
| void Engine::Core::SteamAudioBackend::shutdown | ( | ) |
Shut down Steam Audio and release all sources and effects. Must not run concurrently with render() (call after the device stopped).
| void Engine::Core::SteamAudioBackend::updateSourcePosition | ( | SourceId | source, |
| const glm::vec3 & | position ) |
Move an existing source to a new world position.
| void Engine::Core::SteamAudioBackend::updateSourceVolume | ( | SourceId | source, |
| float | volume ) |
Change the base gain of an existing source.
|
private |
Definition at line 116 of file SteamAudioBackend.h.
|
private |
Definition at line 117 of file SteamAudioBackend.h.
Referenced by isInitialized().
|
staticconstexpr |
Definition at line 26 of file SteamAudioBackend.h.