diff --git a/include/SoundSources/StaticSoundSource.hpp b/include/SoundSources/StaticSoundSource.hpp index ac235ab..30bfe72 100644 --- a/include/SoundSources/StaticSoundSource.hpp +++ b/include/SoundSources/StaticSoundSource.hpp @@ -1,7 +1,7 @@ #pragma once #include "BaseSoundSource.hpp" - +#include "Enums/XFiWorkaround.hpp" namespace MetaAudio { @@ -16,7 +16,7 @@ namespace MetaAudio alure::Buffer m_buffer; - float* al_xfi_workaround; + XFiWorkaround m_xfi_workaround{}; public: StaticSoundSource(const alure::Buffer& buffer, alure::Source& source); diff --git a/include/Utilities/ChannelManager.hpp b/include/Utilities/ChannelManager.hpp index bdd0575..af76a8f 100644 --- a/include/Utilities/ChannelManager.hpp +++ b/include/Utilities/ChannelManager.hpp @@ -12,8 +12,6 @@ namespace MetaAudio friend AudioEngine; private: - cvar_t* al_xfi_workaround; - struct { std::vector static_; diff --git a/src/AudioEngine.cpp b/src/AudioEngine.cpp index 56a0096..a390c05 100644 --- a/src/AudioEngine.cpp +++ b/src/AudioEngine.cpp @@ -312,17 +312,17 @@ namespace MetaAudio AL_CopyVector(forward, orientation); AL_CopyVector(up, orientation + 3); - alure::Listener al_listener = al_context->getListener(); - if (openal_mute) - { - al_listener.setGain(0.0f); - } - else - { - al_listener.setGain(std::clamp(settings.Volume(), 0.0f, 1.0f)); - } - - al_context->setDopplerFactor(std::clamp(settings.DopplerFactor(), 0.0f, 10.0f)); + alure::Listener al_listener = al_context->getListener(); + if (openal_mute) + { + al_listener.setGain(0.0f); + } + else + { + al_listener.setGain(std::clamp(settings.Volume(), 0.0f, 1.0f)); + } + + al_context->setDopplerFactor(std::clamp(settings.DopplerFactor(), 0.0f, 10.0f)); std::pair alure_orientation( alure::Vector3(orientation[0], orientation[1], orientation[2]), @@ -359,26 +359,26 @@ namespace MetaAudio al_listener.setPosition(AL_UnpackVector(origin)); al_listener.setOrientation(alure_orientation); - bool underwater = (*gAudEngine.cl_waterlevel > 2) ? true : false; - int roomtype = underwater ? - (int)settings.ReverbUnderwaterType() : - (int)settings.ReverbType(); - al_efx->InterplEffect(roomtype); + bool underwater = (*gAudEngine.cl_waterlevel > 2) ? true : false; + int roomtype = underwater ? + (int)settings.ReverbUnderwaterType() : + (int)settings.ReverbType(); + al_efx->InterplEffect(roomtype); channel_manager->ForEachChannel([&](aud_channel_t& channel) { SND_Spatialize(&channel, false); }); - if (settings.SoundShow()) - { - std::string output; - size_t total = 0; - channel_manager->ForEachChannel([&](aud_channel_t& channel) - { - if (channel.sfx && channel.volume > 0) - { - output.append(std::to_string(static_cast(channel.volume * 255.0f)) + " " + channel.sfx->name + "\n"); - ++total; - } - }); + if (settings.SoundShow()) + { + std::string output; + size_t total = 0; + channel_manager->ForEachChannel([&](aud_channel_t& channel) + { + if (channel.sfx && channel.volume > 0) + { + output.append(std::to_string(static_cast(channel.volume * 255.0f)) + " " + channel.sfx->name + "\n"); + ++total; + } + }); if (!output.empty()) { @@ -432,10 +432,10 @@ namespace MetaAudio return; } - if (settings.NoSound()) - { - return; - } + if (settings.NoSound()) + { + return; + } if (sfx->name[0] == '*') entchannel = CHAN_STREAM; @@ -515,30 +515,30 @@ namespace MetaAudio vox->InitMouth(entnum, entchannel); } - if (ch->entchannel == CHAN_STREAM || (ch->entchannel >= CHAN_NETWORKVOICE_BASE && ch->entchannel <= CHAN_NETWORKVOICE_END)) - { - if (ch->entchannel >= CHAN_NETWORKVOICE_BASE && ch->entchannel <= CHAN_NETWORKVOICE_END) - { - ch->sound_source = SoundSourceFactory::GetStreamingSource(sc->decoder, al_context->createSource(), 1024, 2); - delete sc; // must be deleted here as voice data does not go to the cache to be deleted later - sc = nullptr; - } - else - { - ch->sound_source = SoundSourceFactory::GetStreamingSource(sc->decoder, al_context->createSource(), 4096, 4); - } - } - else - { - if (settings.XfiWorkaround() == XFiWorkaround::Streaming || sc->force_streaming) - { - ch->sound_source = SoundSourceFactory::GetStreamingSource(al_context->createDecoder(sc->buffer.getName()), al_context->createSource(), 16384, 4); - } - else - { - ch->sound_source = SoundSourceFactory::GetStaticSource(sc->buffer, al_context->createSource()); - } - } + if (ch->entchannel == CHAN_STREAM || (ch->entchannel >= CHAN_NETWORKVOICE_BASE && ch->entchannel <= CHAN_NETWORKVOICE_END)) + { + if (ch->entchannel >= CHAN_NETWORKVOICE_BASE && ch->entchannel <= CHAN_NETWORKVOICE_END) + { + ch->sound_source = SoundSourceFactory::GetStreamingSource(sc->decoder, al_context->createSource(), 1024, 2); + delete sc; // must be deleted here as voice data does not go to the cache to be deleted later + sc = nullptr; + } + else + { + ch->sound_source = SoundSourceFactory::GetStreamingSource(sc->decoder, al_context->createSource(), 4096, 4); + } + } + else + { + if (settings.XfiWorkaround() == XFiWorkaround::Streaming || sc->force_streaming) + { + ch->sound_source = SoundSourceFactory::GetStreamingSource(al_context->createDecoder(sc->buffer.getName()), al_context->createSource(), 16384, 4); + } + else + { + ch->sound_source = SoundSourceFactory::GetStaticSource(sc->buffer, al_context->createSource()); + } + } try { @@ -759,34 +759,34 @@ namespace MetaAudio } } - void AudioEngine::S_Init() - { - gAudEngine.S_Init(); + void AudioEngine::S_Init() + { + gAudEngine.S_Init(); - if (!gEngfuncs.CheckParm("-nosound", NULL)) - { - S_StopAllSounds(true); - } + if (!gEngfuncs.CheckParm("-nosound", NULL)) + { + S_StopAllSounds(true); + } - SteamAudio_Init(); - settings.Init(gEngfuncs); - AL_ResetEFX(); + SteamAudio_Init(); + settings.Init(gEngfuncs); + AL_ResetEFX(); channel_manager = alure::MakeUnique(); vox = alure::MakeUnique(this, m_loader); } - std::shared_ptr AudioEngine::GetOccluder() - { - if (settings.Occluder() == OccluderType::SteamAudio) - { - return std::make_shared(sa_meshloader, *gEngfuncs.pEventAPI); - } - else - { - return std::make_shared(*gEngfuncs.pEventAPI); - } - } + std::shared_ptr AudioEngine::GetOccluder() + { + if (settings.Occluder() == OccluderType::SteamAudio) + { + return std::make_shared(sa_meshloader, *gEngfuncs.pEventAPI); + } + else + { + return std::make_shared(*gEngfuncs.pEventAPI); + } + } AudioEngine::~AudioEngine() { diff --git a/src/SoundSources/StaticSoundSource.cpp b/src/SoundSources/StaticSoundSource.cpp index 366c224..cb39cac 100644 --- a/src/SoundSources/StaticSoundSource.cpp +++ b/src/SoundSources/StaticSoundSource.cpp @@ -1,33 +1,34 @@ #include "snd_local.h" #include "SoundSources/StaticSoundSource.hpp" +#include "Config/SettingsManager.hpp" namespace MetaAudio { - StaticSoundSource::StaticSoundSource(const alure::Buffer& buffer, alure::Source& source): m_buffer(buffer) - { - al_xfi_workaround = &gEngfuncs.pfnGetCvarPointer("al_xfi_workaround")->value; - m_source = alure::AutoObj(source); - m_frequency = buffer.getFrequency(); - m_length = buffer.getLength(); - } + StaticSoundSource::StaticSoundSource(const alure::Buffer& buffer, alure::Source& source) : m_buffer(buffer) + { + m_xfi_workaround = settings.XfiWorkaround(); + m_source = alure::AutoObj(source); + m_frequency = buffer.getFrequency(); + m_length = buffer.getLength(); + } - void StaticSoundSource::Play() - { - m_source->play(m_buffer); - m_start_time = std::chrono::steady_clock::now(); - m_maximum_end_time = m_start_time + std::chrono::milliseconds(static_cast(static_cast(m_length) / m_frequency * 1.5 * 1000)); // 50% of safety - } + void StaticSoundSource::Play() + { + m_source->play(m_buffer); + m_start_time = std::chrono::steady_clock::now(); + m_maximum_end_time = m_start_time + std::chrono::milliseconds(static_cast(static_cast(m_length) / m_frequency * 1.5 * 1000)); // 50% of safety + } - bool StaticSoundSource::IsPlaying() - { - if (*al_xfi_workaround == 1.0f) - { - return m_source->isPlaying() && std::chrono::steady_clock::now() < m_maximum_end_time; - } - else - { - return m_source->isPlaying(); - } - } + bool StaticSoundSource::IsPlaying() + { + if (m_xfi_workaround == XFiWorkaround::Timer) + { + return m_source->isPlaying() && std::chrono::steady_clock::now() < m_maximum_end_time; + } + else + { + return m_source->isPlaying(); + } + } } \ No newline at end of file