xnes icon indicating copy to clipboard operation
xnes copied to clipboard

Crackling sound issue

Open digdug82 opened this issue 9 years ago • 8 comments

For some reason the sound is always having crackling noise, In some games are much more that the others, but the noise is always there.

digdug82 avatar Dec 14 '16 14:12 digdug82

I don't know how to improve the sound quality. Suggestions are welcome.

tjwei avatar Dec 15 '16 03:12 tjwei

I've started working on this. @tjwei how did you come up with 22100 for the sample rate? I notice the default is 32000 (although setting it to that does not fix the issue).

jasmith79 avatar Apr 13 '17 11:04 jasmith79

I can now say some things that don't work either on their own or in conjunction:

  • Setting SoundSync to TRUE and calling the sync function in the rendering loop.
  • Increasing the sample rate.
  • Decreasing the sample rate.
  • Increasing the buffer size for sound samples (even into several thousand ms)
  • Increasing the allowable latency.
  • Turning off stereo/16-bit sound.

I'm starting to run out of ideas here. Having googled this problem and experimented quite a bit I am unsure that it is solvable.

jasmith79 avatar Apr 16 '17 19:04 jasmith79

Hi @jasmith79, thanks for the effort! The choice of 22100 is quite arbitrary, It is intended to be 22050, half of 44100. 44100 or 48000 might be too high, but 16000 or 32000 makes more sense. I suspect separating UI and logic into two workers might fix the issue, but it is not very easy to do.

tjwei avatar Apr 17 '17 01:04 tjwei

Good news! I mostly fixed this. Bad news! the 'fix' is rather convoluted.

I was messing around with compiling to web assembly instead of asm.js. The downside (and its significant) is that means it only will run in Chrome Canary. In Canary there are still occasional pops but its barely noticeable, In Firefox Developer Edition the games load and there's (as far as I can tell) perfect sound but keypresses aren't forwarded to SDL, meaning you can't actually play anything.

I'm going to hold off on a PR until this stabilizes or I come up with a better solution, but for those of you who just can't wait: here you go. Note that you will need the latest (and I mean latest) version of emscripten to compile. Also note that loading in Canary seems to randomly fail: just refresh if it takes longer than 4-5 seconds for a local load.

As for me, I'm timed out on this for now, I've spent too many lunch breaks/evenings on this already :)

jasmith79 avatar Apr 18 '17 16:04 jasmith79

Web Assembly version now works on stable versions of Chrome, Firefox on Windows 10, Linux Mint 18.x, and MacOS Sierra. Sound still hiccups or cracks occasionally, but is light-years better than it was. I also fixed the last two complier errors. Here's a live demo, just be sure to maximize your browser window as some aspects of the responsive UI are not yet implemented.

jasmith79 avatar Apr 23 '17 22:04 jasmith79

Aww, so sad to see this 3 years later. Any chance you will pick up working on this again? I noticed lots of crackling on snes.party and then found myself here.

fnorf avatar Mar 25 '20 19:03 fnorf

@fnorf Moving from asm.js to web assembly removed most of the crackling which makes me suspect that it's a performance (i.e. synchronization) issue. Web assembly is pretty widely supported at this point, If I get a weekend here (thanks to COVID-19 chances are better) I may try to compile it with a newer version of emscripten and run it in a current browser to see if that persists.

jasmith79 avatar Mar 26 '20 10:03 jasmith79