all repos — mgba @ 5d9730433f9fa275f56393e33b14d768a2294fc1

mGBA Game Boy Advance Emulator

GB Audio: Only update channel 4 when sampling
Jeffrey Pfau jeffrey@endrift.com
Sun, 21 Feb 2016 11:01:59 -0800
commit

5d9730433f9fa275f56393e33b14d768a2294fc1

parent

1ea453e6d22e3dfcb7f0276e83b25c406c0b3464

1 files changed, 15 insertions(+), 15 deletions(-)

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

@@ -552,21 +552,6 @@ _updateEnvelope(&audio->ch4.envelope);

audio->ch4.sample = sample * audio->ch4.envelope.currentVolume; } } - - if (audio->ch4.envelope.dead != 2) { - if (audio->nextCh4 <= 0) { - int32_t timing = _updateChannel4(&audio->ch4); - if (audio->nextCh4 < -timing) { - int32_t bound = timing * 16; - // Perform negative modulo to cap to 16 iterations - audio->nextCh4 = bound - (audio->nextCh4 - 1) % bound - 1; - } - audio->nextCh4 += timing; - } - if (audio->nextCh4 < audio->nextEvent) { - audio->nextEvent = audio->nextCh4; - } - } } if (audio->ch4.length && audio->ch4.stop && !(frame & 1)) {

@@ -602,6 +587,21 @@

void GBAudioSamplePSG(struct GBAudio* audio, int16_t* left, int16_t* right) { int sampleLeft = 0; int sampleRight = 0; + + if (audio->ch4.envelope.dead != 2) { + while (audio->nextCh4 <= 0) { + int32_t timing = _updateChannel4(&audio->ch4); + if (audio->nextCh4 < -timing) { + int32_t bound = timing * 16; + // Perform negative modulo to cap to 16 iterations + audio->nextCh4 = bound - (audio->nextCh4 - 1) % bound - 1; + } + audio->nextCh4 += timing; + } + if (audio->nextCh4 < audio->nextEvent) { + audio->nextEvent = audio->nextCh4; + } + } if (audio->playingCh1 && !audio->forceDisableCh[0]) { if (audio->ch1Left) {