From 16da7a2aa6b28c27f2528ba1c4ca65a4104b7f4b Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Sun, 21 Nov 2021 10:39:47 -0800 Subject: [PATCH] fix audio mixing for GambatteLink3x --- .../Gameboy/GambatteLink.ISoundProvider.cs | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.ISoundProvider.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.ISoundProvider.cs index 05310b1e83..7e9ca7b22d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.ISoundProvider.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.ISoundProvider.cs @@ -93,15 +93,46 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy // since P2 is center, mix its samples with P1 and P3 _linkedBlips[P1].ReadSamplesLeft(_settings._linkedSettings[P1].Muted ? ScratchBuffer : SampleBuffer, count); _linkedBlips[P3].ReadSamplesRight(_settings._linkedSettings[P3].Muted ? ScratchBuffer : SampleBuffer, count); - _linkedBlips[P2].ReadSamples(ScratchBuffer, count, false); + _linkedBlips[P2].ReadSamplesLeft(ScratchBuffer, count); if (!_settings._linkedSettings[P2].Muted) { fixed (short* p = SampleBuffer, q = ScratchBuffer) { - for (int i = 0; i < SampleBuffer.Length; i++) + if (_settings._linkedSettings[P1].Muted && _settings._linkedSettings[P3].Muted) { - int s = (p[i] + q[i]) / 2; - p[i] = (short)s; + for (int i = 0; i < SampleBuffer.Length; i += 2) + { + p[i] = q[i]; + p[i + 1] = q[i]; + } + } + else if (_settings._linkedSettings[P1].Muted) + { + for (int i = 0; i < SampleBuffer.Length; i += 2) + { + p[i] = q[i]; + int s = (p[i + 1] + q[i]) / 2; + p[i + 1] = (short)s; + } + } + else if (_settings._linkedSettings[P3].Muted) + { + for (int i = 0; i < SampleBuffer.Length; i += 2) + { + int s = (p[i] + q[i]) / 2; + p[i] = (short)s; + p[i + 1] = q[i]; + } + } + else + { + for (int i = 0; i < SampleBuffer.Length; i += 2) + { + int s = (p[i] + q[i]) / 2; + p[i] = (short)s; + s = (p[i + 1] + q[i]) / 2; + p[i + 1] = (short)s; + } } } }