| ▲ | dietrichepp 5 hours ago | |
This is great stuff… basically, an easy way to get much higher quality audio out of a GBA emulator. I’ll add some context here—why don’t more games run their audio at 32768 Hz, if that’s such a natural rate to run audio? The answer lies in how you fill the buffers. In any modern, sensible audio system, you can check how much space is available in the audio buffer and simply fill it. The GBA lacks a mechanism to query this. Instead, what you do is calculate this yourself, and figure out when to trigger additional audio DMA from the VBlank interrupt. You know the VBlank runs every 280896 cycles, and you know that the processor runs at 16777216 Hz, so you can do some math to calculate how much data is remaining in the audio DMA stream. A lot of games simplify the math—it’s easier to start a new audio DMA in your VBlank handler, but that means running at a lower sample rate, which will sound pretty crispy. YMMV, some people like the crispy aliased audio. If the audio weren’t crispy, the sound designers probably would have adjusted the samples to compensate. Other factors being equal, I’d rather listen to what the original artists heard when they were testing on real hardware, because that is probably closer to what they intended, even though it has a lot of artifacts in it. | ||
| ▲ | ErroneousBosh an hour ago | parent [-] | |
> why don’t more games run their audio at 32768 Hz, if that’s such a natural rate to run audio? I've written some code to play back 8-bit samples (and indeed to wavetable, FM, and VA synthesis) on 8-bit Arduinos using the PWM to output 8-bit audio. That runs at 31373Hz which is a pretty crazy sample rate. Why? Because the chip is clocked at 16MHz, and if you program the PWM for no prescaler and "phase correct" PWM where it counts up and back down, so you get a widening pulse in the middle of a "burst", then it counts 510 "steps" of the counter. It's an 8-bit counter so it counts from 0 to 255, then the next step counts back down to 254, and so to 0 again, when the next step takes it to 1. And 16000000/510 is 31372.55 ;-) | ||