bfirsh / jsnes

A JavaScript NES emulator.
https://jsnes.org
Apache License 2.0
6.11k stars 828 forks source link

Speed problems on high refresh rate monitors #335

Open grechucia opened 4 years ago

grechucia commented 4 years ago

There are speed problems on high refresh rate monitors (in my case 144hz). On 60Hz monitor running just fine.

In example file "nes-embed.js" quick fix is to delete line 'nes.frame();' from onAnimationFrame()

function onAnimationFrame(){ window.requestAnimationFrame(onAnimationFrame); image.data.set(framebuffer_u8); canvas_ctx.putImageData(image, 0, 0); //nes.frame(); }

I'm not an expert, can someone confirm it's the right way?

navgg commented 4 years ago

It's wrong way, you may need to implement a frame skip. But I'm not sure if requestanimationframe working faster than 60Hz, so the problem may be in wrong sound sample rate or small sound buffer size. Try to initialize audio context like this

var audio_ctx = new window.AudioContext({ sampleRate: nes.papu.sampleRate });