mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-01-02 20:30:03 +01:00
avcodec: add ADPCM PSXC audio decoder
(cherry picked from commit a4055b5cc6d77c26867948e24de6bdfd5c0e6a3b)
This commit is contained in:
@@ -1010,6 +1010,7 @@ OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_MTAF_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_N64_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_PSX_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_PSXC_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_SANYO_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
|
||||
|
||||
@@ -292,6 +292,11 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
|
||||
avctx->block_align % (16 * avctx->ch_layout.nb_channels))
|
||||
return AVERROR_INVALIDDATA;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_PSXC:
|
||||
max_channels = 8;
|
||||
if (avctx->ch_layout.nb_channels <= 0)
|
||||
return AVERROR_INVALIDDATA;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_IMA_DAT4:
|
||||
case AV_CODEC_ID_ADPCM_THP:
|
||||
case AV_CODEC_ID_ADPCM_THP_LE:
|
||||
@@ -349,6 +354,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
|
||||
case AV_CODEC_ID_ADPCM_AFC:
|
||||
case AV_CODEC_ID_ADPCM_DTK:
|
||||
case AV_CODEC_ID_ADPCM_PSX:
|
||||
case AV_CODEC_ID_ADPCM_PSXC:
|
||||
case AV_CODEC_ID_ADPCM_SANYO:
|
||||
case AV_CODEC_ID_ADPCM_MTAF:
|
||||
case AV_CODEC_ID_ADPCM_ARGO:
|
||||
@@ -1353,6 +1359,9 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
|
||||
case AV_CODEC_ID_ADPCM_PSX:
|
||||
nb_samples = buf_size / (16 * ch) * 28;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_PSXC:
|
||||
nb_samples = ((buf_size - 1) / ch) * 2;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_ARGO:
|
||||
nb_samples = buf_size / avctx->block_align * 32;
|
||||
break;
|
||||
@@ -2693,6 +2702,40 @@ static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
|
||||
}
|
||||
}
|
||||
) /* End of CASE */
|
||||
CASE(ADPCM_PSXC,
|
||||
for (int block = 0; block < avpkt->size / avctx->block_align; block++) {
|
||||
int nb_samples_per_block = ((avctx->block_align - 1) / channels) * 2;
|
||||
for (int channel = 0; channel < channels; channel++) {
|
||||
int filter, shift, byte;
|
||||
|
||||
samples = samples_p[channel] + block * nb_samples_per_block;
|
||||
av_assert0((block + 1) * nb_samples_per_block <= nb_samples);
|
||||
|
||||
filter = bytestream2_get_byteu(&gb);
|
||||
shift = filter & 0xf;
|
||||
filter = filter >> 4;
|
||||
if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table))
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
for (int n = 0; n < nb_samples_per_block; n++) {
|
||||
int sample = 0, scale;
|
||||
|
||||
if (n & 1) {
|
||||
scale = sign_extend(byte >> 4, 4);
|
||||
} else {
|
||||
byte = bytestream2_get_byteu(&gb);
|
||||
scale = sign_extend(byte & 0xF, 4);
|
||||
}
|
||||
|
||||
scale = scale * (1 << 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
) /* End of CASE */
|
||||
CASE(ADPCM_SANYO,
|
||||
int (*expand)(ADPCMChannelStatus *c, int bits);
|
||||
GetBitContext g;
|
||||
@@ -2904,6 +2947,7 @@ ADPCM_DECODER(ADPCM_MS, sample_fmts_both, adpcm_ms, "ADPCM Mic
|
||||
ADPCM_DECODER(ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF")
|
||||
ADPCM_DECODER(ADPCM_N64, sample_fmts_s16p, adpcm_n64, "ADPCM Silicon Graphics N64")
|
||||
ADPCM_DECODER(ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation")
|
||||
ADPCM_DECODER(ADPCM_PSXC, sample_fmts_s16p, adpcm_psxc, "ADPCM Playstation C")
|
||||
ADPCM_DECODER(ADPCM_SANYO, sample_fmts_s16p, adpcm_sanyo, "ADPCM Sanyo")
|
||||
ADPCM_DECODER(ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit")
|
||||
ADPCM_DECODER(ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit")
|
||||
|
||||
@@ -701,6 +701,7 @@ extern const FFCodec ff_adpcm_ms_decoder;
|
||||
extern const FFCodec ff_adpcm_mtaf_decoder;
|
||||
extern const FFCodec ff_adpcm_n64_decoder;
|
||||
extern const FFCodec ff_adpcm_psx_decoder;
|
||||
extern const FFCodec ff_adpcm_psxc_decoder;
|
||||
extern const FFCodec ff_adpcm_sanyo_decoder;
|
||||
extern const FFCodec ff_adpcm_sbpro_2_decoder;
|
||||
extern const FFCodec ff_adpcm_sbpro_3_decoder;
|
||||
|
||||
@@ -2669,6 +2669,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
|
||||
.long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA Magix"),
|
||||
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
|
||||
},
|
||||
{
|
||||
.id = AV_CODEC_ID_ADPCM_PSXC,
|
||||
.type = AVMEDIA_TYPE_AUDIO,
|
||||
.name = "adpcm_psxc",
|
||||
.long_name = NULL_IF_CONFIG_SMALL("ADPCM Playstation C"),
|
||||
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
|
||||
},
|
||||
|
||||
/* AMR */
|
||||
{
|
||||
|
||||
@@ -432,6 +432,7 @@ enum AVCodecID {
|
||||
AV_CODEC_ID_ADPCM_N64,
|
||||
AV_CODEC_ID_ADPCM_IMA_HVQM2,
|
||||
AV_CODEC_ID_ADPCM_IMA_MAGIX,
|
||||
AV_CODEC_ID_ADPCM_PSXC,
|
||||
|
||||
/* AMR */
|
||||
AV_CODEC_ID_AMR_NB = 0x12000,
|
||||
|
||||
@@ -677,6 +677,11 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
|
||||
if (frame_bytes > INT_MAX / 28)
|
||||
return 0;
|
||||
return frame_bytes * 28;
|
||||
case AV_CODEC_ID_ADPCM_PSXC:
|
||||
frame_bytes = (frame_bytes - 1) / ch;
|
||||
if (frame_bytes > INT_MAX / 2)
|
||||
return 0;
|
||||
return frame_bytes * 2;
|
||||
case AV_CODEC_ID_ADPCM_4XM:
|
||||
case AV_CODEC_ID_ADPCM_IMA_ACORN:
|
||||
case AV_CODEC_ID_ADPCM_IMA_DAT4:
|
||||
|
||||
Reference in New Issue
Block a user