Skip to content
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

GBA: Send audio samples to frontend with correct pacing #244

Merged
merged 1 commit into from
Oct 26, 2021

Conversation

jdgleaver
Copy link

As reported in #109, #134 and libretro/RetroArch#8235, GBA content run with the mGBA core is sometimes subject to crackling audio and intermittent bad frame pacing (particularly when using low frontend audio latency settings).

It turns out that the core is handling audio suboptimally in the libretro layer. At the set audio sample rate, the frontend expects between 548 and 549 audio samples per frame - but the AVStream audio callback reads and sends exactly 512 samples. This means that the audio callback becomes desynchronised with retro_run() - sometimes 512 samples will get sent to the frontend for the current frame, sometimes 1024 as the core either falls behind or overcompensates. As a result, when the frontend tries to synchronise on audio, jitter can occur - and if the frontend audio buffer is small (when using low latency values), it can sometimes run dry or reach capacity, causing crackling.

This PR modifies audio handling in the libretro layer such that the correct expected number of samples is sent to the frontend in proper synchronisation with retro_run(). With this change I no longer experience cracking audio in GBA games, and the 240p test suit demonstrates smooth scrolling.

Note that the changes here only affect GBA content. GB/GBC emulation produces irregular audio sample pacing that is not consistent with the set sample rate, and so I am unsure how best to handle it. The existing AVStream audio callback and fixed buffer size of 512 is therefore maintained for GB/GBC content (since it already seems to produce acceptable results in most cases)

@Ryunam
Copy link

Ryunam commented Oct 28, 2021

That's amazing! I definitely remember noticing and reporting this issue quite a few years ago and it's cool to see it addressed at last. :) Many thanks for taking the time to work on it.

@jdgleaver
Copy link
Author

You're very welcome! I'm happy to help :)

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.

None yet

3 participants