jsmolka / eggvance

A Game Boy Advance emulator.
https://smolka.dev/tags/eggvance
GNU General Public License v3.0
65 stars 1 forks source link

BIOS intro: bad sound #16

Closed jsmolka closed 3 years ago

jsmolka commented 3 years ago

The last bleep in the BIOS intro sounds distorted / metallic. This can be fixed by splitting the long arm.run(960) into smaller 100 cycle chunks (see #14). The sound is provided by the FIFO so it's most likely a timer issue.


The bug is caused by the current layout of the tick function.

void Arm::tick(int cycles)
{
    this->cycles -= cycles;

    if (state & kStateTimer)
        timer.run(cycles);

    if (irq.delaying)
    {
        irq.delay -= cycles;

        if (irq.delay < 0)
            irq.delay = 0;
    }

    apu.run(cycles);
}

Running the timer first with large values skipped some samples and caused the metallic sound. Running 100 cycles max each step reduced that probability and mitigated the bug. Another way to do this is switching the timer.run and apu.run positions. I will solve this bug with the upcoming scheduler.