Actually call on_reset callback
[lsnes.git] / libgambatte-patches / svn364 / 0003-Fix-sound-DC-levels.patch
blob79b713b1e87ecf4fb8f47f26897c4355d7094154
1 From 8dac6800be952bb48afec48ec2e5c597f7aefae3 Mon Sep 17 00:00:00 2001
2 From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
3 Date: Thu, 5 Dec 2013 08:46:03 +0200
4 Subject: [PATCH 3/3] Fix sound DC levels
6 This was causing popping in Mega Man (I)
7 ---
8 libgambatte/src/sound/channel1.cpp | 5 ++---
9 libgambatte/src/sound/channel2.cpp | 4 ++--
10 libgambatte/src/sound/channel3.cpp | 6 +++---
11 libgambatte/src/sound/channel4.cpp | 5 ++---
12 4 files changed, 9 insertions(+), 11 deletions(-)
14 diff --git a/libgambatte/src/sound/channel1.cpp b/libgambatte/src/sound/channel1.cpp
15 index 6b9ccf1..915ab1a 100644
16 --- a/libgambatte/src/sound/channel1.cpp
17 +++ b/libgambatte/src/sound/channel1.cpp
18 @@ -220,14 +220,13 @@ void Channel1::loadState(const SaveState &state) {
20 void Channel1::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cycles) {
21 const unsigned outBase = envelopeUnit.dacIsOn() ? soBaseVol & soMask : 0;
22 - const unsigned outLow = outBase * (0 - 15ul);
23 const unsigned endCycles = cycleCounter + cycles;
25 for (;;) {
26 - const unsigned outHigh = master ? outBase * (envelopeUnit.getVolume() * 2 - 15ul) : outLow;
27 + const unsigned outHigh = master ? outBase * (envelopeUnit.getVolume()) : 0;
28 + const unsigned outLow = -outHigh;
29 const unsigned nextMajorEvent = nextEventUnit->getCounter() < endCycles ? nextEventUnit->getCounter() : endCycles;
30 unsigned out = dutyUnit.isHighState() ? outHigh : outLow;
32 while (dutyUnit.getCounter() <= nextMajorEvent) {
33 *buf = out - prevOut;
34 prevOut = out;
35 diff --git a/libgambatte/src/sound/channel2.cpp b/libgambatte/src/sound/channel2.cpp
36 index 6bd5b04..dc74d7c 100644
37 --- a/libgambatte/src/sound/channel2.cpp
38 +++ b/libgambatte/src/sound/channel2.cpp
39 @@ -125,11 +125,11 @@ void Channel2::loadState(const SaveState &state) {
41 void Channel2::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cycles) {
42 const unsigned outBase = envelopeUnit.dacIsOn() ? soBaseVol & soMask : 0;
43 - const unsigned outLow = outBase * (0 - 15ul);
44 const unsigned endCycles = cycleCounter + cycles;
46 for (;;) {
47 - const unsigned outHigh = master ? outBase * (envelopeUnit.getVolume() * 2 - 15ul) : outLow;
48 + const unsigned outHigh = master ? outBase * (envelopeUnit.getVolume()) : 0;
49 + const unsigned outLow = -outHigh;
50 const unsigned nextMajorEvent = nextEventUnit->getCounter() < endCycles ? nextEventUnit->getCounter() : endCycles;
51 unsigned out = dutyUnit.isHighState() ? outHigh : outLow;
52 while (dutyUnit.getCounter() <= nextMajorEvent) {
53 diff --git a/libgambatte/src/sound/channel3.cpp b/libgambatte/src/sound/channel3.cpp
54 index ec2c8ed..758f3d5 100644
55 --- a/libgambatte/src/sound/channel3.cpp
56 +++ b/libgambatte/src/sound/channel3.cpp
57 @@ -155,7 +155,7 @@ void Channel3::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cy
59 for (;;) {
60 const unsigned nextMajorEvent = lengthCounter.getCounter() < endCycles ? lengthCounter.getCounter() : endCycles;
61 - unsigned out = outBase * (master ? ((sampleBuf >> (~wavePos << 2 & 4) & 0xF) >> rShift) * 2 - 15ul : 0 - 15ul);
62 + unsigned out = outBase * (master ? ((sampleBuf >> (~wavePos << 2 & 4) & 0xF) >> rShift) * 2 - (15 >> rShift) : 0);
64 while (waveCounter <= nextMajorEvent) {
65 *buf += out - prevOut;
66 @@ -168,7 +168,7 @@ void Channel3::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cy
67 ++wavePos;
68 wavePos &= 0x1F;
69 sampleBuf = waveRam[wavePos >> 1];
70 - out = outBase * (/*master ? */((sampleBuf >> (~wavePos << 2 & 4) & 0xF) >> rShift) * 2 - 15ul/* : 0 - 15ul*/);
71 + out = outBase * (/*master ? */((sampleBuf >> (~wavePos << 2 & 4) & 0xF) >> rShift) * 2 - (15 >> rShift)/* : 0 - 15ul*/);
74 if (cycleCounter < nextMajorEvent) {
75 @@ -184,7 +184,7 @@ void Channel3::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cy
76 break;
78 } else {
79 - unsigned const out = outBase * (0 - 15ul);
80 + unsigned const out = outBase * 0;
81 *buf += out - prevOut;
82 prevOut = out;
83 cycleCounter += cycles;
84 diff --git a/libgambatte/src/sound/channel4.cpp b/libgambatte/src/sound/channel4.cpp
85 index b646dff..5132303 100644
86 --- a/libgambatte/src/sound/channel4.cpp
87 +++ b/libgambatte/src/sound/channel4.cpp
88 @@ -264,14 +264,13 @@ void Channel4::loadState(const SaveState &state) {
90 void Channel4::update(uint_least32_t *buf, const unsigned soBaseVol, unsigned cycles) {
91 const unsigned outBase = envelopeUnit.dacIsOn() ? soBaseVol & soMask : 0;
92 - const unsigned outLow = outBase * (0 - 15ul);
93 const unsigned endCycles = cycleCounter + cycles;
95 for (;;) {
96 - const unsigned outHigh = /*master ? */outBase * (envelopeUnit.getVolume() * 2 - 15ul)/* : outLow*/;
97 + const unsigned outHigh = /*master ? */outBase * (envelopeUnit.getVolume())/* : outLow*/;
98 + const unsigned outLow = -outHigh;
99 const unsigned nextMajorEvent = nextEventUnit->getCounter() < endCycles ? nextEventUnit->getCounter() : endCycles;
100 unsigned out = lfsr.isHighState() ? outHigh : outLow;
102 while (lfsr.getCounter() <= nextMajorEvent) {
103 *buf += out - prevOut;
104 prevOut = out;
106 1.8.5