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

Represents a loaded audio clip that can be played, stopped, and positioned. More...

#include <kaudio.h>

Public Member Functions

 kAudio ()
 Constructs an empty audio clip; call initFromFile() (via kAudioManager) before use.
 ~kAudio ()
 Destructor; releases the underlying miniaudio sound resource.
void play ()
 Starts or resumes playback from the current position.
void stop ()
 Stops playback and resets the cursor to the beginning.
void pause ()
 Pauses playback without resetting the cursor.
void resume ()
 Resumes a paused sound. Equivalent to play() if already stopped.
void setLooping (bool loop)
 Sets the looping flag.
void setVolume (float volume)
 Sets the playback volume.
void setPitch (float pitch)
 Sets the playback pitch / speed multiplier.
void setPosition (const kVec3 &position)
 Positions the sound in 3D world space for spatialized audio.
void setVelocity (const kVec3 &velocity)
 Sets the velocity of the audio emitter (used for Doppler shift).
void setSpatialization (bool enable)
 Enables or disables 3D spatialization for this sound.
bool isPlaying () const
 Returns true if the sound is currently playing.
bool isPaused () const
 Returns true if the sound is paused.
bool isLooping () const
 Returns true if the looping flag is set.
bool initFromFile (void *maEngine, const kString &filePath)
 Initialises the sound from a file using an existing miniaudio engine.
void uninit ()
 Releases the miniaudio sound resource.

Detailed Description

Represents a loaded audio clip that can be played, stopped, and positioned.

Instances must be created through kAudioManager::loadAudio() and destroyed with kAudioManager::unloadAudio() — do not instantiate directly.

2D audio (default)
kAudio* sfx = audioManager->loadAudio("Assets/audio/explosion.wav");
sfx->setVolume(0.8f);
sfx->play();
kAudio()
Constructs an empty audio clip; call initFromFile() (via kAudioManager) before use.
void setVolume(float volume)
Sets the playback volume.
void play()
Starts or resumes playback from the current position.
3D positional audio
kAudio* footstep = audioManager->loadAudio("Assets/audio/footstep.wav");
footstep->setPosition(kVec3(10.f, 0.f, -5.f));
footstep->setLooping(true);
footstep->play();
void setPosition(const kVec3 &position)
Positions the sound in 3D world space for spatialized audio.
void setLooping(bool loop)
Sets the looping flag.
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33

Constructor & Destructor Documentation

◆ kAudio()

kemena::kAudio::kAudio ( )

Constructs an empty audio clip; call initFromFile() (via kAudioManager) before use.

◆ ~kAudio()

kemena::kAudio::~kAudio ( )

Destructor; releases the underlying miniaudio sound resource.

Member Function Documentation

◆ initFromFile()

bool kemena::kAudio::initFromFile ( void * maEngine,
const kString & filePath )

Initialises the sound from a file using an existing miniaudio engine.

Parameters
maEngineOpaque pointer to a ma_engine instance owned by kAudioManager.
filePathPath to the audio file (WAV, MP3, FLAC, OGG, …).
Returns
true on success.
Note
Not part of the public API — call kAudioManager::loadAudio() instead.

◆ isLooping()

bool kemena::kAudio::isLooping ( ) const

Returns true if the looping flag is set.

◆ isPaused()

bool kemena::kAudio::isPaused ( ) const

Returns true if the sound is paused.

◆ isPlaying()

bool kemena::kAudio::isPlaying ( ) const

Returns true if the sound is currently playing.

◆ pause()

void kemena::kAudio::pause ( )

Pauses playback without resetting the cursor.

◆ play()

void kemena::kAudio::play ( )

Starts or resumes playback from the current position.

◆ resume()

void kemena::kAudio::resume ( )

Resumes a paused sound. Equivalent to play() if already stopped.

◆ setLooping()

void kemena::kAudio::setLooping ( bool loop)

Sets the looping flag.

Parameters
looptrue to loop indefinitely.

◆ setPitch()

void kemena::kAudio::setPitch ( float pitch)

Sets the playback pitch / speed multiplier.

Parameters
pitch1.0 = normal speed; >1.0 = higher pitch and faster.

◆ setPosition()

void kemena::kAudio::setPosition ( const kVec3 & position)

Positions the sound in 3D world space for spatialized audio.

Parameters
positionWorld-space position of the audio emitter.

◆ setSpatialization()

void kemena::kAudio::setSpatialization ( bool enable)

Enables or disables 3D spatialization for this sound.

Parameters
enablefalse = 2D (no panning or attenuation); true = 3D (default for loaded sounds).

◆ setVelocity()

void kemena::kAudio::setVelocity ( const kVec3 & velocity)

Sets the velocity of the audio emitter (used for Doppler shift).

Parameters
velocityVelocity vector in world units per second.

◆ setVolume()

void kemena::kAudio::setVolume ( float volume)

Sets the playback volume.

Parameters
volumeLinear amplitude scalar; 0.0 = silent, 1.0 = full volume.

◆ stop()

void kemena::kAudio::stop ( )

Stops playback and resets the cursor to the beginning.

◆ uninit()

void kemena::kAudio::uninit ( )

Releases the miniaudio sound resource.


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