Kemena3D
Loading...
Searching...
No Matches
kemena::kAudioManager Class Reference

Owns the miniaudio engine and acts as a factory for kAudio instances. More...

#include <kaudiomanager.h>

Public Member Functions

 kAudioManager ()
 Constructs the manager; call init() before use.
 ~kAudioManager ()
 Destroys the manager, calling shutdown() if still active.
bool init ()
 Initialises the underlying miniaudio engine.
void shutdown ()
 Stops all sounds, unloads every kAudio, and tears down the engine. Called automatically by the destructor.
void setMasterVolume (float volume)
 Sets the master output volume.
float getMasterVolume () const
 Returns the current master volume.
void setListenerPosition (const kVec3 &position)
 Moves the audio listener to a new world-space position.
void setListenerDirection (const kVec3 &forward, const kVec3 &up)
 Sets the listener's orientation.
void setListenerVelocity (const kVec3 &velocity)
 Sets the listener's velocity for Doppler shift calculation.
kAudioloadAudio (const kString &filePath)
 Loads an audio file and returns a new kAudio instance.
void unloadAudio (kAudio *audio)
 Stops and destroys a previously loaded kAudio.

Detailed Description

Owns the miniaudio engine and acts as a factory for kAudio instances.

Create one kAudioManager per application. Call init() before loading any audio, and shutdown() (or let the destructor do it) when done.

audio->init();
kAudio* music = audio->loadAudio("Assets/audio/music.ogg");
music->setLooping(true);
music->play();
// Set listener position each frame
audio->setListenerPosition(camera->getPosition());
audio->setListenerDirection(camera->getForward(), camera->getUp());
Represents a loaded audio clip that can be played, stopped, and positioned.
Definition kaudio.h:36
void play()
Starts or resumes playback from the current position.
void setLooping(bool loop)
Sets the looping flag.
bool init()
Initialises the underlying miniaudio engine.
kAudio * loadAudio(const kString &filePath)
Loads an audio file and returns a new kAudio instance.
kAudioManager()
Constructs the manager; call init() before use.
void setListenerPosition(const kVec3 &position)
Moves the audio listener to a new world-space position.
void setListenerDirection(const kVec3 &forward, const kVec3 &up)
Sets the listener's orientation.

Constructor & Destructor Documentation

◆ kAudioManager()

kemena::kAudioManager::kAudioManager ( )

Constructs the manager; call init() before use.

◆ ~kAudioManager()

kemena::kAudioManager::~kAudioManager ( )

Destroys the manager, calling shutdown() if still active.

Member Function Documentation

◆ getMasterVolume()

float kemena::kAudioManager::getMasterVolume ( ) const

Returns the current master volume.

◆ init()

bool kemena::kAudioManager::init ( )

Initialises the underlying miniaudio engine.

Returns
true on success; false if the audio device could not be opened.

◆ loadAudio()

kAudio * kemena::kAudioManager::loadAudio ( const kString & filePath)

Loads an audio file and returns a new kAudio instance.

The returned pointer is owned by this manager. Release it with unloadAudio() rather than deleting it directly.

Supports any format miniaudio accepts: WAV, MP3, FLAC, OGG (via stb_vorbis).

Parameters
filePathPath to the audio file.
Returns
Pointer to the loaded kAudio, or nullptr on failure.

◆ setListenerDirection()

void kemena::kAudioManager::setListenerDirection ( const kVec3 & forward,
const kVec3 & up )

Sets the listener's orientation.

Parameters
forwardNormalised forward vector.
upNormalised up vector.

◆ setListenerPosition()

void kemena::kAudioManager::setListenerPosition ( const kVec3 & position)

Moves the audio listener to a new world-space position.

Parameters
positionListener position (typically the camera position).

◆ setListenerVelocity()

void kemena::kAudioManager::setListenerVelocity ( const kVec3 & velocity)

Sets the listener's velocity for Doppler shift calculation.

Parameters
velocityVelocity in world units per second.

◆ setMasterVolume()

void kemena::kAudioManager::setMasterVolume ( float volume)

Sets the master output volume.

Parameters
volumeLinear scalar; 0.0 = mute, 1.0 = full volume.

◆ shutdown()

void kemena::kAudioManager::shutdown ( )

Stops all sounds, unloads every kAudio, and tears down the engine. Called automatically by the destructor.

◆ unloadAudio()

void kemena::kAudioManager::unloadAudio ( kAudio * audio)

Stops and destroys a previously loaded kAudio.

Parameters
audioPointer returned by loadAudio().

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