all repos — mgba @ 1dc405db3829a6f5eaed21a034e5d0b7ed0c7f5a

mGBA Game Boy Advance Emulator

GB Audio: Channel 4 fixes (fixes #1265, closes #1289)
Vicki Pfau vi@endrift.com
Sat, 14 Sep 2019 13:08:34 -0700
commit

1dc405db3829a6f5eaed21a034e5d0b7ed0c7f5a

parent

df5b6b73516c6c0af83c3ef07e7002645e8044c1

2 files changed, 9 insertions(+), 7 deletions(-)

jump to
M CHANGESCHANGES

@@ -40,6 +40,8 @@ - GB: Fix savedata initialization (fixes mgba.io/i/1473, mgba.io/i/1478)

- GB Memory: Better emulate 0xFEA0 region on DMG, MGB and AGB - GB Printer: Reset printer buffer index after printing - GB Video: Fix mode 0 window edge case (fixes mgba.io/i/1519) + - GBA Audio: Fix channel 4 aliasing (fixes mgba.io/i/1265) + - GB Audio: Improve channel 4 supersampling Other fixes: - Qt: Fix some Qt display driver race conditions - Core: Improved lockstep driver reliability (Le Hoang Quyen)
M src/gb/audio.csrc/gb/audio.c

@@ -37,7 +37,7 @@

static void _updateSquareSample(struct GBAudioSquareChannel* ch); static int32_t _updateSquareChannel(struct GBAudioSquareChannel* ch); -static int8_t _coalesceNoiseChannel(struct GBAudioNoiseChannel* ch); +static int16_t _coalesceNoiseChannel(struct GBAudioNoiseChannel* ch); static void _updateFrame(struct mTiming* timing, void* user, uint32_t cyclesLate); static void _updateChannel1(struct mTiming* timing, void* user, uint32_t cyclesLate);

@@ -632,8 +632,11 @@ sampleRight += audio->ch3.sample;

} } + sampleLeft <<= 3; + sampleRight <<= 3; + if (!audio->forceDisableCh[3]) { - int8_t sample = _coalesceNoiseChannel(&audio->ch4); + int16_t sample = audio->style == GB_AUDIO_GBA ? (audio->ch4.sample << 3) : _coalesceNoiseChannel(&audio->ch4); if (audio->ch4Left) { sampleLeft += sample; }

@@ -642,9 +645,6 @@ if (audio->ch4Right) {

sampleRight += sample; } } - - sampleLeft <<= 3; - sampleRight <<= 3; *left = sampleLeft * (1 + audio->volumeLeft); *right = sampleRight * (1 + audio->volumeRight);

@@ -768,12 +768,12 @@ return period * 4;

} } -static int8_t _coalesceNoiseChannel(struct GBAudioNoiseChannel* ch) { +static int16_t _coalesceNoiseChannel(struct GBAudioNoiseChannel* ch) { if (!ch->nSamples) { return ch->sample; } // TODO keep track of timing - int8_t sample = ch->samples / ch->nSamples; + int16_t sample = (ch->samples << 3) / ch->nSamples; ch->nSamples = 0; ch->samples = 0; return sample;