feat(audio): integrate OpenAL audio engine with WAV/MP3/FLAC support

This commit is contained in:
2026-07-06 15:56:42 +08:00
parent c098fdbc72
commit d23540ff86
18 changed files with 400 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
#include "Cubed/audio/audio_engine.hpp"
#include "Cubed/tools/log.hpp"
#include <stdexcept>
namespace Cubed {
AudioEngine::AudioEngine() {};
AudioEngine::~AudioEngine() {
if (!m_init) {
return;
}
m_bgm.reset();
m_sounds.clear();
alcMakeContextCurrent(nullptr);
alcDestroyContext(context);
alcCloseDevice(device);
}
void AudioEngine::init() {
device = alcOpenDevice(NULL);
if (!device) {
throw std::runtime_error("Failed to open OpenAL device.");
}
context = alcCreateContext(device, nullptr);
if (!context) {
throw std::runtime_error("Failed to create OpenAL context.");
}
alcMakeContextCurrent(context);
m_sounds.init();
m_bgm = std::make_unique<AudioSource>();
m_bgm->set_buffer(m_sounds.get_buffer("bgm/bgm001.mp3"));
Logger::info("Audio Engine Init Success");
m_init = true;
}
void AudioEngine::play_bgm() { m_bgm->play(); }
void AudioEngine::update(glm::vec3 listener_pos) {}
} // namespace Cubed