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.
This uses the chd_precache() function of libchdr which just loads the
CHD image to memory without decompressing it. So this is "weaker" than
the full preload to RAM option, which fully decompresses the CHD image,
but it still solves the problem of having the CHD images stored on
unreliable network storage. It's also much faster, since CHDs are quite
slow to decompress in whole.
The main point of this is to be able to use M3U files to run multi-disc
games and still be able to work around unreliable storage. The full
preload to RAM option does not work with M3U files. This option does.
CHD precache is ignored (and the option disabled in the UI) if the full
preload to RAM option is enabled.