Phase 4 volume
Some checks are pending
Build / setup (push) Waiting to run
Build / build-appimage (push) Blocked by required conditions
Build / build-steamlink (push) Blocked by required conditions
Build / build-windows-macos (push) Blocked by required conditions

This commit is contained in:
Joey Yakimowich-Payne 2026-02-11 21:20:48 -07:00
commit 9e52a4200b
6 changed files with 182 additions and 9 deletions

View file

@ -8,6 +8,7 @@
#include "renderers/sdl.h"
#include <Limelight.h>
#include <cmath>
#define TRY_INIT_RENDERER(renderer, opusConfig) \
{ \
@ -183,7 +184,7 @@ void Session::arDecodeAndPlaySample(char* sampleData, int sampleLength)
s_ActiveSession->m_AudioSampleCount++;
// If audio is muted, don't decode or play the audio
if (s_ActiveSession->m_AudioMuted) {
if (s_ActiveSession->m_AudioMuted.load(std::memory_order_relaxed)) {
return;
}
@ -217,6 +218,27 @@ void Session::arDecodeAndPlaySample(char* sampleData, int sampleLength)
if (samplesDecoded > 0) {
SDL_assert(desiredBufferSize >= frameSize * samplesDecoded);
desiredBufferSize = frameSize * samplesDecoded;
const float volume = s_ActiveSession->getAudioVolumeScalar();
if (volume <= 0.0f) {
SDL_memset(buffer, 0, desiredBufferSize);
}
else if (volume < 1.0f) {
const int totalSamples = samplesDecoded * s_ActiveSession->m_ActiveAudioConfig.channelCount;
if (s_ActiveSession->m_AudioRenderer->getAudioBufferFormat() == IAudioRenderer::AudioFormat::Float32NE) {
float* output = (float*)buffer;
for (int i = 0; i < totalSamples; i++) {
output[i] = SDL_clamp(output[i] * volume, -1.0f, 1.0f);
}
}
else {
short* output = (short*)buffer;
for (int i = 0; i < totalSamples; i++) {
const int scaled = (int) std::lround((float)output[i] * volume);
output[i] = (short)SDL_clamp(scaled, -32768, 32767);
}
}
}
}
else {
desiredBufferSize = 0;