[FFmpeg-devel] [PATCH v3 1/2] avcodec: add decoder for Rayman 2's ADPCM variant
Zane van Iperen
zane at zanevaniperen.com
Thu Feb 20 16:49:37 EET 2020
20/2/20 11:49 pm, Paul B Mahol пишет:
>
> On 2/20/20, Zane van Iperen <zane at zanevaniperen.com> wrote:
>> Adds support for the ADPCM variant used in Rayman 2's files.
>>
>> + case AV_CODEC_ID_ADPCM_IMA_APM:
>> + for (n = nb_samples / 2; n > 0; n--) {
>> + for (channel = 0; channel < avctx->channels; channel++) {
>> + int v = bytestream2_get_byteu(&gb);
>> + *samples++ =
>> adpcm_ima_qt_expand_nibble(&c->status[channel], v >> 4 , 3);
>> + samples[st] =
>> adpcm_ima_qt_expand_nibble(&c->status[channel], v & 0x0F, 3);
>
> This looks wrong. You increase samples twice, above and down bellow.
>
> Also, codec looks same as SSI just with optional extradata?
It's right. The channels are interleaved per-byte, not per-nibble as in SSI.
If you look underneath AV_CODEC_ID_ADPCM_IMA_WS, you'll see a similar construction.
In the v2 of this patch, I was doing this:
for (channel = 0; bytestream2_get_bytes_left(&gb) > 0;) {
int v = bytestream2_get_byteu(&gb);
*samples_p[channel]++ = adpcm_ima_qt_expand_nibble(&c->status[channel], v >> 4, 3);
*samples_p[channel]++ = adpcm_ima_qt_expand_nibble(&c->status[channel], v & 0x0F, 3);
channel = (channel + 1) % avctx->channels;
}
/* Changing samples_p changes the frame itself. Undo any damage. */
for (channel = 0; channel < avctx->channels; channel++)
samples_p[channel] -= nb_samples;
It's the same thing (except using S16P instead of S16), but I thought the IMA_WS version
seemed neater.
Regardless, my test files give the same hashes with both versions:
$ ./ffmpeg -loglevel error -i main\ title.apm -map 0:a -f md5 -
MD5=c6db6dac4372e6413624d20dcdbf33ac
$ ./ffmpeg -loglevel error -i outro1.apm -map 0:a -f md5 -
MD5=a5cb56a035ab4b79adceba6fe4a428d2
If you think the v2 form is better, simply disregard v3. This is the only difference
between them.
>> + }
>> + samples += avctx->channels;
>> + }
>> + break;
>> case AV_CODEC_ID_ADPCM_IMA_OKI:
Zane
More information about the ffmpeg-devel
mailing list