libretro / swanstation

GNU General Public License v3.0
96 stars 22 forks source link

Don't submit audio samples to frontend multiple times mid-frame #9

Closed realnc closed 2 years ago

realnc commented 2 years ago

The core is submitting audio samples to the frontend in multiple calls before the current video frame loop has finished. This is a bad idea, as the retro_audio_sample_batch_t callback is a blocking call, since the frontend performs audio sync.

When using a low audio latency setting in RetroArch (like 5ms), audio dropouts can occur. It's also possible that input lag is increased, since video frames are presented later than they could have. The calls to retro_audio_sample_batch_t can block for over 10ms, unnecessarily delaying video frame presentation.

This commit fixes the issue by submitting all accumulated audio samples at the end of the current video frame. Since the rendered audio is stored in a HeapFIFOQueue which is not contiguous, an extra buffer is used to consolidate all samples into a contiguous buffer. The buffer is a stack allocated std::array so there's no memory allocation involved.