Here's the audio emulation approaches I know of so far. Are there any other common ones? What additional gotchas are there?
- Have the audio callback drive emulation: Emulate the number of cycles required to generate the number of samples requested. Pros: Simple, straightforward and glitch-free if you're fast enough. Cons: Might cause slightly uneven emulation speed and video jitter. Also means that wonky audio could mess up everything else.
- Have a video-based emulation loop and put samples into a buffer that's consumed by the callback. Pros: No jitter in the video. Cons: Harder to implement and could run into over- and underflow more easily.
- (More like an addition to 2.) Fill in missing data if more samples are requested than available, e.g. by assuming that the APU state doesn't change. Pros: Reduced risk of underflow. Cons: Still inaccurate playback in case of underflow.