From 920a9c3f4b68b783c8e22b0f26a4ad9304918860 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sat, 11 Nov 2023 10:00:33 +0000 Subject: [PATCH] fix rate converters mono/stereo output buffer copy --- sdl2-hyper-sonic-drivers/examples/pcm-example.cpp | 8 ++++---- .../audio/converters/CopyRateConverter.hpp | 4 ++-- .../audio/converters/LinearRateConverter.hpp | 8 ++++---- .../src/HyperSonicDrivers/files/VOCFile.cpp | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp index 9366805b..d640781e 100644 --- a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp @@ -39,12 +39,12 @@ int main(int argc, char* argv[]) delayMillis(100); } - /* drv.play(wavSound); + drv.play(wavSound); while(drv.isPlaying(wavSound)) { cout << "is playing" << endl; delayMillis(1000); - }*/ + } delayMillis(500); @@ -59,13 +59,13 @@ int main(int argc, char* argv[]) drv.play(wavSound, 150, 127); drv.play(vocSound, 255, -127); - /*for (int i = 0, sig = +1; i < 3; i++, sig *= -1) + for (int i = 0, sig = +1; i < 3; i++, sig *= -1) { cout << i << ". playing same sound again reversed balance" << endl; delayMillis(200); drv.play(wavSound, 150, 127 * sig); drv.play(vocSound, 255, -127 * sig); - }*/ + } while(drv.isPlaying()) { 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 8d5af722..2a87bf3f 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 ? 1 : 0], out0, vol_l); + output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l); // output right channel - output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r); + output_channel(obuf[reverseStereo ? 1 : 0], 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 9cbd4c59..7ea2bac9 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp @@ -101,7 +101,7 @@ namespace HyperSonicDrivers::audio::converters inLen -= (stereo ? 2 : 1); ilast0 = icur0; icur0 = *inPtr++; - if (stereo) + if constexpr (stereo) { ilast1 = icur1; icur1 = *inPtr++; @@ -114,12 +114,12 @@ namespace HyperSonicDrivers::audio::converters while (opos < fracOneLow && obuf < oend) { // interpolate - int16_t out0 = interpolate(ilast0, icur0, opos); - int16_t out1 = stereo ? interpolate(ilast1, icur1, opos) : out0; + 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 right channel - output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r); + output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r); obuf += 2; // Increment output position diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp index e55fd0b1..43e94066 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp @@ -75,7 +75,7 @@ namespace HyperSonicDrivers::files // timeConstant = 65536 - (256000000 / (channels * sampleRate); // sampleRate = 256000000 / ((65536 - (timeConstant<<8))*channels) m_sampleRate = 256000000L / ((65536 - (timeConstant << 8)) * m_channels); - //_sampleRate = 1000000 / (256 - timeConstant); + //m_sampleRate = 1000000 / (256 - timeConstant); assertValid_(m_sampleRate == (1000000 / (256 - timeConstant))); // pack Method switch (packMethod) @@ -131,10 +131,10 @@ namespace HyperSonicDrivers::files case 7: logW("end loop block not-implemented"); break; - case 8: + case 8: // extended logW("special block 8 not-implemented"); break; - case 9: + case 9: // extended 2 { assertValid_(m_version >= 0x0114); m_sampleRate = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24);