From 770314fd7e86c0be355f19bd4273ebd12d5bcdc6 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 18 Jul 2023 18:18:02 +1000 Subject: [PATCH] Unused alternate blending for stereo --- source/frontend/StarVoice.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/source/frontend/StarVoice.cpp b/source/frontend/StarVoice.cpp index 9d84033..f27c000 100644 --- a/source/frontend/StarVoice.cpp +++ b/source/frontend/StarVoice.cpp @@ -288,9 +288,31 @@ void Voice::mix(int16_t* buffer, size_t frameCount, unsigned channels) { speakerBuffer[i] = audio->take(); speaker->decibelLevel = getAudioLoudness(speakerBuffer.data(), samples); - auto channelVolumes = speaker->channelVolumes.load(); + + auto levels = speaker->channelVolumes.load(); for (size_t i = 0; i != samples; ++i) - sharedBuffer[i] += (int32_t)(speakerBuffer[i]) * channelVolumes[i % 2]; + sharedBuffer[i] += (int32_t)(speakerBuffer[i]) * levels[i % 2]; + //Blends the weaker channel into the stronger one, + /* unused, is a bit too strong on stereo music. + float maxLevel = max(levels[0], levels[1]); + float leftToRight = maxLevel != 0.0f ? 1.0f - (levels[0] / maxLevel) : 0.0f; + float rightToLeft = maxLevel != 0.0f ? 1.0f - (levels[1] / maxLevel) : 0.0f; + + int16_t* speakerData = speakerBuffer.data(); + int32_t* sharedData = sharedBuffer.data(); + for (size_t i = 0; i != frameCount; ++i) { + auto leftSample = (float)*speakerData++; + auto rightSample = (float)*speakerData++; + + if (rightToLeft != 0.0f) + leftSample = ( leftSample + rightSample * rightToLeft) / (1.0f + rightToLeft); + if (leftToRight != 0.0f) + rightSample = (rightSample + leftSample * leftToRight) / (1.0f + leftToRight); + + *sharedData++ += (int32_t)leftSample * levels[0]; + *sharedData++ += (int32_t)rightSample * levels[1]; + } + //*/ } else { for (size_t i = 0; i != samples; ++i)