gamercade-io / gamercade_console

A Neo-Retro Fantasy Console. Make WASM-powered, networked multiplayer games.
https://gamercade.io
Apache License 2.0
166 stars 10 forks source link

Add Sound in Console #33

Closed RobDavenport closed 1 year ago

RobDavenport commented 1 year ago

First pass at trying to get the sound to play in the console. #11

I think this approach is fine for now, basically we keep a "predicted state" and tick the synths locally every time we render a game frame. It's kinda wasteful, but I'm not sure of another approach to use... Perhaps we can use channels and have the main thread "request" the sending back of audio every X samples or something, but I'm not sure how much better that will be.

Performance for this also seems pretty good, as the audio_test example runs at ~1% CPU or less.

The basic logic for this is:

Had to a bit of refactoring on how audio was being generated, as the previous method was producing too much crackling and too latency sensitive. This should be decent enough for a first pass.

TODO:

RobDavenport commented 1 year ago

audio test game.zip for testing

RobDavenport commented 1 year ago

There's a minor popping issue when the audio callback & rollback are slightly out of sync. I've left a comment in the audio callback about this, maybe we can get it fixed later.