Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into update-steamaudio
Browse files Browse the repository at this point in the history
  • Loading branch information
LAGonauta committed Dec 12, 2023
2 parents 145b3b3 + 86e2151 commit 01ee1a0
Show file tree
Hide file tree
Showing 17 changed files with 299 additions and 159 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ jobs:
submodules: recursive
fetch-depth: 0

- name: Get branch name
run: echo "BranchName=$env:GITHUB_REF_NAME" >> $env:GITHUB_ENV

- name: Get commit hash
run: echo "CommitHash=$(git rev-parse --short=7 HEAD)" >> $env:GITHUB_ENV

- name: Get commit count
run: echo "CommitCount=$(git rev-list --count master)" >> $env:GITHUB_ENV
run: echo "CommitCount=$(git rev-list --count ${{env.BranchName}})" >> $env:GITHUB_ENV

- name: Get current date
run: echo "CurrentDate=$(date +'%Y-%m-%d')" >> $env:GITHUB_ENV
Expand Down Expand Up @@ -82,8 +85,8 @@ jobs:

- name: Download MetaHook
run: |
Invoke-WebRequest -Uri https://github.com/hzqst/MetaHookSv/releases/download/v20231124b/MetaHookSv-windows-x86.zip -OutFile MetaHook.zip
if (!(Get-FileHash ./MetaHook.zip).Hash.Equals("4B22EA01E0B025CAEABD7301FEF52FA05A807263B8B761760FA3AAD7E1D2EA23")) {
Invoke-WebRequest -Uri https://github.com/hzqst/MetaHookSv/releases/download/v20231210a/MetaHookSv-windows-x86.zip -OutFile MetaHook.zip
if (!(Get-FileHash ./MetaHook.zip).Hash.Equals("E5F3DB974C0D00241125757A6CE83E1BCF114D156E8E3E27C7622CAE7DDE36A1")) {
Exit -1
}
Expand-Archive ./MetaHook.zip -DestinationPath MetaHook/
Expand All @@ -93,7 +96,7 @@ jobs:

- uses: actions/upload-artifact@v3
with:
name: '${{env.CurrentDate}}_MetaAudio-${{env.CommitCount}}@${{env.CommitHash}}'
name: '${{env.CurrentDate}}_MetaAudio-${{env.CommitCount}}@${{env.CommitHash}}-${{env.BranchName}}'
path: Output/

- name: Make Release folder
Expand All @@ -103,16 +106,16 @@ jobs:
uses: papeloto/action-zip@v1
with:
files: 'Output/'
dest: 'Release/${{env.CurrentDate}}_MetaAudio-${{env.CommitCount}}@${{env.CommitHash}}.zip'
dest: 'Release/${{env.CurrentDate}}_MetaAudio-${{env.CommitCount}}@${{env.CommitHash}}-${{env.BranchName}}.zip'

- name: Make copy for static download URL
run: copy 'Release/${{env.CurrentDate}}_MetaAudio-${{env.CommitCount}}@${{env.CommitHash}}.zip' 'Release/MetaAudio.zip'
run: copy 'Release/${{env.CurrentDate}}_MetaAudio-${{env.CommitCount}}@${{env.CommitHash}}-${{env.BranchName}}.zip' 'Release/MetaAudio.zip'

- name: GitHub pre-release
uses: 'marvinpinto/action-automatic-releases@latest'
with:
repo_token: '${{secrets.GITHUB_TOKEN}}'
automatic_release_tag: 'latest'
prerelease: true
title: '[${{env.CurrentDate}}] MetaAudio-${{env.CommitCount}}@${{env.CommitHash}}'
title: '[${{env.CurrentDate}}] MetaAudio-${{env.CommitCount}}@${{env.CommitHash}}-${{env.BranchName}}'
files: "Release/*"
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ jobs:

- name: Download MetaHook
run: |
Invoke-WebRequest -Uri https://github.com/hzqst/MetaHookSv/releases/download/v20231124b/MetaHookSv-windows-x86.zip -OutFile MetaHook.zip
if (!(Get-FileHash ./MetaHook.zip).Hash.Equals("4B22EA01E0B025CAEABD7301FEF52FA05A807263B8B761760FA3AAD7E1D2EA23")) {
Invoke-WebRequest -Uri https://github.com/hzqst/MetaHookSv/releases/download/v20231210a/MetaHookSv-windows-x86.zip -OutFile MetaHook.zip
if (!(Get-FileHash ./MetaHook.zip).Hash.Equals("E5F3DB974C0D00241125757A6CE83E1BCF114D156E8E3E27C7622CAE7DDE36A1")) {
Exit -1
}
Expand-Archive ./MetaHook.zip -DestinationPath MetaHook/
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ set(SOURCES
src/Utilities/AudioCache.cpp
src/interface.cpp
src/Config/EfxJsonReader.cpp
src/Config/SettingsManager.cpp
src/Effects/GoldSrcOcclusionCalculator.cpp
src/Effects/SteamAudioOcclusionCalculator.cpp
src/Utilities/Fade.cpp
Expand Down
2 changes: 1 addition & 1 deletion externals/MetaHookSv
11 changes: 0 additions & 11 deletions include/AudioEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ namespace MetaAudio
private:
std::unordered_map<alure::String, sfx_t> known_sfx;

//engine cvars
cvar_t* nosound = nullptr;
cvar_t* volume = nullptr;
cvar_t* sxroomwater_type = nullptr;
cvar_t* sxroom_type = nullptr;
cvar_t* snd_show = nullptr;

//active control
cvar_t* al_doppler = nullptr;
cvar_t* al_xfi_workaround = nullptr;
cvar_t* al_occluder = nullptr;
bool openal_started = false;
bool openal_mute = false;

Expand Down
37 changes: 37 additions & 0 deletions include/Config/SettingsManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "Enums/XFiWorkaround.hpp"
#include "Enums/OccluderType.hpp"

namespace MetaAudio
{
class SettingsManager final
{
public:
void Init(const cl_enginefunc_t& engFuncs);

bool NoSound();

bool OcclusionEnabled();
bool OcclusionFade();

bool ReverbEnabled();
size_t ReverbType();
size_t ReverbUnderwaterType();

bool SoundShow();

float DopplerFactor();

float Volume();

OccluderType Occluder();

XFiWorkaround XfiWorkaround();
};
}

#ifndef _METAAUDIO_SETTINGS_MANAGER_
#define _METAAUDIO_SETTINGS_MANAGER_
extern MetaAudio::SettingsManager settings;
#endif
10 changes: 10 additions & 0 deletions include/Enums/OccluderType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

namespace MetaAudio
{
enum class OccluderType
{
GoldSrc,
SteamAudio
};
}
11 changes: 11 additions & 0 deletions include/Enums/XFiWorkaround.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace MetaAudio
{
enum class XFiWorkaround
{
Disabled,
Timer,
Streaming
};
}
2 changes: 1 addition & 1 deletion include/Loaders/LocalAudioDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace MetaAudio
private:
struct Audio
{
wavinfo_t info;
wavinfo_t info{};
alure::Vector<ALubyte> data;
};

Expand Down
170 changes: 77 additions & 93 deletions src/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Effects/SteamAudioOcclusionCalculator.hpp"

#include "SoundSources/SoundSourceFactory.hpp"
#include "Config/SettingsManager.hpp"

namespace MetaAudio
{
Expand Down Expand Up @@ -311,20 +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
{
if (volume)
al_listener.setGain(std::clamp(volume->value, 0.0f, 1.0f));
else
al_listener.setGain(1.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(al_doppler->value, 0.0f, 10.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 @@ -361,28 +359,26 @@ namespace MetaAudio
al_listener.setPosition(AL_UnpackVector(origin));
al_listener.setOrientation(alure_orientation);

int roomtype = 0;
bool underwater = (*gAudEngine.cl_waterlevel > 2) ? true : false;
if (sxroomwater_type && sxroom_type)
{
roomtype = underwater ? (int)sxroomwater_type->value : (int)sxroom_type->value;
}
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 (snd_show && snd_show->value)
{
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 @@ -436,10 +432,10 @@ namespace MetaAudio
return;
}

if (nosound && nosound->value)
{
return;
}
if (settings.NoSound())
{
return;
}

if (sfx->name[0] == '*')
entchannel = CHAN_STREAM;
Expand Down Expand Up @@ -519,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 (al_xfi_workaround->value == 2.0f || 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 @@ -763,46 +759,34 @@ namespace MetaAudio
}
}

void AudioEngine::S_Init()
{
al_doppler = gEngfuncs.pfnRegisterVariable("al_doppler", "1", FCVAR_EXTDLL);
al_xfi_workaround = gEngfuncs.pfnRegisterVariable("al_xfi_workaround", "0", FCVAR_EXTDLL);
if (gSteamAudio.IsValid())
{
al_occluder = gEngfuncs.pfnRegisterVariable("al_occluder", "0", FCVAR_EXTDLL);
}
void AudioEngine::S_Init()
{
gAudEngine.S_Init();

gAudEngine.S_Init();
if (!gEngfuncs.CheckParm("-nosound", NULL))
{
S_StopAllSounds(true);
}

if (!gEngfuncs.CheckParm("-nosound", NULL))
{
nosound = gEngfuncs.pfnGetCvarPointer("nosound");
volume = gEngfuncs.pfnGetCvarPointer("volume");
sxroomwater_type = gEngfuncs.pfnGetCvarPointer("waterroom_type");
sxroom_type = gEngfuncs.pfnGetCvarPointer("room_type");
snd_show = gEngfuncs.pfnGetCvarPointer("snd_show");

S_StopAllSounds(true);
}

SteamAudio_Init();
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 (!al_occluder || al_occluder->value == 0.0f)
{
return std::make_shared<GoldSrcOcclusionCalculator>(*gEngfuncs.pEventAPI);
}
else
{
return std::make_shared<SteamAudioOcclusionCalculator>(sa_meshloader, *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
Loading

0 comments on commit 01ee1a0

Please sign in to comment.