all repos — mgba @ e1a4acec9f39a1f7081d56b69c851747caada807

mGBA Game Boy Advance Emulator

GB Audio: Rearrange WriteNR14 and fix GBC timing
Jeffrey Pfau jeffrey@endrift.com
Sun, 19 Jun 2016 22:42:03 -0700
commit

e1a4acec9f39a1f7081d56b69c851747caada807

parent

fb7ecb8079aa848c1b6811c8a5fdc692dd201bed

1 files changed, 9 insertions(+), 8 deletions(-)

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

@@ -144,6 +144,13 @@ audio->playingCh1 = false;

} } if (GBAudioRegisterControlIsRestart(value << 8)) { + audio->playingCh1 = audio->ch1.envelope.initialVolume || audio->ch1.envelope.direction; + audio->ch1.envelope.currentVolume = audio->ch1.envelope.initialVolume; + if (audio->ch1.envelope.currentVolume > 0) { + audio->ch1.envelope.dead = audio->ch1.envelope.stepTime ? 0 : 1; + } else { + audio->ch1.envelope.dead = audio->ch1.envelope.stepTime ? 0 : 2; + } if (audio->nextEvent == INT_MAX) { audio->eventDiff = 0; }

@@ -151,13 +158,7 @@ if (audio->playingCh1) {

audio->ch1.control.hi = !audio->ch1.control.hi; } audio->nextCh1 = audio->eventDiff; - audio->playingCh1 = audio->ch1.envelope.initialVolume || audio->ch1.envelope.direction; - audio->ch1.envelope.currentVolume = audio->ch1.envelope.initialVolume; - if (audio->ch1.envelope.currentVolume > 0) { - audio->ch1.envelope.dead = audio->ch1.envelope.stepTime ? 0 : 1; - } else { - audio->ch1.envelope.dead = audio->ch1.envelope.stepTime ? 0 : 2; - } + audio->ch1.realFrequency = audio->ch1.control.frequency; audio->ch1.sweepStep = audio->ch1.time; audio->ch1.sweepEnable = (audio->ch1.sweepStep != 8) || audio->ch1.shift;

@@ -855,7 +856,7 @@ void _scheduleEvent(struct GBAudio* audio) {

// TODO: Don't need p if (audio->p) { audio->nextEvent = audio->p->cpu->cycles >> audio->p->doubleSpeed; - audio->p->cpu->nextEvent = audio->nextEvent; + audio->p->cpu->nextEvent = audio->p->cpu->cycles; } else { audio->nextEvent = 0; }