workhorsy / SaltyNES

A NES emulator in WebAssembly
https://workhorsy.org/SaltyNES/
GNU General Public License v3.0
84 stars 6 forks source link

Sound is distorted. #9

Open workhorsy opened 6 years ago

workhorsy commented 6 years ago

Look at vnes and jsnes too see why their sound is smooth, and ours is popping and distorted.

https://github.com/workhorsylegacy/vNES

https://github.com/bfirsh/jsnes

ClosetGeek-Git commented 5 years ago

Just a guess, but this could be due to additional latency caused by calling JS from WASM. Basically, SDL does it's thing to generate sound but eventual this generated sound (raw wave form?) is pushed out to the browsers JavaScript API. The glue between these two spaces may cause enough latency that it could be an issue if being called too many times per second. Just a thought.

This explains the concept some https://hacks.mozilla.org/2018/10/calls-between-javascript-and-webassembly-are-finally-fast-%F0%9F%8E%89/

Not sure how likely it is that this is the issue, but since this is basically a SDL based sound synthesizer WASM is generating every cycle of the outgoing wave form. Also note that SDL is communicating with JS at the same time for video output as well.

workhorsy commented 5 years ago

It has been a long time since I worked on this.

It does have an option to run under SDL on the desktop. I just tried it, and it has messed up sound too. So it can't have anything to do with the browser. Thanks for looking into it though.