Skip to content

Commit

Permalink
Use settings manager everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
LAGonauta committed Dec 16, 2023
1 parent cab1fd4 commit 76166f7
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 105 deletions.
4 changes: 2 additions & 2 deletions include/SoundSources/StaticSoundSource.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "BaseSoundSource.hpp"

#include "Enums/XFiWorkaround.hpp"

namespace MetaAudio
{
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions include/Utilities/ChannelManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace MetaAudio
friend AudioEngine;

private:
cvar_t* al_xfi_workaround;

struct
{
std::vector<aud_channel_t> static_;
Expand Down
154 changes: 77 additions & 77 deletions src/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Vector3, alure::Vector3> alure_orientation(
alure::Vector3(orientation[0], orientation[1], orientation[2]),
Expand Down Expand Up @@ -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<int>(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<int>(channel.volume * 255.0f)) + " " + channel.sfx->name + "\n");
++total;
}
});

if (!output.empty())
{
Expand Down Expand Up @@ -432,10 +432,10 @@ namespace MetaAudio
return;
}

if (settings.NoSound())
{
return;
}
if (settings.NoSound())
{
return;
}

if (sfx->name[0] == '*')
entchannel = CHAN_STREAM;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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<ChannelManager>();
vox = alure::MakeUnique<VoxManager>(this, m_loader);
}

std::shared_ptr<IOcclusionCalculator> AudioEngine::GetOccluder()
{
if (settings.Occluder() == OccluderType::SteamAudio)
{
return std::make_shared<SteamAudioOcclusionCalculator>(sa_meshloader, *gEngfuncs.pEventAPI);
}
else
{
return std::make_shared<GoldSrcOcclusionCalculator>(*gEngfuncs.pEventAPI);
}
}
std::shared_ptr<IOcclusionCalculator> AudioEngine::GetOccluder()
{
if (settings.Occluder() == OccluderType::SteamAudio)
{
return std::make_shared<SteamAudioOcclusionCalculator>(sa_meshloader, *gEngfuncs.pEventAPI);
}
else
{
return std::make_shared<GoldSrcOcclusionCalculator>(*gEngfuncs.pEventAPI);
}
}

AudioEngine::~AudioEngine()
{
Expand Down
49 changes: 25 additions & 24 deletions src/SoundSources/StaticSoundSource.cpp
Original file line number Diff line number Diff line change
@@ -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<long long>(static_cast<double>(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<long long>(static_cast<double>(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();
}
}
}

0 comments on commit 76166f7

Please sign in to comment.