[FFmpeg-devel] Help with adding new adpcm decoder

James Darnley james.darnley at gmail.com
Tue Nov 22 13:47:04 EET 2016

I want to add a decoder for a game's music, specifically Falcom's Xanadu
Next.  I think the audio could be decompressed by adpcm_ms but the
problem comes from the rest of the format.

The file starts with a riff wave header that lies about being pcm and
other values, but I can force the decoder with ffmpeg.  In the data
block (which has an incorrect size) the data is divided into frames and
subframes of constant size (except for the last one).

The frames have an 8 byte header.  The first 4 being a little endian
number of the bytes in the frame, which is always 20480 0x5000 (except
for the last frame).  I am not sure of the meaning of the remaining 4
bytes.  In reality the header is almost always these bytes:
00 50 00 00 20 3e 01 00

The subframes are each 2048 bytes.  Each subframe leads with the
adpcm_ms specifics:
- two 1-byte 'block_predictor' for left and right channels
- two 2-byte 'idelta' values
- four 2-byte starting samples
(14 bytes)

10 subframes in each frame.  A quick and crap diagram:

| 8 byte header
|  2048 bytes
| [2048 bytes]

I can probably successfully decode with the existing code in
libavcodec/adpcm.c by adding a new codecand a few new cases to existing

My trouble is with how the AVPackets are created.  The decoder gets
packets of constant 4096 bytes.  The 8 byte frame header means the
packets drift from the subframes.  As a concrete example, the 2nd
2048-byte subframe would be split between the 1st and 2nd packets (just
8 bytes in the 2nd)

Is it the wave demuxer that splits the packets up like this?  I don't
think I can change that because the riff header lies about the data within.

In that case would I be best by tracking the drift using the adpcm
context structure and decoding what samples I can?  I think I will
attempt that anyway, right now, before I get any feedback.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 603 bytes
Desc: OpenPGP digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161122/8783ba0b/attachment.sig>

More information about the ffmpeg-devel mailing list