Skip to content

Commit cccf168

Browse files
committed
Merge commit '81fa1ae2e1d06f29aca3e8af4673d05ac4f8f8e6'
2 parents 1528411 + 81fa1ae commit cccf168

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

thirdparty/SameBoy/Core/apu.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ static void update_sample(GB_gameboy_t *gb, unsigned index, int8_t value, unsign
107107
}
108108
}
109109

110+
static double smooth(double x)
111+
{
112+
return 3*x*x - 2*x*x*x;
113+
}
114+
110115
static void render(GB_gameboy_t *gb, bool no_downsampling, GB_sample_t *dest)
111116
{
112117
GB_sample_t output = {0,0};
@@ -123,7 +128,7 @@ static void render(GB_gameboy_t *gb, bool no_downsampling, GB_sample_t *dest)
123128
gb->apu_output.dac_discharge[i] = 0;
124129
}
125130
else {
126-
multiplier *= gb->apu_output.dac_discharge[i];
131+
multiplier *= smooth(gb->apu_output.dac_discharge[i]);
127132
}
128133
}
129134
else {
@@ -132,7 +137,7 @@ static void render(GB_gameboy_t *gb, bool no_downsampling, GB_sample_t *dest)
132137
gb->apu_output.dac_discharge[i] = 1;
133138
}
134139
else {
135-
multiplier *= gb->apu_output.dac_discharge[i];
140+
multiplier *= smooth(gb->apu_output.dac_discharge[i]);
136141
}
137142
}
138143
}
@@ -350,7 +355,6 @@ void GB_apu_div_event(GB_gameboy_t *gb)
350355
if (gb->apu.wave_channel.pulse_length) {
351356
if (!--gb->apu.wave_channel.pulse_length) {
352357
gb->apu.is_active[GB_WAVE] = false;
353-
gb->apu.wave_channel.current_sample = 0;
354358
update_sample(gb, GB_WAVE, 0, 0);
355359
}
356360
}
@@ -806,7 +810,6 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
806810
gb->apu.wave_channel.enable = value & 0x80;
807811
if (!gb->apu.wave_channel.enable) {
808812
gb->apu.is_active[GB_WAVE] = false;
809-
gb->apu.wave_channel.current_sample = 0;
810813
update_sample(gb, GB_WAVE, 0, 0);
811814
}
812815
break;
@@ -815,7 +818,9 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
815818
break;
816819
case GB_IO_NR32:
817820
gb->apu.wave_channel.shift = (uint8_t[]){4, 0, 1, 2}[(value >> 5) & 3];
818-
update_sample(gb, GB_WAVE, gb->apu.wave_channel.current_sample >> gb->apu.wave_channel.shift, 0);
821+
if (gb->apu.is_active[GB_WAVE]) {
822+
update_sample(gb, GB_WAVE, gb->apu.wave_channel.current_sample >> gb->apu.wave_channel.shift, 0);
823+
}
819824
break;
820825
case GB_IO_NR33:
821826
gb->apu.wave_channel.sample_length &= ~0xFF;
@@ -856,7 +861,9 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
856861
}
857862
if (!gb->apu.is_active[GB_WAVE]) {
858863
gb->apu.is_active[GB_WAVE] = true;
859-
update_sample(gb, GB_WAVE, 0, 0);
864+
update_sample(gb, GB_WAVE,
865+
gb->apu.wave_channel.current_sample >> gb->apu.wave_channel.shift,
866+
0);
860867
}
861868
gb->apu.wave_channel.sample_countdown = (gb->apu.wave_channel.sample_length ^ 0x7FF) + 3;
862869
gb->apu.wave_channel.current_sample_index = 0;
@@ -865,11 +872,6 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
865872
gb->apu.wave_channel.length_enabled = false;
866873
}
867874
/* Note that we don't change the sample just yet! This was verified on hardware. */
868-
/* Todo: The first sample might *not* beskipped on the DMG, this could be a bug
869-
introduced on the CGB. It appears that the bug was fixed on the AGB, but it's
870-
not reflected by PCM34. This should be probably verified as this could just
871-
mean differences in the DACs. */
872-
/* Todo: Similar issues may apply to the other channels on the DMG/AGB, test, verify and fix if needed */
873875
}
874876

875877
/* APU glitch - if length is enabled while the DIV-divider's LSB is 1, tick the length once. */

thirdparty/SameBoy/Core/apu.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88

99
#ifdef GB_INTERNAL
1010
/* Speed = 1 / Length (in seconds) */
11-
/* Todo: Measure these and find the actual curve shapes.
12-
They are known to be incorrect (Some analog test ROM sound different),
13-
but are good enough approximations to fix Cannon Fodder's terrible audio.
14-
It also varies by model. */
15-
#define DAC_DECAY_SPEED 50000
16-
#define DAC_ATTACK_SPEED 1000
11+
#define DAC_DECAY_SPEED 20000
12+
#define DAC_ATTACK_SPEED 20000
1713

1814

1915
/* Divides nicely and never overflows with 4 channels and 8 (1-8) volume levels */

0 commit comments

Comments
 (0)