bfirsh/jsnes

Embed audio is high-pitched

htv04 opened this issue · 4 comments

htv04 commented

Made an implementation of JSNES here: https://github.com/HTV04/htv04.github.io/blob/master/webnes-ce/js/webnes.js

But for whatever reason, the audio is high-pitched. I don't know how to fix this, and I don't know if this is a problem with JSNES or my code.

htv04 commented

Additionally, the emulation speed seems to vary among devices. I am very new to JS and I don't know what I'm doing wrong here,

I was having a similar issue, as the JSNES i built and used in the Embed example was running at an erratic 65FPS(ish) with slightly high pitched audio. I fixed it by doing 2 things. First, set the sampleRate in nes.js to 48000 instead of 44100 (which was a pure hunch lol) and commenting out the nes.frame() call in onAnimationFrame in nes-embed.js; It seems to run much smoother with correct audio now!

Thanks for the fix @NESblast!

Generally, your best bet is to use the Emulator component in jsnes-web. That's the thing actually in use and has pretty complex, battle tested timing logic. Usage is here: https://github.com/bfirsh/jsnes-web/blob/d3c35eec11986412626cbd08668dbac700e08751/src/RunPage.js#L119-L125

I'll add something to this effect to the home page...