[FFmpeg-cvslog] avcodec: add ADPCM PSX decoder
Paul B Mahol
git at videolan.org
Fri Oct 16 16:38:09 CEST 2015
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Oct 13 14:16:24 2015 +0200| [8b11e43799260009dead51667bf6ff0157c05ff4] | committer: Paul B Mahol
avcodec: add ADPCM PSX decoder
Signed-off-by: Paul B Mahol <onemda at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8b11e43799260009dead51667bf6ff0157c05ff4
---
libavcodec/Makefile | 1 +
libavcodec/adpcm.c | 40 ++++++++++++++++++++++++++++++++++++++++
libavcodec/allcodecs.c | 1 +
libavcodec/avcodec.h | 1 +
libavcodec/codec_desc.c | 7 +++++++
libavcodec/utils.c | 1 +
libavcodec/version.h | 2 +-
7 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8f7493e..1e1e479 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -687,6 +687,7 @@ OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_PSX_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_SBPRO_4_DECODER) += adpcm.o adpcm_data.o
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index ba38041..11eb974 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -152,6 +152,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
case AV_CODEC_ID_ADPCM_THP_LE:
case AV_CODEC_ID_ADPCM_AFC:
case AV_CODEC_ID_ADPCM_DTK:
+ case AV_CODEC_ID_ADPCM_PSX:
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
break;
case AV_CODEC_ID_ADPCM_IMA_WS:
@@ -665,6 +666,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
nb_samples = (buf_size / 128) * 224 / ch;
break;
case AV_CODEC_ID_ADPCM_DTK:
+ case AV_CODEC_ID_ADPCM_PSX:
nb_samples = buf_size / (16 * ch) * 28;
break;
}
@@ -1548,6 +1550,43 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
bytestream2_seek(&gb, 0, SEEK_SET);
}
break;
+ case AV_CODEC_ID_ADPCM_PSX:
+ for (channel = 0; channel < avctx->channels; channel++) {
+ samples = samples_p[channel];
+
+ /* Read in every sample for this channel. */
+ for (i = 0; i < nb_samples / 28; i++) {
+ int filter, shift, flag, byte;
+
+ filter = bytestream2_get_byteu(&gb);
+ shift = filter & 0xf;
+ filter = filter >> 4;
+ if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table))
+ return AVERROR_INVALIDDATA;
+ flag = bytestream2_get_byteu(&gb);
+
+ /* Decode 28 samples. */
+ for (n = 0; n < 28; n++) {
+ int sample = 0, scale;
+
+ if (flag < 0x07) {
+ if (n & 1) {
+ scale = sign_extend(byte >> 4, 4);
+ } else {
+ byte = bytestream2_get_byteu(&gb);
+ scale = sign_extend(byte, 4);
+ }
+
+ scale = scale << 12;
+ sample = (int)((scale >> shift) + (c->status[channel].sample1 * xa_adpcm_table[filter][0] + c->status[channel].sample2 * xa_adpcm_table[filter][1]) / 64);
+ }
+ *samples++ = av_clip_int16(sample);
+ c->status[channel].sample2 = c->status[channel].sample1;
+ c->status[channel].sample1 = sample;
+ }
+ }
+ }
+ break;
default:
return -1;
@@ -1622,6 +1661,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg,
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_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM PSX");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b506463..d62bec7 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -509,6 +509,7 @@ void avcodec_register_all(void)
REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav);
REGISTER_DECODER(ADPCM_IMA_WS, adpcm_ima_ws);
REGISTER_ENCDEC (ADPCM_MS, adpcm_ms);
+ REGISTER_DECODER(ADPCM_PSX, adpcm_psx);
REGISTER_DECODER(ADPCM_SBPRO_2, adpcm_sbpro_2);
REGISTER_DECODER(ADPCM_SBPRO_3, adpcm_sbpro_3);
REGISTER_DECODER(ADPCM_SBPRO_4, adpcm_sbpro_4);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 531286a..18889ec 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -393,6 +393,7 @@ enum AVCodecID {
AV_CODEC_ID_ADPCM_IMA_RAD,
AV_CODEC_ID_ADPCM_G726LE,
AV_CODEC_ID_ADPCM_THP_LE,
+ AV_CODEC_ID_ADPCM_PSX,
/* AMR */
AV_CODEC_ID_AMR_NB = 0x12000,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 0817f0c..6979857 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1978,6 +1978,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("LucasArts VIMA audio"),
.props = AV_CODEC_PROP_LOSSY,
},
+ {
+ .id = AV_CODEC_ID_ADPCM_PSX,
+ .type = AVMEDIA_TYPE_AUDIO,
+ .name = "adpcm_psx",
+ .long_name = NULL_IF_CONFIG_SMALL("ADPCM PSX"),
+ .props = AV_CODEC_PROP_LOSSY,
+ },
/* AMR */
{
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 0e4f3c0..0ae35ed 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -3063,6 +3063,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
switch (id) {
case AV_CODEC_ID_ADPCM_AFC:
return frame_bytes / (9 * ch) * 16;
+ case AV_CODEC_ID_ADPCM_PSX:
case AV_CODEC_ID_ADPCM_DTK:
return frame_bytes / (16 * ch) * 28;
case AV_CODEC_ID_ADPCM_4XM:
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 953ff9f..97f4ae4 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57
-#define LIBAVCODEC_VERSION_MINOR 6
+#define LIBAVCODEC_VERSION_MINOR 7
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
More information about the ffmpeg-cvslog
mailing list