I wrote a NES emulator for ExciteBike 64, so that the original 8-bit ExciteBike could be played as an unlockable level. The hardest part was getting the audio to sound approximately right!
Fun fact: NES Excitebike supported saving and loading your custom tracks to the Famicom Data Recorder. The USA version of the FDR was never released, but the USA version of NES Excitebike still had all the save/load code+functionality built in. When you tried to save a track it would just hang for a while before returning to the menu. After figuring out where the save/load routines were, and where the track was stored in RAM, we were able to put hooks in the emulator to save the tracks to the N64 cart.
Audio seems to be a problem in a lot of emulators... SNES emulators had issues with sound for years. (wind blowing in FF3 (6j) being the one I always remember) I guess it's because of trying to support the capabilities of the actual sound chip?
Also the bit about the track saving is fantastic. Thanks for sharing!
No worries! Audio emulation can be hard for a couple of other reasons too: Firstly, it's sometimes easy to tell that something "isn't quite right", but unless you have awesome ears (I don't), it's hard to hear exactly what the problem is. Secondly, audio isn't the sexiest part of emulator development - it often gets overlooked, and consequently there's far less information available about it.
As it happens, audio emulation on the ZX-Spectrum 48k is easier: There's a one-bit on/off output wired to a speaker. Even generating tones has to be done by timing Z80 cycles! Some people still managed to do amazing things using pulse-width modulation.
> I guess it's because of trying to support the capabilities of the actual sound chip?
This may be the case for some emulators -- such as the NES emulator in excitebike. However, (if I understand everything I've read correctly) the SNES didn't have a 'sound chip' in the same sense that the NES (or GameBoy, C64, etc.) did. The NES and all of Nintendo's other hardware used to synthesize its sound in real-time, but that changed with the SNES, which introduced sample-based audio instead. (Fun fact: some people suggest that the N64's sampled audio can meet -- or exceed -- CD quality!)
I suspect issues with SNES emulation are simply that all of the SNES emulators we have are fairly poor in _all regards_, it's just that it's easier to notice in the sound than in things like timing.
Here are some examples of the other failings of many SNES emulators:
The SNES sound hardware was a little bit more complicated than that.
It has a control CPU, and it's own RAM, with no access to the contents of the cartridge, or to main RAM. Obviously, you have to emulate all of that accurately, or the code that controls the sound output might not work correctly.
The actual hardware is more complicated than just a sample mixer. It's implemented as a custom DSP, which does sample decompression, high quality resampling, mixing, has an envelope generator, several effects (programmable FIR filter, echo, panning), and a noise generator.
Older SNES emulators didn't really emulate any of this. They treated it as if it were a simple sample playback device. This worked OK for most games, because they didn't use those features. However, when a game actually used those features, everything sounded wrong.
Later, they started supporting the effects, but nobody understood how the DSP was actually implementing those effects, so they didn't sound quite right. They just implemented stuff that sounded about right on the games they were testing on. Reverse-engineering all the hardware, so this stuff could be emulated accurately, took a very long time.
Right now, the SNES audio hardware is completely understood. We have several emulators that are perfectly accurate, both in terms of timing, and output. For example:
Fun fact: NES Excitebike supported saving and loading your custom tracks to the Famicom Data Recorder. The USA version of the FDR was never released, but the USA version of NES Excitebike still had all the save/load code+functionality built in. When you tried to save a track it would just hang for a while before returning to the menu. After figuring out where the save/load routines were, and where the track was stored in RAM, we were able to put hooks in the emulator to save the tracks to the N64 cart.