[Scummvm-devel] Idea: IndexedMp3AudioStream

yotam barnoy yotambarnoy at gmail.com
Thu Oct 7 10:21:12 CEST 2010


Hey guys

I would like to address problems that occur with small devices and
ripped mp3 CD tracks in those games that have them. There are 2
problems:

1. We immediately get the playback length of every AudioCD
AudioStream, both in AudioCDManager and in makeLoopingAudioStream. In
our mp3 files (which are usually VBR) we have to read all the way from
the start of the file to the end of the file in order to get the
playback length. CD rips can be in the order of tens of megabytes and
mp3 files need to be read frame by frame, which on slow devices causes
read times of 20 seconds or more.

2. Every time we seek, we have to peruse the file until we find the
appropriate frame. If the seek is earlier in the file we go from the
beginning of the file. This process can take a long time on large
audio files as well.

The combined effect of 1 & 2 is even worse, as the mp3 file first
needs to be completely read to get its length, and then read again
until the playback point is found.

To deal with this issue, I propose a wrap to the mp3 AudioStream when
used for CD tracks. An IndexedMp3AudioStream will create an index file
for the mp3 the first time it's played. The index file will consist of
the total time of the file, followed by a list of (time, offset)
values at regular intervals. The index file will remain loaded while
the mp3AudioStream is initialized, and seeks will consist of finding
the nearest earlier point in a linked list of (time, offset) pairs.
This will be enabled only for small devices.

As an additional measure, we may want to get rid of the automatic
playback length retrieval in  makeLoopingAudioStream for small
devices, as this could cause slowdown in mp3 files other than CD
tracks as well.

Thoughts?

Yotam




More information about the Scummvm-devel mailing list