all repos — mgba @ e97d36b7fce63db7aac845922a27a490f5ee0e0a

mGBA Game Boy Advance Emulator

GB: More audio fixes
Jeffrey Pfau jeffrey@endrift.com
Thu, 11 Feb 2016 00:10:18 -0800
commit

e97d36b7fce63db7aac845922a27a490f5ee0e0a

parent

f1f9dee111f1500418526ecb21a233fc13ca6c3e

1 files changed, 7 insertions(+), 4 deletions(-)

jump to
M src/gb/audio.csrc/gb/audio.c

@@ -98,6 +98,7 @@ if (audio->p) {

audio->p->memory.io[REG_NR52] &= ~0x0001; } } + audio->ch1.sweepOccurred = false; audio->ch1.time = GBAudioRegisterSquareSweepGetTime(value); if (!audio->ch1.time) { audio->ch1.time = 8;

@@ -381,6 +382,7 @@ audio->ch4Left = GBRegisterNR51GetCh4Left(value);

} void GBAudioWriteNR52(struct GBAudio* audio, uint8_t value) { + bool wasEnable = audio->enable; audio->enable = GBAudioEnableGetEnable(value); if (!audio->enable) { audio->playingCh1 = 0;

@@ -430,7 +432,7 @@ audio->p->memory.io[REG_NR50] = 0;

audio->p->memory.io[REG_NR51] = 0; audio->p->memory.io[REG_NR52] &= ~0x000F; } - } else { + } else if (!wasEnable) { audio->frame = 7; } }

@@ -725,14 +727,14 @@ }

static bool _updateSweep(struct GBAudioChannel1* ch, bool initial) { if (initial || ch->time != 8) { + int frequency = ch->control.frequency; if (ch->direction) { - int frequency = ch->control.frequency; frequency -= frequency >> ch->shift; - if (frequency >= 0) { + if (!initial && frequency >= 0) { ch->control.frequency = frequency; + ch->realFrequency = frequency; } } else { - int frequency = ch->control.frequency; frequency += frequency >> ch->shift; if (frequency < 2048) { if (!initial && ch->shift) {

@@ -740,6 +742,7 @@ ch->control.frequency = frequency;

if (!_updateSweep(ch, true)) { return false; } + ch->realFrequency = frequency; } } else { return false;