Game Audio Module
A C++ audio system using miniaudio with Python bindings
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
audio::AudioSystem Class Reference

Low-level audio system that interfaces directly with miniaudio. More...

#include <audio_system.h>

Public Member Functions

 AudioSystem ()
 Constructor.
 
 ~AudioSystem ()
 Destructor.
 
std::unique_ptr< AudioGroupCreateGroup ()
 Creates a new AudioGroup object.
 
std::unique_ptr< SoundCreateSound (const std::string &filepath, AudioGroup *group=nullptr)
 Creates a new Sound object.
 
float GetMasterVolume () const
 Gets the current master volume.
 
void SetMasterVolume (float volume)
 Sets the master volume for all audio.
 
Listener Management (Spatial Audio)
void SetListenerPosition (const Vec3 &position, ma_uint32 listenerIndex=0)
 Set the listener position in 3D space.
 
Vec3 GetListenerPosition (ma_uint32 listenerIndex=0) const
 Get the listener position.
 
void SetListenerDirection (const Vec3 &direction, ma_uint32 listenerIndex=0)
 Set the listener direction (forward vector)
 
Vec3 GetListenerDirection (ma_uint32 listenerIndex=0) const
 Get the listener direction.
 
void SetListenerUp (const Vec3 &up, ma_uint32 listenerIndex=0)
 Set the listener up vector.
 
Vec3 GetListenerUp (ma_uint32 listenerIndex=0) const
 Get the listener up vector.
 
ma_engine * GetEngine ()
 Get access to the miniaudio engine (for advanced use)
 

Private Attributes

ma_engine engine_
 miniaudio engine instance
 
float master_volume_
 Master volume level.
 
Cached Listener State (for optimization)
Vec3 cached_listener_position_
 Cached listener position to avoid redundant updates.
 
Vec3 cached_listener_direction_
 Cached listener direction.
 
Vec3 cached_listener_up_
 Cached listener up vector.
 
bool listener_state_dirty_
 Flag to track if listener state needs update.
 

Detailed Description

Low-level audio system that interfaces directly with miniaudio.

The AudioSystem class handles the core audio functionality, including initialization of the miniaudio engine and creation of sounds and groups. It manages the underlying audio resources and provides a layer of abstraction over the miniaudio library.

AudioSystem is not meant to be used directly by game code; instead, it's accessed through the AudioManager.

Constructor & Destructor Documentation

◆ AudioSystem()

audio::AudioSystem::AudioSystem ( )

Constructor.

Initializes the miniaudio engine

◆ ~AudioSystem()

audio::AudioSystem::~AudioSystem ( )

Destructor.

Cleans up all audio resources and uninitializes the miniaudio engine

Member Function Documentation

◆ CreateGroup()

std::unique_ptr< AudioGroup > audio::AudioSystem::CreateGroup ( )

Creates a new AudioGroup object.

Creates an audio group for collective control of sounds. The caller takes ownership of the returned unique_ptr.

Returns
std::unique_ptr<AudioGroup> Unique pointer to the newly created AudioGroup (caller owns)

◆ CreateSound()

std::unique_ptr< Sound > audio::AudioSystem::CreateSound ( const std::string &  filepath,
AudioGroup group = nullptr 
)

Creates a new Sound object.

Loads an audio file and creates a Sound object. The caller takes ownership of the returned unique_ptr.

Parameters
filepathPath to the audio file
groupOptional pointer to the group to add the sound to
Returns
std::unique_ptr<Sound> Unique pointer to the newly created Sound (caller owns)

◆ GetEngine()

ma_engine * audio::AudioSystem::GetEngine ( )
inline

Get access to the miniaudio engine (for advanced use)

Returns
ma_engine* Pointer to the miniaudio engine

◆ GetListenerDirection()

Vec3 audio::AudioSystem::GetListenerDirection ( ma_uint32  listenerIndex = 0) const

Get the listener direction.

Parameters
listenerIndexIndex of the listener (default 0)
Returns
Vec3 Current listener direction

◆ GetListenerPosition()

Vec3 audio::AudioSystem::GetListenerPosition ( ma_uint32  listenerIndex = 0) const

Get the listener position.

Parameters
listenerIndexIndex of the listener (default 0)
Returns
Vec3 Current listener position

◆ GetListenerUp()

Vec3 audio::AudioSystem::GetListenerUp ( ma_uint32  listenerIndex = 0) const

Get the listener up vector.

Parameters
listenerIndexIndex of the listener (default 0)
Returns
Vec3 Current listener up vector

◆ GetMasterVolume()

float audio::AudioSystem::GetMasterVolume ( ) const
inline

Gets the current master volume.

Returns
float Current master volume (0.0 to 1.0)

◆ SetListenerDirection()

void audio::AudioSystem::SetListenerDirection ( const Vec3 direction,
ma_uint32  listenerIndex = 0 
)

Set the listener direction (forward vector)

The direction vector represents which way the listener is facing. Should be normalized.

Parameters
directionForward direction vector (should be normalized)
listenerIndexIndex of the listener (default 0)

◆ SetListenerPosition()

void audio::AudioSystem::SetListenerPosition ( const Vec3 position,
ma_uint32  listenerIndex = 0 
)

Set the listener position in 3D space.

The listener represents the "ears" of the player/camera. All spatialized sounds are positioned relative to the listener.

Parameters
position3D position of the listener
listenerIndexIndex of the listener (default 0)

◆ SetListenerUp()

void audio::AudioSystem::SetListenerUp ( const Vec3 up,
ma_uint32  listenerIndex = 0 
)

Set the listener up vector.

The up vector defines the orientation of the listener. Typically (0, 1, 0) for a standard Y-up coordinate system.

Parameters
upUp vector (should be normalized)
listenerIndexIndex of the listener (default 0)

◆ SetMasterVolume()

void audio::AudioSystem::SetMasterVolume ( float  volume)

Sets the master volume for all audio.

Parameters
volumeVolume level (0.0 to 1.0)

Member Data Documentation

◆ cached_listener_direction_

Vec3 audio::AudioSystem::cached_listener_direction_
mutableprivate

Cached listener direction.

◆ cached_listener_position_

Vec3 audio::AudioSystem::cached_listener_position_
mutableprivate

Cached listener position to avoid redundant updates.

◆ cached_listener_up_

Vec3 audio::AudioSystem::cached_listener_up_
mutableprivate

Cached listener up vector.

◆ engine_

ma_engine audio::AudioSystem::engine_
private

miniaudio engine instance

◆ listener_state_dirty_

bool audio::AudioSystem::listener_state_dirty_
mutableprivate

Flag to track if listener state needs update.

◆ master_volume_

float audio::AudioSystem::master_volume_
private

Master volume level.


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