From 48159d2fe5a866552a25215a09be666571ff768a Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 14:28:03 +0000 Subject: [PATCH] Fix pan and IRateConverters --- sdl2-hyper-sonic-drivers/examples/pcm-example.cpp | 2 +- .../HyperSonicDrivers/audio/converters/CopyRateConverter.hpp | 4 ++-- .../audio/converters/LinearRateConverter.hpp | 4 ++-- .../audio/converters/SimpleRateConverter.hpp | 4 ++-- .../src/HyperSonicDrivers/audio/mixer/Channel.cpp | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp index d640781e..4ec2058c 100644 --- a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) for (int i = 0, sig = +1; i < 3; i++, sig *= -1) { cout << i << ". playing same sound again reversed balance" << endl; - delayMillis(200); + delayMillis(500); drv.play(wavSound, 150, 127 * sig); drv.play(vocSound, 255, -127 * sig); } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp index 2a87bf3f..8d5af722 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp @@ -47,9 +47,9 @@ namespace HyperSonicDrivers::audio::converters int16_t out1 = (stereo ? *it++ : out0); // output left channel - output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l); + output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l); // output right channel - output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r); + output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r); obuf += 2; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp index 7ea2bac9..52f56d7f 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp @@ -117,9 +117,9 @@ namespace HyperSonicDrivers::audio::converters const int16_t out0 = interpolate(ilast0, icur0, opos); const int16_t out1 = stereo ? interpolate(ilast1, icur1, opos) : out0; // output left channel - output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l); + output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l); // output right channel - output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r); + output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r); obuf += 2; // Increment output position diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/SimpleRateConverter.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/SimpleRateConverter.hpp index 4530f9a1..6b54fc32 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/SimpleRateConverter.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/SimpleRateConverter.hpp @@ -95,9 +95,9 @@ namespace HyperSonicDrivers::audio::converters opos += opos_inc; // output left channel - output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l); + output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l); // output right channel - output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r); + output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r); obuf += 2; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp index 814a9fb0..f0c87746 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp @@ -118,8 +118,8 @@ namespace HyperSonicDrivers::audio::mixer const float pan = (127.5f + m_pan) / 255.0f; // TODO: create different selectable pan laws // -3dB pan law - m_volL = static_cast(std::round(sqrt(pan) * vol / ch_max_vol)); - m_volR = static_cast(std::round(sqrt(1 - pan) * vol / ch_max_vol)); + m_volL = static_cast(std::round(sqrt(1 - pan) * vol / ch_max_vol)); + m_volR = static_cast(std::round(sqrt(pan) * vol / ch_max_vol)); // adjust for master volume const auto m_vol = m_mixer.getMasterVolume();