X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Faudio%2Faudio.cpp;h=c7ed554ee8304e880fb8ce2f2587437b76d27b1d;hb=150d065f431d665326fd8028748c48a74ad956bb;hp=426745f7912b60383f16b32739c151f486e24f6b;hpb=045a6ec084bf1fb4df3c6ade4a88932cf61bed23;p=blank.git diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 426745f..c7ed554 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -1,6 +1,10 @@ #include "ALError.hpp" #include "Audio.hpp" #include "Sound.hpp" +#include "SoundBank.hpp" + +#include "../app/Assets.hpp" +#include "../shared/ResourceIndex.hpp" #include #include @@ -48,7 +52,8 @@ ALError::ALError(ALenum num, const std::string &msg) } -Audio::Audio() { +Audio::Audio() +: last_free(0) { alGenSources(NUM_SRC, source); ALenum err = alGetError(); if (err != AL_NO_ERROR) { @@ -99,7 +104,7 @@ void Audio::Play( } ALuint src = source[i]; - IntervalTimer &t = timer[i]; + CoarseTimer &t = timer[i]; sound.Bind(src); alSourcefv(src, AL_POSITION, glm::value_ptr(pos)); @@ -107,7 +112,7 @@ void Audio::Play( alSourcefv(src, AL_DIRECTION, glm::value_ptr(dir)); alSourcePlay(src); - t = IntervalTimer(sound.Duration()); + t = CoarseTimer(sound.Duration()); t.Start(); } @@ -147,11 +152,7 @@ int Audio::NextFree() noexcept { Sound::Sound() : handle(AL_NONE) , duration(0) { - alGenBuffers(1, &handle); - ALenum err = alGetError(); - if (err != AL_NO_ERROR) { - throw ALError(err, "alGenBuffers"); - } + } Sound::Sound(const char *file) @@ -175,18 +176,19 @@ Sound::~Sound() { ALenum err = alGetError(); if (err != AL_NO_ERROR) { std::cerr << "warning: alDeleteBuffers failed with " << al_error_string(err) << std::endl; - //throw ALError(err, "alDeleteBuffers"); } } } Sound::Sound(Sound &&other) -: handle(other.handle) { +: handle(other.handle) +, duration(other.duration) { other.handle = AL_NONE; } Sound &Sound::operator =(Sound &&other) { std::swap(handle, other.handle); + std::swap(duration, other.duration); return *this; } @@ -194,4 +196,18 @@ void Sound::Bind(ALuint src) const { alSourcei(src, AL_BUFFER, handle); } + +SoundBank::SoundBank() +: sounds() { + +} + +void SoundBank::Load(const AssetLoader &loader, const ResourceIndex &index) { + sounds.clear(); + sounds.resize(index.Size()); + for (const auto &entry : index.Entries()) { + sounds[entry.second] = loader.LoadSound(entry.first); + } +} + }