nesdev.com
http://forums.nesdev.com/

Sound is at least two seconds behind...
http://forums.nesdev.com/viewtopic.php?f=3&t=15916
Page 1 of 1

Author:  _jamesbrown_ [ Sun May 07, 2017 7:34 pm ]
Post subject:  Sound is at least two seconds behind...

I created a very rudimentary implementation of the APU in my emulator. I currently sample at 48000Hz and every 41st cycle of the cpu, I go ahead and spew the current tone out for the two pulse waves (basically nearest neighbor algorithm). I don't do anything else fancy like envelopes or handling duty cycles, everything is at a constant volume. As a result, the music/sound never turns off (I'm only testing with Donkey Kong) which is expected.

What I noticed is that the PPU doesn't match up with the APU. I'm testing with Donkey Kong and if Mario gets hit by a barrel, the kill noise is delayed and doesn't output for a few seconds.

My implementation of the PPU is to currently draw out the whole frame at the end (89,342 PPU cycles). I don't think I'm bound by my computer as it's able to keep up fine. Also there's zero input lag between keyboard input (controlling mario) and picture output.

Based on my implementation, does it make sense that the sound doesn't match up with the picture? There is still a lot of work to do but for now I'm more curious as to what could cause the delay. Thanks.

Author:  Memblers [ Sun May 07, 2017 10:37 pm ]
Post subject:  Re: Sound is at least two seconds behind...

That's what would happen if the audio buffer is too long, can you make it shorter? What system/library are you using for audio? I've only used SDL myself, but that info might allow someone else to help.

edit: PPU and audio synchronization seems to be a recurring problem with making an NES emulator, so there will surely be more to it than just using a shorter buffer. If you can find other threads about that, it might help.

Author:  _jamesbrown_ [ Mon May 08, 2017 4:46 pm ]
Post subject:  Re: Sound is at least two seconds behind...

Memblers wrote:
That's what would happen if the audio buffer is too long, can you make it shorter? What system/library are you using for audio? I've only used SDL myself, but that info might allow someone else to help.

edit: PPU and audio synchronization seems to be a recurring problem with making an NES emulator, so there will surely be more to it than just using a shorter buffer. If you can find other threads about that, it might help.


I'm also using SDL... I can believe that my audio buffer is too long. Is this the "samples" member in SDL_AudioSpec as an argument to SDL_OpenAudioDevice? (https://wiki.libsdl.org/SDL_OpenAudioDevice) I'm using 1600 here, which I calculated from:

4800hz * sizeof(short) / 30 / 2 (30 being arbitrary, in this case 30fps -- NTSC).

I stole that boilerplate calculation from some stackoverflow post so I may be off track here.

Author:  Quietust [ Mon May 08, 2017 5:08 pm ]
Post subject:  Re: Sound is at least two seconds behind...

_jamesbrown_ wrote:
(30 being arbitrary, in this case 30fps -- NTSC)

As far as the NES is concerned, NTSC is 60fps, not 30.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/