[FFmpeg-devel] [PATCH] avcodec/adpcm: consolidate tables into adpcm_data.c

Paul B Mahol onemda at gmail.com
Tue Mar 10 15:52:25 EET 2020


I fail to see how useful this is.
Unless you plan to write encoder it is not useful.

On 3/10/20, Zane van Iperen <zane at zanevaniperen.com> wrote:
> Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>
> ---
>  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 */
> --
> 2.17.1
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list