From 76b8349abe9f1fb128a012a076f4184dec9b2dd0 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Thu, 5 Dec 2013 08:49:45 +0200 Subject: [PATCH] Gambatte: DC levels fixes --- ...-to-make-libgambatte-rerecording-friendly.patch | 4 +- .../svn364/0002-Expose-CPU-registers.patch | 4 +- .../svn364/0003-Fix-sound-DC-levels.patch | 107 ++++++++++++++++++++ ...-to-make-libgambatte-rerecording-friendly.patch | 4 +- .../svn537/0002-Expose-CPU-registers.patch | 4 +- .../svn537/0003-Breakpoints-debugging.patch | 4 +- .../svn537/0004-Fix-sound-DC-levels.patch | 109 +++++++++++++++++++++ 7 files changed, 226 insertions(+), 10 deletions(-) create mode 100644 libgambatte-patches/svn364/0003-Fix-sound-DC-levels.patch create mode 100644 libgambatte-patches/svn537/0004-Fix-sound-DC-levels.patch diff --git a/libgambatte-patches/svn364/0001-Changes-to-make-libgambatte-rerecording-friendly.patch b/libgambatte-patches/svn364/0001-Changes-to-make-libgambatte-rerecording-friendly.patch index 88bbb94c..a0914404 100644 --- a/libgambatte-patches/svn364/0001-Changes-to-make-libgambatte-rerecording-friendly.patch +++ b/libgambatte-patches/svn364/0001-Changes-to-make-libgambatte-rerecording-friendly.patch @@ -1,7 +1,7 @@ From f4fcace8e1261f4e0e01c7db174dc148eab1180f Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Fri, 18 Jan 2013 21:06:30 +0200 -Subject: [PATCH 1/2] Changes to make libgambatte rerecording friendly +Subject: [PATCH 1/3] Changes to make libgambatte rerecording friendly --- Makefile | 10 + @@ -5793,5 +5793,5 @@ index 22bf619..2358d2d 100644 } -- -1.8.4.3 +1.8.5 diff --git a/libgambatte-patches/svn364/0002-Expose-CPU-registers.patch b/libgambatte-patches/svn364/0002-Expose-CPU-registers.patch index 52d7df81..8d9173dc 100644 --- a/libgambatte-patches/svn364/0002-Expose-CPU-registers.patch +++ b/libgambatte-patches/svn364/0002-Expose-CPU-registers.patch @@ -1,7 +1,7 @@ From 0ba9fa35b68d63c4adcf0bd7e19eef52bdc3ecd4 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 18 Nov 2013 01:53:58 +0200 -Subject: [PATCH 2/2] Expose CPU registers +Subject: [PATCH 2/3] Expose CPU registers --- libgambatte/include/gambatte.h | 22 +++++++++++++++++++ @@ -130,5 +130,5 @@ index 9c4fcdc..380ab42 100644 +} } -- -1.8.4.3 +1.8.5 diff --git a/libgambatte-patches/svn364/0003-Fix-sound-DC-levels.patch b/libgambatte-patches/svn364/0003-Fix-sound-DC-levels.patch new file mode 100644 index 00000000..79b713b1 --- /dev/null +++ b/libgambatte-patches/svn364/0003-Fix-sound-DC-levels.patch @@ -0,0 +1,107 @@ +From 8dac6800be952bb48afec48ec2e5c597f7aefae3 Mon Sep 17 00:00:00 2001 +From: Ilari Liusvaara +Date: Thu, 5 Dec 2013 08:46:03 +0200 +Subject: [PATCH 3/3] Fix sound DC levels + +This was causing popping in Mega Man (I) +--- + libgambatte/src/sound/channel1.cpp | 5 ++--- + libgambatte/src/sound/channel2.cpp | 4 ++-- + libgambatte/src/sound/channel3.cpp | 6 +++--- + libgambatte/src/sound/channel4.cpp | 5 ++--- + 4 files changed, 9 insertions(+), 11 deletions(-) + +diff --git a/libgambatte/src/sound/channel1.cpp b/libgambatte/src/sound/channel1.cpp +index 6b9ccf1..915ab1a 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 6bd5b04..dc74d7c 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 ec2c8ed..758f3d5 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 b646dff..5132303 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; +-- +1.8.5 + diff --git a/libgambatte-patches/svn537/0001-Changes-to-make-libgambatte-rerecording-friendly.patch b/libgambatte-patches/svn537/0001-Changes-to-make-libgambatte-rerecording-friendly.patch index 7c0e44ba..5698e1ee 100644 --- a/libgambatte-patches/svn537/0001-Changes-to-make-libgambatte-rerecording-friendly.patch +++ b/libgambatte-patches/svn537/0001-Changes-to-make-libgambatte-rerecording-friendly.patch @@ -1,7 +1,7 @@ From 148f2f6e1142f9d2caa9612dd9a68069426537f8 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Fri, 9 Aug 2013 20:13:11 +0300 -Subject: [PATCH 1/3] Changes to make libgambatte rerecording friendly +Subject: [PATCH 1/4] Changes to make libgambatte rerecording friendly --- Makefile | 10 + @@ -5889,5 +5889,5 @@ index 7d8dbe1..341bce6 100644 } -- -1.8.4.4 +1.8.5 diff --git a/libgambatte-patches/svn537/0002-Expose-CPU-registers.patch b/libgambatte-patches/svn537/0002-Expose-CPU-registers.patch index 9d7362c2..dc0795e1 100644 --- a/libgambatte-patches/svn537/0002-Expose-CPU-registers.patch +++ b/libgambatte-patches/svn537/0002-Expose-CPU-registers.patch @@ -1,7 +1,7 @@ From 1bcbfe173abb9650c8ae13677d4dca4f0222ab7e Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 18 Nov 2013 01:53:58 +0200 -Subject: [PATCH 2/3] Expose CPU registers +Subject: [PATCH 2/4] Expose CPU registers --- libgambatte/include/gambatte.h | 22 +++++++++++++++++++ @@ -120,5 +120,5 @@ index 0204557..a61e177 100644 +} } -- -1.8.4.4 +1.8.5 diff --git a/libgambatte-patches/svn537/0003-Breakpoints-debugging.patch b/libgambatte-patches/svn537/0003-Breakpoints-debugging.patch index 98564d6d..104dce56 100644 --- a/libgambatte-patches/svn537/0003-Breakpoints-debugging.patch +++ b/libgambatte-patches/svn537/0003-Breakpoints-debugging.patch @@ -1,7 +1,7 @@ From 6725b4545adc3e94e0344e5f904267349ce167ba Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Thu, 28 Nov 2013 22:05:32 +0200 -Subject: [PATCH 3/3] Breakpoints & debugging +Subject: [PATCH 3/4] Breakpoints & debugging --- libgambatte/include/gambatte.h | 23 +++++++++ @@ -486,5 +486,5 @@ index a531930..4a252b7 100644 void nontrivial_write(unsigned p, unsigned data, unsigned cycleCounter); void updateSerial(unsigned cc); -- -1.8.4.4 +1.8.5 diff --git a/libgambatte-patches/svn537/0004-Fix-sound-DC-levels.patch b/libgambatte-patches/svn537/0004-Fix-sound-DC-levels.patch new file mode 100644 index 00000000..7067cb57 --- /dev/null +++ b/libgambatte-patches/svn537/0004-Fix-sound-DC-levels.patch @@ -0,0 +1,109 @@ +From 607d3e252c43d67cea54ec222ef1767a86b3660b Mon Sep 17 00:00:00 2001 +From: Ilari Liusvaara +Date: Thu, 5 Dec 2013 08:48:21 +0200 +Subject: [PATCH 4/4] Fix sound DC levels + +This was causing popping in Mega Man (I) +--- + libgambatte/src/sound/channel1.cpp | 6 +++--- + libgambatte/src/sound/channel2.cpp | 6 +++--- + libgambatte/src/sound/channel3.cpp | 8 ++++---- + libgambatte/src/sound/channel4.cpp | 4 ++-- + 4 files changed, 12 insertions(+), 12 deletions(-) + +diff --git a/libgambatte/src/sound/channel1.cpp b/libgambatte/src/sound/channel1.cpp +index c517965..dd83894 100644 +--- a/libgambatte/src/sound/channel1.cpp ++++ b/libgambatte/src/sound/channel1.cpp +@@ -218,13 +218,13 @@ void Channel1::loadState(SaveState const &state) { + + void Channel1::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) { + unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; +- unsigned const outLow = outBase * (0 - 15ul); + unsigned const endCycles = cycleCounter_ + cycles; + + for (;;) { + unsigned const outHigh = master_ +- ? outBase * (envelopeUnit_.getVolume() * 2 - 15ul) +- : outLow; ++ ? outBase * (envelopeUnit_.getVolume()) ++ : 0; ++ unsigned const outLow = -outHigh; + unsigned const nextMajorEvent = std::min(nextEventUnit_->counter(), endCycles); + unsigned out = dutyUnit_.isHighState() ? outHigh : outLow; + +diff --git a/libgambatte/src/sound/channel2.cpp b/libgambatte/src/sound/channel2.cpp +index f154249..6024d79 100644 +--- a/libgambatte/src/sound/channel2.cpp ++++ b/libgambatte/src/sound/channel2.cpp +@@ -122,13 +122,13 @@ void Channel2::loadState(SaveState const &state) { + + void Channel2::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) { + unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; +- unsigned const outLow = outBase * (0 - 15ul); + unsigned const endCycles = cycleCounter_ + cycles; + + for (;;) { + unsigned const outHigh = master_ +- ? outBase * (envelopeUnit_.getVolume() * 2 - 15ul) +- : outLow; ++ ? outBase * (envelopeUnit_.getVolume()) ++ : 0; ++ unsigned const outLow = -outHigh; + unsigned const nextMajorEvent = std::min(nextEventUnit->counter(), endCycles); + unsigned out = dutyUnit_.isHighState() ? outHigh : outLow; + +diff --git a/libgambatte/src/sound/channel3.cpp b/libgambatte/src/sound/channel3.cpp +index c583949..f25c96d 100644 +--- a/libgambatte/src/sound/channel3.cpp ++++ b/libgambatte/src/sound/channel3.cpp +@@ -156,8 +156,8 @@ void Channel3::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cy + unsigned const nextMajorEvent = + std::min(lengthCounter_.counter(), endCycles); + unsigned out = master_ +- ? ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - 15ul +- : 0 - 15ul; ++ ? ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - (15 >> rshift_) ++ : 0; + out *= outBase; + + while (waveCounter_ <= nextMajorEvent) { +@@ -171,7 +171,7 @@ void Channel3::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cy + ++wavePos_; + wavePos_ &= 0x1F; + sampleBuf_ = waveRam_[wavePos_ >> 1]; +- out = ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - 15ul; ++ out = ((sampleBuf_ >> (~wavePos_ << 2 & 4) & 0xF) >> rshift_) * 2 - (15 >> rshift_); + out *= outBase; + } + +@@ -188,7 +188,7 @@ void Channel3::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cy + break; + } + } else { +- unsigned const out = outBase * (0 - 15ul); ++ unsigned const out = 0; + *buf += out - prevOut_; + prevOut_ = out; + cycleCounter_ += cycles; +diff --git a/libgambatte/src/sound/channel4.cpp b/libgambatte/src/sound/channel4.cpp +index bc0a312..0abd4fb 100644 +--- a/libgambatte/src/sound/channel4.cpp ++++ b/libgambatte/src/sound/channel4.cpp +@@ -224,11 +224,11 @@ void Channel4::loadState(SaveState const &state) { + + void Channel4::update(uint_least32_t *buf, unsigned const soBaseVol, unsigned cycles) { + unsigned const outBase = envelopeUnit_.dacIsOn() ? soBaseVol & soMask_ : 0; +- unsigned const outLow = outBase * (0 - 15ul); + unsigned const endCycles = cycleCounter_ + cycles; + + for (;;) { +- unsigned const outHigh = outBase * (envelopeUnit_.getVolume() * 2 - 15ul); ++ unsigned const outHigh = outBase * (envelopeUnit_.getVolume()); ++ unsigned const outLow = -outHigh; + unsigned const nextMajorEvent = std::min(nextEventUnit_->counter(), endCycles); + unsigned out = lfsr_.isHighState() ? outHigh : outLow; + +-- +1.8.5 + -- 2.11.4.GIT