From d470f36a0d669d6bc21d7a17483df9de6376e67d Mon Sep 17 00:00:00 2001 From: eadmaster <51NMBsFda0ab1> Date: Tue, 22 Dec 2020 11:52:28 +0100 Subject: [PATCH] fixed missing volume on 32bit systems (#170) --- libgambatte/src/sound.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/libgambatte/src/sound.cpp b/libgambatte/src/sound.cpp index 1b0f3a04..45248e62 100644 --- a/libgambatte/src/sound.cpp +++ b/libgambatte/src/sound.cpp @@ -103,10 +103,27 @@ namespace gambatte uint_least32_t *const buf = buffer_ + bufferPos_; std::memset(buf, 0, cycles * sizeof(uint_least32_t)); - ch1_.update(buf, (soChVol_[0] * soVol_ * 0x1999999A) >> 32, cycles); - ch2_.update(buf, (soChVol_[1] * soVol_ * 0x1999999A) >> 32, cycles); - ch3_.update(buf, (soChVol_[2] * soVol_ * 0x1999999A) >> 32, cycles); - ch4_.update(buf, (soChVol_[3] * soVol_ * 0x1999999A) >> 32, cycles); + + /* apply volume scaling if set by the user */ + if (soChVol_[0]<10) + ch1_.update(buf, ((uint_fast64_t)0x1999999A * soChVol_[0] * soVol_) >> 32, cycles); + else + ch1_.update(buf, soVol_, cycles); + + if (soChVol_[1]<10) + ch2_.update(buf, ((uint_fast64_t)0x1999999A * soChVol_[1] * soVol_) >> 32, cycles); + else + ch2_.update(buf, soVol_, cycles); + + if (soChVol_[2]<10) + ch3_.update(buf, ((uint_fast64_t)0x1999999A * soChVol_[2] * soVol_) >> 32, cycles); + else + ch3_.update(buf, soVol_, cycles); + + if (soChVol_[3]<10) + ch4_.update(buf, ((uint_fast64_t)0x1999999A * soChVol_[3] * soVol_) >> 32, cycles); + else + ch4_.update(buf, soVol_, cycles); } void PSG::generateSamples(unsigned long const cycleCounter, bool const doubleSpeed)