From patchwork Tue Mar 10 13:10:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 18106 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2E94E44A2BD for ; Tue, 10 Mar 2020 15:10:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0B0EF6882F4; Tue, 10 Mar 2020 15:10:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail2.protonmail.ch (mail2.protonmail.ch [185.70.40.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A5A61687FE4 for ; Tue, 10 Mar 2020 15:10:30 +0200 (EET) Date: Tue, 10 Mar 2020 13:10:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail; t=1583845828; bh=Cg1X7ZZ0OgwCyA0ONgmc6mSBA6J61JpxJHu50VYwafM=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=h96zyK2aYIdIK7CRrL8E39AVo3KaZjRDcumfp8LrtS58ZiM+lILPFWizDB9stn2kZ dQQf0v1i48EgMi5k+JayRhO6bODD3dCDFAGjWToh88mhXPkI6kFGScVuyzEOqTGRtJ uw4FxlAntZ8lf/u6oEXFwWutFJL7IDturJEymcx0= To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200310131008.29859-1-zane@zanevaniperen.com> Feedback-ID: xylLYHwBzJW7F28tHN-oL9EBm6h5yqtCqG6YwPpJ2oMwBYJT6-HxTnFTF6p18axLiSywX61iUfj4CElBGg8-GA==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mail.protonmail.ch Subject: [FFmpeg-devel] [PATCH] avcodec/adpcm: consolidate tables into adpcm_data.c X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zane van Iperen --- libavcodec/adpcm.c | 67 +++++++++++------------------------------ libavcodec/adpcm_data.c | 29 ++++++++++++++++++ libavcodec/adpcm_data.h | 4 +++ 3 files changed, 51 insertions(+), 49 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index c69cac3379..c27d7103f2 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -60,37 +60,6 @@ * readstr http://www.geocities.co.jp/Playtown/2004/ */ -/* These are for CD-ROM XA ADPCM */ -static const int8_t xa_adpcm_table[5][2] = { - { 0, 0 }, - { 60, 0 }, - { 115, -52 }, - { 98, -55 }, - { 122, -60 } -}; - -static const int16_t ea_adpcm_table[] = { - 0, 240, 460, 392, - 0, 0, -208, -220, - 0, 1, 3, 4, - 7, 8, 10, 11, - 0, -1, -3, -4 -}; - -// padded to zero where table size is less then 16 -static const int8_t swf_index_tables[4][16] = { - /*2*/ { -1, 2 }, - /*3*/ { -1, -1, 2, 4 }, - /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 }, - /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 } -}; - -static const int8_t zork_index_table[8] = { - -1, -1, -1, 1, 4, 7, 10, 12, -}; - -/* end of tables */ - typedef struct ADPCMDecodeContext { ADPCMChannelStatus status[14]; int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */ @@ -483,7 +452,7 @@ static inline int16_t adpcm_zork_expand_nibble(ADPCMChannelStatus *c, uint8_t ni sample += c->predictor; sample = av_clip_int16(sample); - index += zork_index_table[(nibble >> 4) & 7]; + index += ff_adpcm_zork_index_table[(nibble >> 4) & 7]; index = av_clip(index, 0, 88); c->predictor = sample; @@ -510,12 +479,12 @@ static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1, for(i=0;i<4;i++) { shift = 12 - (in[4+i*2] & 15); filter = in[4+i*2] >> 4; - if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) { + if (filter >= FF_ARRAY_ELEMS(ff_adpcm_xa_table)) { avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter); filter=0; } - f0 = xa_adpcm_table[filter][0]; - f1 = xa_adpcm_table[filter][1]; + f0 = ff_adpcm_xa_table[filter][0]; + f1 = ff_adpcm_xa_table[filter][1]; s_1 = left->sample1; s_2 = left->sample2; @@ -539,13 +508,13 @@ static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1, shift = 12 - (in[5+i*2] & 15); filter = in[5+i*2] >> 4; - if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) { + if (filter >= FF_ARRAY_ELEMS(ff_adpcm_xa_table)) { avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter); filter=0; } - f0 = xa_adpcm_table[filter][0]; - f1 = xa_adpcm_table[filter][1]; + f0 = ff_adpcm_xa_table[filter][0]; + f1 = ff_adpcm_xa_table[filter][1]; for(j=0;j<28;j++) { d = in[16+i+j*4]; @@ -585,7 +554,7 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_ //read bits & initial values nb_bits = get_bits(&gb, 2)+2; - table = swf_index_tables[nb_bits-2]; + table = ff_adpcm_swf_index_tables[nb_bits-2]; k0 = 1 << (nb_bits-2); signmask = 1 << (nb_bits-1); @@ -1409,10 +1378,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, for (count1 = 0; count1 < nb_samples / 28; count1++) { int byte = bytestream2_get_byteu(&gb); - coeff1l = ea_adpcm_table[ byte >> 4 ]; - coeff2l = ea_adpcm_table[(byte >> 4 ) + 4]; - coeff1r = ea_adpcm_table[ byte & 0x0F]; - coeff2r = ea_adpcm_table[(byte & 0x0F) + 4]; + coeff1l = ff_adpcm_ea_table[ byte >> 4 ]; + coeff2l = ff_adpcm_ea_table[(byte >> 4 ) + 4]; + coeff1r = ff_adpcm_ea_table[ byte & 0x0F]; + coeff2r = ff_adpcm_ea_table[(byte & 0x0F) + 4]; byte = bytestream2_get_byteu(&gb); shift_left = 20 - (byte >> 4); @@ -1450,7 +1419,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, for(channel = 0; channel < avctx->channels; channel++) { int byte = bytestream2_get_byteu(&gb); for (i=0; i<2; i++) - coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i]; + coeff[channel][i] = ff_adpcm_ea_table[(byte >> 4) + 4*i]; shift[channel] = 20 - (byte & 0x0F); } for (count1 = 0; count1 < nb_samples / 2; count1++) { @@ -1515,8 +1484,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, for (count2=0; count2<28; count2++) *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16); } else { - coeff1 = ea_adpcm_table[ byte >> 4 ]; - coeff2 = ea_adpcm_table[(byte >> 4) + 4]; + coeff1 = ff_adpcm_ea_table[ byte >> 4 ]; + coeff2 = ff_adpcm_ea_table[(byte >> 4) + 4]; shift = 20 - (byte & 0x0F); for (count2=0; count2<28; count2++) { @@ -1561,7 +1530,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, for (n = 0; n < 4; n++, s += 32) { int val = sign_extend(bytestream2_get_le16u(&gb), 16); for (i=0; i<2; i++) - coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i]; + coeff[i][n] = ff_adpcm_ea_table[(val&0x0F)+4*i]; s[0] = val & ~0x0F; val = sign_extend(bytestream2_get_le16u(&gb), 16); @@ -1882,7 +1851,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, filter = bytestream2_get_byteu(&gb); shift = filter & 0xf; filter = filter >> 4; - if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) + if (filter >= FF_ARRAY_ELEMS(ff_adpcm_xa_table)) return AVERROR_INVALIDDATA; flag = bytestream2_get_byteu(&gb); @@ -1899,7 +1868,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } 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); + sample = (int)((scale >> shift) + (c->status[channel].sample1 * ff_adpcm_xa_table[filter][0] + c->status[channel].sample2 * ff_adpcm_xa_table[filter][1]) / 64); } *samples++ = av_clip_int16(sample); c->status[channel].sample2 = c->status[channel].sample1; diff --git a/libavcodec/adpcm_data.c b/libavcodec/adpcm_data.c index 4cce0a5857..d8b488197e 100644 --- a/libavcodec/adpcm_data.c +++ b/libavcodec/adpcm_data.c @@ -177,3 +177,32 @@ const int16_t ff_adpcm_mtaf_stepsize[32][16] = { { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365, -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, }, }; + +/* These are for CD-ROM XA ADPCM */ +const int8_t ff_adpcm_xa_table[5][2] = { + { 0, 0 }, + { 60, 0 }, + { 115, -52 }, + { 98, -55 }, + { 122, -60 } +}; + +const int16_t ff_adpcm_ea_table[20] = { + 0, 240, 460, 392, + 0, 0, -208, -220, + 0, 1, 3, 4, + 7, 8, 10, 11, + 0, -1, -3, -4 +}; + +// padded to zero where table size is less then 16 +const int8_t ff_adpcm_swf_index_tables[4][16] = { + /*2*/ { -1, 2 }, + /*3*/ { -1, -1, 2, 4 }, + /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 }, + /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 } +}; + +const int8_t ff_adpcm_zork_index_table[8] = { + -1, -1, -1, 1, 4, 7, 10, 12, +}; diff --git a/libavcodec/adpcm_data.h b/libavcodec/adpcm_data.h index 5a687131d8..601271e48a 100644 --- a/libavcodec/adpcm_data.h +++ b/libavcodec/adpcm_data.h @@ -42,5 +42,9 @@ extern const int16_t ff_adpcm_yamaha_indexscale[]; extern const int8_t ff_adpcm_yamaha_difflookup[]; extern const int16_t ff_adpcm_afc_coeffs[2][16]; extern const int16_t ff_adpcm_mtaf_stepsize[32][16]; +extern const int8_t ff_adpcm_xa_table[5][2]; +extern const int16_t ff_adpcm_ea_table[20]; +extern const int8_t ff_adpcm_swf_index_tables[4][16]; +extern const int8_t ff_adpcm_zork_index_table[8]; #endif /* AVCODEC_ADPCM_DATA_H */