Skip to content

Add Sound in Console #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 25, 2022
Merged

Add Sound in Console #33

merged 14 commits into from
Aug 25, 2022

Conversation

RobDavenport
Copy link
Member

@RobDavenport RobDavenport commented Aug 22, 2022

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:

  • Any time we save a state to memory for rollback, we also save along that predicted audio state.
  • When loading a state, we send the predicted audio state down to the audio thread and let it continue playing.
  • Whenever we call game_loop update, we also "advance" the locally predicted audio state along with it.
  • The saved data is the SoundEngineData struct, which might be kinda overkill but we can see how it performs for now.

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:

  • Add sound engine to console
  • Add raw Apis to Api list
  • Add AudioContext and related functions
  • Update gamercade_rs helper functions
  • Update website with related functions and documentation
  • Setup a default sound or beep instrument
  • Build an audio test project/rom

@RobDavenport
Copy link
Member Author

audio test game.zip
for testing

@RobDavenport RobDavenport marked this pull request as ready for review August 24, 2022 22:51
@RobDavenport
Copy link
Member Author

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.

@RobDavenport RobDavenport merged commit 45cd117 into main Aug 25, 2022
@RobDavenport RobDavenport deleted the sound_in_console branch August 26, 2022 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant