[Scummvm-devel] Idea: IndexedMp3AudioStream
yotam barnoy
yotambarnoy at gmail.com
Thu Oct 7 15:38:06 CEST 2010
:)
Copied from the ID3 spec: [http://www.id3.org/id3v2.4.0-frames]
4.30. Audio seek point index
Audio files with variable bit rates are intrinsically difficult to
deal with in the case of seeking within the file. The ASPI frame
makes seeking easier by providing a list a seek points within the
audio file. The seek points are a fractional offset within the audio
data, providing a starting point from which to find an appropriate
point to start decoding. The presence of an ASPI frame requires the
existence of a TLEN frame, indicating the duration of the file in
milliseconds. There may only be one 'audio seek point index' frame in
a tag.
<Header for 'Seek Point Index', ID: "ASPI">
Indexed data start (S) $xx xx xx xx
Indexed data length (L) $xx xx xx xx
Number of index points (N) $xx xx
Bits per index point (b) $xx
Then for every index point the following data is included;
Fraction at index (Fi) $xx (xx)
'Indexed data start' is a byte offset from the beginning of the file.
'Indexed data length' is the byte length of the audio data being
indexed. 'Number of index points' is the number of index points, as
the name implies. The recommended number is 100. 'Bits per index
point' is 8 or 16, depending on the chosen precision. 8 bits works
well for short files (less than 5 minutes of audio), while 16 bits is
advantageous for long files. 'Fraction at index' is the numerator of
the fraction representing a relative position in the data. The
denominator is 2 to the power of b.
Here are the algorithms to be used in the calculation. The known data
must be the offset of the start of the indexed data (S), the offset
of the end of the indexed data (E), the number of index points (N),
the offset at index i (Oi). We calculate the fraction at index i
(Fi).
Oi is the offset of the frame whose start is soonest after the point
for which the time offset is (i/N * duration).
The frame data should be calculated as follows:
Fi = Oi/L * 2^b (rounded down to the nearest integer)
Offset calculation should be calculated as follows from data in the
frame:
Oi = (Fi/2^b)*L (rounded up to the nearest integer)
On Thu, Oct 7, 2010 at 3:29 PM, Willem Jan Palenstijn <wjp at usecode.org> wrote:
> On Thu, Oct 07, 2010 at 01:37:38PM +0200, Johannes Schickel wrote:
>> I take this index file will be written to disk too? I mean else we
>> would still suffer from the long delay on every time the MP3 file is
>> opened. Now how do you plan to handle filename clashes, like you have
>> two games with MP3 files for CDDA setup and then start one and then
>> the other, since savepath is the only real save place to write you
>> can't just use the mp3 filename and save the index to savepath. Also
>> of course all our make*Stream factory functions never take a filename
>> but a SeekableReadStream object.
>
> Or maybe just hash the first 4kB (or something) of the mp3 and use that as a
> key?
>
> -Willem Jan
>
More information about the Scummvm-devel
mailing list