all repos — mgba @ b515214fbeed84fe5532740b10ac677d94fca2cb

mGBA Game Boy Advance Emulator

GB Audio: Reoptimize channel 4
Jeffrey Pfau jeffrey@endrift.com
Sat, 24 Dec 2016 18:33:45 -0800
commit

b515214fbeed84fe5532740b10ac677d94fca2cb

parent

0bf0975a5d040bcc00741b25ebe8f18110ba08a0

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

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

@@ -873,15 +873,21 @@

static void _updateChannel4(struct mTiming* timing, void* user, uint32_t cyclesLate) { struct GBAudio* audio = user; struct GBAudioNoiseChannel* ch = &audio->ch4; - int lsb = ch->lfsr & 1; - ch->sample = lsb * 0x10 - 0x8; - ch->sample *= ch->envelope.currentVolume; - ch->lfsr >>= 1; - ch->lfsr ^= (lsb * 0x60) << (ch->power ? 0 : 8); - int cycles = ch->ratio ? 2 * ch->ratio : 1; - cycles <<= ch->frequency; - cycles *= 8; - mTimingSchedule(timing, &audio->ch4Event, audio->timingFactor * cycles - cyclesLate); + + int32_t baseCycles = ch->ratio ? 2 * ch->ratio : 1; + baseCycles <<= ch->frequency; + baseCycles *= 8 * audio->timingFactor; + int32_t cycles = 0; + + do { + int lsb = ch->lfsr & 1; + ch->sample = lsb * 0x10 - 0x8; + ch->sample *= ch->envelope.currentVolume; + ch->lfsr >>= 1; + ch->lfsr ^= (lsb * 0x60) << (ch->power ? 0 : 8); + cycles += baseCycles; + } while (cycles < audio->sampleInterval); + mTimingSchedule(timing, &audio->ch4Event, cycles - cyclesLate); } void GBAudioPSGSerialize(const struct GBAudio* audio, struct GBSerializedPSGState* state, uint32_t* flagsOut) {
M src/gba/audio.csrc/gba/audio.c

@@ -73,6 +73,7 @@ audio->chBLeft = false;

audio->chBTimer = false; audio->enable = false; audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate; + audio->psg.sampleInterval = audio->sampleInterval; blip_clear(audio->psg.left); blip_clear(audio->psg.right);