Streaming for VOC files in ScummVM
|Reported by:||agent-q||Owned by:||agent-q|
The following patch enables VOC streams created with makeVOCStream() to stream audio a chunk at a time from disk rather than loading the whole sample into memory. This massively reduces the memory requirements of a VOC stream.
A new class, LinearDiskStream, takes an array of positions and sizes within a stream and plays them as if they were appended together as one sample. This is needed for VOC files because they can (and do) contain more than one block of sample data non-contiguous in a file.
New code in voc.cpp parses the VOC format and creates the sample block data which is used by LinearDiskStream. There is a certain amount of duplication of code here, but I couldn't find a way to avoid it.
It is anticipated that LinearDiskStream could be used to stream WAVs or any other file format containing uncompressed data. All that is needed is a function to create a block list (perhaps of only one block for WAV file format) specifying where the same data is in the stream.
The preprocessor symbol STREAM_AUDIO_FROM_DISK must be added to enable the new streaming functionality (currently used only for VOC files), without it everything runs as before. I added it to common/scummsys.h
This is tested in the Scumm engine and the Kyra engine, and there are no problems. I'll be testing others as I do my normal testing.
A small change is needed (included in this patch) to the Kyra engine to prevent it from deleting the stream object after creating the audio stream. This may be needed for other engines too.
Looping is not yet supported, mainly because it seems to never be used, at least for VOC files.
Ticket imported from: #2834001. Ticket imported from: patches/1171.