[FFmpeg-cvslog] avcodec/adpcm: add support for 5.1 ADPCM MS
Paul B Mahol
git at videolan.org
Fri Jul 26 13:57:37 EEST 2019
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu Jul 25 16:11:27 2019 +0200| [f79873409b058fe612bacddc1112d66c2fadf59d] | committer: Kieran Kunhya
avcodec/adpcm: add support for 5.1 ADPCM MS
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f79873409b058fe612bacddc1112d66c2fadf59d
---
libavcodec/adpcm.c | 31 ++++++++++++++++++++++++++++++-
libavformat/wavdec.c | 2 ++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index e194764374..2d3f432ffb 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -105,6 +105,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
case AV_CODEC_ID_ADPCM_EA_R2:
case AV_CODEC_ID_ADPCM_EA_R3:
case AV_CODEC_ID_ADPCM_EA_XAS:
+ case AV_CODEC_ID_ADPCM_MS:
max_channels = 6;
break;
case AV_CODEC_ID_ADPCM_MTAF:
@@ -170,6 +171,10 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
avctx->sample_fmt = c->vqa_version == 3 ? AV_SAMPLE_FMT_S16P :
AV_SAMPLE_FMT_S16;
break;
+ case AV_CODEC_ID_ADPCM_MS:
+ avctx->sample_fmt = avctx->channels > 2 ? AV_SAMPLE_FMT_S16P :
+ AV_SAMPLE_FMT_S16;
+ break;
default:
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
}
@@ -924,6 +929,29 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
{
int block_predictor;
+ if (avctx->channels > 2) {
+ for (channel = 0; channel < avctx->channels; channel++) {
+ samples = samples_p[channel];
+ block_predictor = bytestream2_get_byteu(&gb);
+ if (block_predictor > 6) {
+ av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[%d] = %d\n",
+ channel, block_predictor);
+ return AVERROR_INVALIDDATA;
+ }
+ c->status[channel].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
+ c->status[channel].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
+ c->status[channel].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
+ c->status[channel].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
+ c->status[channel].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
+ *samples++ = c->status[channel].sample2;
+ *samples++ = c->status[channel].sample1;
+ for(n = (nb_samples - 2) >> 1; n > 0; n--) {
+ int byte = bytestream2_get_byteu(&gb);
+ *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte >> 4 );
+ *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte & 0x0F);
+ }
+ }
+ } else {
block_predictor = bytestream2_get_byteu(&gb);
if (block_predictor > 6) {
av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
@@ -961,6 +989,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
*samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 );
*samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
}
+ }
break;
}
case AV_CODEC_ID_ADPCM_MTAF:
@@ -1810,7 +1839,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_RAD, sample_fmts_s16, adpcm_ima_rad,
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood");
-ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_s16, adpcm_ms, "ADPCM Microsoft");
+ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_both, adpcm_ms, "ADPCM Microsoft");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 684efd97f9..52194f54ef 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -590,6 +590,8 @@ break_loop:
} else if (st->codecpar->codec_id == AV_CODEC_ID_XMA1 ||
st->codecpar->codec_id == AV_CODEC_ID_XMA2) {
st->codecpar->block_align = 2048;
+ } else if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_MS && st->codecpar->channels > 2) {
+ st->codecpar->block_align *= st->codecpar->channels;
}
ff_metadata_conv_ctx(s, NULL, wav_metadata_conv);
More information about the ffmpeg-cvslog
mailing list