Hello friends!
My emulator, Nintendoish, is progressing along nicely. I have scan line accurate PPU emulation, mapper support for all of the official US cartridge boards. Currently working on APU emulation. So far it has been an amazing leaning experience!
I have a quick question on audio sync.
Right now my emulator targets ~60 fps. I can hit that on my desktop no problem. On my laptop however, when running in dev mode, it will drop to about 40 fps.
When fps drops, my strategy to prevent slowdown is to simply drop render frames. Keep clocking the NES, but just don't render to the GPU.
This works great with video. Barely noticeable. However, it doesn't seem to work great with audio. I get this weird cascading loop. The NES is running behind and can't fill the audio buffer fast enough, so I output silence. The NES notices it's behind and so skips video frames to catch up. Audio buffer fills back up. But now the audio and video are out of sync.
I've tried just skipping audio frames when I skip a video frame but that creates very noticeable distortion in the audio. Especially when running at 40 fps. While dropping 1/3 of your video frames isn't super noticeable, dropping 1/3rd of your audio very much is.
So I was just wondering, what are some strategies with dealing with this? How do emulators running on low powered devices manage to drop their frame rate without creating audio distortion or getting their video/audio out of sync? Any suggestions?
Thank you!
PS
Source code is here: https://github.com/drewying/Nintendoish. As you will see it still is very much a work in progress.
My emulator, Nintendoish, is progressing along nicely. I have scan line accurate PPU emulation, mapper support for all of the official US cartridge boards. Currently working on APU emulation. So far it has been an amazing leaning experience!
I have a quick question on audio sync.
Right now my emulator targets ~60 fps. I can hit that on my desktop no problem. On my laptop however, when running in dev mode, it will drop to about 40 fps.
When fps drops, my strategy to prevent slowdown is to simply drop render frames. Keep clocking the NES, but just don't render to the GPU.
This works great with video. Barely noticeable. However, it doesn't seem to work great with audio. I get this weird cascading loop. The NES is running behind and can't fill the audio buffer fast enough, so I output silence. The NES notices it's behind and so skips video frames to catch up. Audio buffer fills back up. But now the audio and video are out of sync.
I've tried just skipping audio frames when I skip a video frame but that creates very noticeable distortion in the audio. Especially when running at 40 fps. While dropping 1/3 of your video frames isn't super noticeable, dropping 1/3rd of your audio very much is.
So I was just wondering, what are some strategies with dealing with this? How do emulators running on low powered devices manage to drop their frame rate without creating audio distortion or getting their video/audio out of sync? Any suggestions?
Thank you!
PS
Source code is here: https://github.com/drewying/Nintendoish. As you will see it still is very much a work in progress.