Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Core::SteamAudioBackend Class Reference

Binaural HRTF spatialization backend built on Steam Audio. More...

#include <SteamAudioBackend.h>

Collaboration diagram for Engine::Core::SteamAudioBackend:

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

Detailed Description

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.

Member Typedef Documentation

◆ DestroyCallback

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.

◆ ReadFramesCallback

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.

Returns
Number of frames actually read; 0 signals the end of the source.

Definition at line 32 of file SteamAudioBackend.h.

◆ SourceId

Definition at line 25 of file SteamAudioBackend.h.

Constructor & Destructor Documentation

◆ SteamAudioBackend() [1/2]

Engine::Core::SteamAudioBackend::SteamAudioBackend ( )

Referenced by operator=(), and SteamAudioBackend().

Here is the caller graph for this function:

◆ ~SteamAudioBackend()

Engine::Core::SteamAudioBackend::~SteamAudioBackend ( )

◆ SteamAudioBackend() [2/2]

Engine::Core::SteamAudioBackend::SteamAudioBackend ( const SteamAudioBackend & )
delete

References SteamAudioBackend().

Here is the call graph for this function:

Member Function Documentation

◆ addSource()

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.

Parameters
readFramesCallback that fills interleaved PCM frames in the source's channel layout.
onDestroyCallback invoked on the audio thread when the source is released.
channelsNumber of interleaved channels produced by readFrames.
positionInitial world position.
volumeBase gain (0.0 - 1.0) before distance attenuation.
loopWhether readFrames loops automatically.
Returns
Stable source id, or INVALID_SOURCE on failure.

◆ init() [1/2]

bool Engine::Core::SteamAudioBackend::init ( std::uint32_t sampleRate,
std::uint32_t frameSize )

Initialize Steam Audio with the built-in HRTF.

Parameters
sampleRateShared engine sample rate (see Audio::SAMPLE_RATE).
frameSizeFixed processing frame size (see Audio::FRAME_SIZE).
Returns
true when the context and HRTF initialized successfully.

◆ init() [2/2]

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.

Parameters
sofaFilePathPath to a SOFA HRTF dataset, or nullptr for the built-in HRTF.

◆ isInitialized()

bool Engine::Core::SteamAudioBackend::isInitialized ( ) const
inlinenodiscard

Returns whether init() succeeded and shutdown() has not been called.

Definition at line 67 of file SteamAudioBackend.h.

References initialized_.

◆ isSourceFinished()

bool Engine::Core::SteamAudioBackend::isSourceFinished ( SourceId source) const
nodiscard

Check whether a source reached the end of its audio.

Returns
true when the source is finished or no longer registered.

◆ operator=()

SteamAudioBackend & Engine::Core::SteamAudioBackend::operator= ( const SteamAudioBackend & )
delete

References SteamAudioBackend().

Here is the call graph for this function:

◆ removeSource()

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.

◆ render()

void Engine::Core::SteamAudioBackend::render ( float * pFramesOutInterleavedStereo,
std::uint32_t frameCount )

Accumulate the spatialized mix into an interleaved stereo buffer.

Parameters
pFramesOutInterleaved stereo buffer (2 channels) to add into.
frameCountNumber of stereo frames.

◆ setListener()

void Engine::Core::SteamAudioBackend::setListener ( const glm::vec3 & position,
const glm::quat & orientation )

Set the listener pose (headset position and world orientation).

Parameters
positionWorld position of the headset.
orientationWorld orientation of the headset.

◆ shutdown()

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).

◆ updateSourcePosition()

void Engine::Core::SteamAudioBackend::updateSourcePosition ( SourceId source,
const glm::vec3 & position )

Move an existing source to a new world position.

◆ updateSourceVolume()

void Engine::Core::SteamAudioBackend::updateSourceVolume ( SourceId source,
float volume )

Change the base gain of an existing source.

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> Engine::Core::SteamAudioBackend::impl_
private

Definition at line 116 of file SteamAudioBackend.h.

◆ initialized_

bool Engine::Core::SteamAudioBackend::initialized_ = false
private

Definition at line 117 of file SteamAudioBackend.h.

Referenced by isInitialized().

◆ INVALID_SOURCE

SourceId Engine::Core::SteamAudioBackend::INVALID_SOURCE = 0
staticconstexpr

Definition at line 26 of file SteamAudioBackend.h.


The documentation for this class was generated from the following file: