diff --git a/libgambatte/src/sound/channel1.cpp b/libgambatte/src/sound/channel1.cpp index 6b9ccf15..915ab1a2 100644 --- a/libgambatte/src/sound/channel1.cpp +++ b/libgambatte/src/sound/channel1.cpp @@ -220,14 +220,13 @@ void Channel1::loadState(const SaveState &state) { void Channel1::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cycles) { const unsigned outBase = envelopeUnit.dacIsOn() ? soBaseVol & soMask : 0; - const unsigned outLow = outBase * (0 - 15ul); const unsigned endCycles = cycleCounter + cycles; for (;;) { - const unsigned outHigh = master ? outBase * (envelopeUnit.getVolume() * 2 - 15ul) : outLow; + const unsigned outHigh = master ? outBase * (envelopeUnit.getVolume()) : 0; + const unsigned outLow = -outHigh; const unsigned nextMajorEvent = nextEventUnit->getCounter() < endCycles ? nextEventUnit->getCounter() : endCycles; unsigned out = dutyUnit.isHighState() ? outHigh : outLow; - while (dutyUnit.getCounter() <= nextMajorEvent) { *buf = out - prevOut; prevOut = out; diff --git a/libgambatte/src/sound/channel2.cpp b/libgambatte/src/sound/channel2.cpp index 6bd5b041..dc74d7cc 100644 --- a/libgambatte/src/sound/channel2.cpp +++ b/libgambatte/src/sound/channel2.cpp @@ -125,11 +125,11 @@ void Channel2::loadState(const SaveState &state) { void Channel2::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cycles) { const unsigned outBase = envelopeUnit.dacIsOn() ? soBaseVol & soMask : 0; - const unsigned outLow = outBase * (0 - 15ul); const unsigned endCycles = cycleCounter + cycles; for (;;) { - const unsigned outHigh = master ? outBase * (envelopeUnit.getVolume() * 2 - 15ul) : outLow; + const unsigned outHigh = master ? outBase * (envelopeUnit.getVolume()) : 0; + const unsigned outLow = -outHigh; const unsigned nextMajorEvent = nextEventUnit->getCounter() < endCycles ? nextEventUnit->getCounter() : endCycles; unsigned out = dutyUnit.isHighState() ? outHigh : outLow; while (dutyUnit.getCounter() <= nextMajorEvent) { diff --git a/libgambatte/src/sound/channel3.cpp b/libgambatte/src/sound/channel3.cpp index ec2c8edd..758f3d58 100644 --- a/libgambatte/src/sound/channel3.cpp +++ b/libgambatte/src/sound/channel3.cpp @@ -155,7 +155,7 @@ void Channel3::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cy for (;;) { const unsigned nextMajorEvent = lengthCounter.getCounter() < endCycles ? lengthCounter.getCounter() : endCycles; - unsigned out = outBase * (master ? ((sampleBuf >> (~wavePos << 2 & 4) & 0xF) >> rShift) * 2 - 15ul : 0 - 15ul); + unsigned out = outBase * (master ? ((sampleBuf >> (~wavePos << 2 & 4) & 0xF) >> rShift) * 2 - (15 >> rShift) : 0); while (waveCounter <= nextMajorEvent) { *buf += out - prevOut; @@ -168,7 +168,7 @@ void Channel3::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cy ++wavePos; wavePos &= 0x1F; sampleBuf = waveRam[wavePos >> 1]; - out = outBase * (/*master ? */((sampleBuf >> (~wavePos << 2 & 4) & 0xF) >> rShift) * 2 - 15ul/* : 0 - 15ul*/); + out = outBase * (/*master ? */((sampleBuf >> (~wavePos << 2 & 4) & 0xF) >> rShift) * 2 - (15 >> rShift)/* : 0 - 15ul*/); } if (cycleCounter < nextMajorEvent) { @@ -184,7 +184,7 @@ void Channel3::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cy break; } } else { - unsigned const out = outBase * (0 - 15ul); + unsigned const out = outBase * 0; *buf += out - prevOut; prevOut = out; cycleCounter += cycles; diff --git a/libgambatte/src/sound/channel4.cpp b/libgambatte/src/sound/channel4.cpp index b646dff6..5132303d 100644 --- a/libgambatte/src/sound/channel4.cpp +++ b/libgambatte/src/sound/channel4.cpp @@ -264,14 +264,13 @@ void Channel4::loadState(const SaveState &state) { void Channel4::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cycles) { const unsigned outBase = envelopeUnit.dacIsOn() ? soBaseVol & soMask : 0; - const unsigned outLow = outBase * (0 - 15ul); const unsigned endCycles = cycleCounter + cycles; for (;;) { - const unsigned outHigh = /*master ? */outBase * (envelopeUnit.getVolume() * 2 - 15ul)/* : outLow*/; + const unsigned outHigh = /*master ? */outBase * (envelopeUnit.getVolume())/* : outLow*/; + const unsigned outLow = -outHigh; const unsigned nextMajorEvent = nextEventUnit->getCounter() < endCycles ? nextEventUnit->getCounter() : endCycles; unsigned out = lfsr.isHighState() ? outHigh : outLow; - while (lfsr.getCounter() <= nextMajorEvent) { *buf += out - prevOut; prevOut = out;