1#include "audio/Audio.h"
13 ma_sound_uninit(m_sound.get());
17 ma_decoder_uninit(m_decoder.get());
25 ma_sound_set_position(m_sound.get(), position.x, position.y, position.z);
33 ma_sound_start(m_sound.get());
34 auto looping = loop ? MA_TRUE : MA_FALSE;
35 ma_sound_set_looping(m_sound.get(), looping);
43 ma_sound_stop(m_sound.get());
44 ma_sound_seek_to_pcm_frame(m_sound.get(), 0);
52 return ma_sound_is_playing(m_sound.get());
61 ma_sound_set_volume(m_sound.get(), std::clamp(volume, 0.0f, 1.0f));
69 return ma_sound_get_volume(m_sound.get());
79 auto audio = std::make_shared<Audio>();
80 audio->m_sound = std::make_unique<ma_sound>();
81 audio->m_buffer = buffer;
82 audio->m_decoder = std::make_unique<ma_decoder>();
84 ma_decoder_init_memory(audio->m_buffer.data(), audio->m_buffer.size(),
nullptr, audio->m_decoder.get());
85 if (result != MA_SUCCESS)
89 result = ma_sound_init_from_data_source(engine, audio->m_decoder.get(), 0, NULL, audio->m_sound.get());
90 if (result != MA_SUCCESS)
95 ma_sound_set_spatialization_enabled(audio->m_sound.get(), MA_TRUE);
ma_engine * GetEngine()
Underlying miniaudio engine handle (passed to clip Play()).
void Play(bool loop=false)
Start playback. Pass true to loop forever.
void Stop()
Halt playback if currently playing; no-op otherwise.
void SetPosition(const glm::vec3 &position)
Place the emitter at a world-space position (3D spatialisation).
void SetVolume(float volume)
Linear gain in [0, 1]. Values above 1 amplify but may clip.
bool IsPlaying() const
True between Play() and natural end / Stop().
static std::shared_ptr< Audio > Load(const std::string &path)
Decode an audio file from disk and return a shared instance.
FileSystem & GetFileSystem()
Returns the file system helper for asset-relative path resolution.
AudioManager & GetAudioManager()
static Engine & GetInstance()
Returns the single Engine instance (created on first call).
std::vector< char > LoadAssetFile(const std::string &relativePath)
Load a file from the assets directory into a byte buffer.