LCOV - code coverage report
Current view: top level - libavcodec - on2avc.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 201 601 33.4 %
Date: 2017-12-13 10:57:33 Functions: 14 24 58.3 %

          Line data    Source code
       1             : /*
       2             :  * On2 Audio for Video Codec decoder
       3             :  *
       4             :  * Copyright (c) 2013 Konstantin Shishkov
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include "libavutil/channel_layout.h"
      24             : #include "libavutil/ffmath.h"
      25             : #include "libavutil/float_dsp.h"
      26             : #include "avcodec.h"
      27             : #include "bytestream.h"
      28             : #include "fft.h"
      29             : #include "get_bits.h"
      30             : #include "internal.h"
      31             : 
      32             : #include "on2avcdata.h"
      33             : 
      34             : #define ON2AVC_SUBFRAME_SIZE   1024
      35             : 
      36             : enum WindowTypes {
      37             :     WINDOW_TYPE_LONG       = 0,
      38             :     WINDOW_TYPE_LONG_STOP,
      39             :     WINDOW_TYPE_LONG_START,
      40             :     WINDOW_TYPE_8SHORT     = 3,
      41             :     WINDOW_TYPE_EXT4,
      42             :     WINDOW_TYPE_EXT5,
      43             :     WINDOW_TYPE_EXT6,
      44             :     WINDOW_TYPE_EXT7,
      45             : };
      46             : 
      47             : typedef struct On2AVCContext {
      48             :     AVCodecContext *avctx;
      49             :     AVFloatDSPContext *fdsp;
      50             :     FFTContext mdct, mdct_half, mdct_small;
      51             :     FFTContext fft128, fft256, fft512, fft1024;
      52             :     void (*wtf)(struct On2AVCContext *ctx, float *out, float *in, int size);
      53             : 
      54             :     int is_av500;
      55             : 
      56             :     const On2AVCMode *modes;
      57             :     int window_type, prev_window_type;
      58             :     int num_windows, num_bands;
      59             :     int bits_per_section;
      60             :     const int *band_start;
      61             : 
      62             :     int grouping[8];
      63             :     int ms_present;
      64             :     int ms_info[ON2AVC_MAX_BANDS];
      65             : 
      66             :     int is_long;
      67             : 
      68             :     uint8_t band_type[ON2AVC_MAX_BANDS];
      69             :     uint8_t band_run_end[ON2AVC_MAX_BANDS];
      70             :     int     num_sections;
      71             : 
      72             :     float band_scales[ON2AVC_MAX_BANDS];
      73             : 
      74             :     VLC scale_diff;
      75             :     VLC cb_vlc[16];
      76             : 
      77             :     float scale_tab[128];
      78             : 
      79             :     DECLARE_ALIGNED(32, float, coeffs)[2][ON2AVC_SUBFRAME_SIZE];
      80             :     DECLARE_ALIGNED(32, float, delay) [2][ON2AVC_SUBFRAME_SIZE];
      81             : 
      82             :     DECLARE_ALIGNED(32, float, temp)     [ON2AVC_SUBFRAME_SIZE * 2];
      83             :     DECLARE_ALIGNED(32, float, mdct_buf) [ON2AVC_SUBFRAME_SIZE];
      84             :     DECLARE_ALIGNED(32, float, long_win) [ON2AVC_SUBFRAME_SIZE];
      85             :     DECLARE_ALIGNED(32, float, short_win)[ON2AVC_SUBFRAME_SIZE / 8];
      86             : } On2AVCContext;
      87             : 
      88          30 : static void on2avc_read_ms_info(On2AVCContext *c, GetBitContext *gb)
      89             : {
      90          30 :     int w, b, band_off = 0;
      91             : 
      92          30 :     c->ms_present = get_bits1(gb);
      93          30 :     if (!c->ms_present)
      94          30 :         return;
      95           0 :     for (w = 0; w < c->num_windows; w++) {
      96           0 :         if (!c->grouping[w]) {
      97           0 :             memcpy(c->ms_info + band_off,
      98           0 :                    c->ms_info + band_off - c->num_bands,
      99           0 :                    c->num_bands * sizeof(*c->ms_info));
     100           0 :             band_off += c->num_bands;
     101           0 :             continue;
     102             :         }
     103           0 :         for (b = 0; b < c->num_bands; b++)
     104           0 :             c->ms_info[band_off++] = get_bits1(gb);
     105             :     }
     106             : }
     107             : 
     108             : // do not see Table 17 in ISO/IEC 13818-7
     109          30 : static int on2avc_decode_band_types(On2AVCContext *c, GetBitContext *gb)
     110             : {
     111          30 :     int bits_per_sect = c->is_long ? 5 : 3;
     112          30 :     int esc_val = (1 << bits_per_sect) - 1;
     113          30 :     int num_bands = c->num_bands * c->num_windows;
     114          30 :     int band = 0, i, band_type, run_len, run;
     115             : 
     116         285 :     while (band < num_bands) {
     117         225 :         band_type = get_bits(gb, 4);
     118         225 :         run_len   = 1;
     119             :         do {
     120         225 :             run = get_bits(gb, bits_per_sect);
     121         225 :             if (run > num_bands - band - run_len) {
     122           0 :                 av_log(c->avctx, AV_LOG_ERROR, "Invalid band type run\n");
     123           0 :                 return AVERROR_INVALIDDATA;
     124             :             }
     125         225 :             run_len += run;
     126         225 :         } while (run == esc_val);
     127        1695 :         for (i = band; i < band + run_len; i++) {
     128        1470 :             c->band_type[i]    = band_type;
     129        1470 :             c->band_run_end[i] = band + run_len;
     130             :         }
     131         225 :         band += run_len;
     132             :     }
     133             : 
     134          30 :     return 0;
     135             : }
     136             : 
     137             : // completely not like Table 18 in ISO/IEC 13818-7
     138             : // (no intensity stereo, different coding for the first coefficient)
     139          30 : static int on2avc_decode_band_scales(On2AVCContext *c, GetBitContext *gb)
     140             : {
     141          30 :     int w, w2, b, scale, first = 1;
     142          30 :     int band_off = 0;
     143             : 
     144          60 :     for (w = 0; w < c->num_windows; w++) {
     145          30 :         if (!c->grouping[w]) {
     146           0 :             memcpy(c->band_scales + band_off,
     147           0 :                    c->band_scales + band_off - c->num_bands,
     148           0 :                    c->num_bands * sizeof(*c->band_scales));
     149           0 :             band_off += c->num_bands;
     150           0 :             continue;
     151             :         }
     152        1500 :         for (b = 0; b < c->num_bands; b++) {
     153        1470 :             if (!c->band_type[band_off]) {
     154         211 :                 int all_zero = 1;
     155         211 :                 for (w2 = w + 1; w2 < c->num_windows; w2++) {
     156           0 :                     if (c->grouping[w2])
     157           0 :                         break;
     158           0 :                     if (c->band_type[w2 * c->num_bands + b]) {
     159           0 :                         all_zero = 0;
     160           0 :                         break;
     161             :                     }
     162             :                 }
     163         211 :                 if (all_zero) {
     164         211 :                     c->band_scales[band_off++] = 0;
     165         211 :                     continue;
     166             :                 }
     167             :             }
     168        1259 :             if (first) {
     169          30 :                 scale = get_bits(gb, 7);
     170          30 :                 first = 0;
     171             :             } else {
     172        1229 :                 scale += get_vlc2(gb, c->scale_diff.table, 9, 3) - 60;
     173             :             }
     174        1259 :             if (scale < 0 || scale > 127) {
     175           0 :                 av_log(c->avctx, AV_LOG_ERROR, "Invalid scale value %d\n",
     176             :                        scale);
     177           0 :                 return AVERROR_INVALIDDATA;
     178             :             }
     179        1259 :             c->band_scales[band_off++] = c->scale_tab[scale];
     180             :         }
     181             :     }
     182             : 
     183          30 :     return 0;
     184             : }
     185             : 
     186       20628 : static inline float on2avc_scale(int v, float scale)
     187             : {
     188       20628 :     return v * sqrtf(abs(v)) * scale;
     189             : }
     190             : 
     191             : // spectral data is coded completely differently - there are no unsigned codebooks
     192        1249 : static int on2avc_decode_quads(On2AVCContext *c, GetBitContext *gb, float *dst,
     193             :                                int dst_size, int type, float band_scale)
     194             : {
     195             :     int i, j, val, val1;
     196             : 
     197        6396 :     for (i = 0; i < dst_size; i += 4) {
     198        5147 :         val = get_vlc2(gb, c->cb_vlc[type].table, 9, 3);
     199             : 
     200       25735 :         for (j = 0; j < 4; j++) {
     201       20588 :             val1 = sign_extend((val >> (12 - j * 4)) & 0xF, 4);
     202       20588 :             *dst++ = on2avc_scale(val1, band_scale);
     203             :         }
     204             :     }
     205             : 
     206        1249 :     return 0;
     207             : }
     208             : 
     209           2 : static inline int get_egolomb(GetBitContext *gb)
     210             : {
     211           2 :     int v = 4;
     212             : 
     213           5 :     while (get_bits1(gb)) {
     214           1 :         v++;
     215           1 :         if (v > 30) {
     216           0 :             av_log(NULL, AV_LOG_WARNING, "Too large golomb code in get_egolomb.\n");
     217           0 :             v = 30;
     218           0 :             break;
     219             :         }
     220             :     }
     221             : 
     222           2 :     return (1 << v) + get_bits_long(gb, v);
     223             : }
     224             : 
     225          10 : static int on2avc_decode_pairs(On2AVCContext *c, GetBitContext *gb, float *dst,
     226             :                                int dst_size, int type, float band_scale)
     227             : {
     228             :     int i, val, val1, val2, sign;
     229             : 
     230          30 :     for (i = 0; i < dst_size; i += 2) {
     231          20 :         val = get_vlc2(gb, c->cb_vlc[type].table, 9, 3);
     232             : 
     233          20 :         val1 = sign_extend(val >> 8,   8);
     234          20 :         val2 = sign_extend(val & 0xFF, 8);
     235          20 :         if (type == ON2AVC_ESC_CB) {
     236           6 :             if (val1 <= -16 || val1 >= 16) {
     237           1 :                 sign = 1 - (val1 < 0) * 2;
     238           1 :                 val1 = sign * get_egolomb(gb);
     239             :             }
     240           6 :             if (val2 <= -16 || val2 >= 16) {
     241           1 :                 sign = 1 - (val2 < 0) * 2;
     242           1 :                 val2 = sign * get_egolomb(gb);
     243             :             }
     244             :         }
     245             : 
     246          20 :         *dst++ = on2avc_scale(val1, band_scale);
     247          20 :         *dst++ = on2avc_scale(val2, band_scale);
     248             :     }
     249             : 
     250          10 :     return 0;
     251             : }
     252             : 
     253          30 : static int on2avc_read_channel_data(On2AVCContext *c, GetBitContext *gb, int ch)
     254             : {
     255             :     int ret;
     256             :     int w, b, band_idx;
     257             :     float *coeff_ptr;
     258             : 
     259          30 :     if ((ret = on2avc_decode_band_types(c, gb)) < 0)
     260           0 :         return ret;
     261          30 :     if ((ret = on2avc_decode_band_scales(c, gb)) < 0)
     262           0 :         return ret;
     263             : 
     264          30 :     coeff_ptr = c->coeffs[ch];
     265          30 :     band_idx  = 0;
     266          30 :     memset(coeff_ptr, 0, ON2AVC_SUBFRAME_SIZE * sizeof(*coeff_ptr));
     267          60 :     for (w = 0; w < c->num_windows; w++) {
     268        1500 :         for (b = 0; b < c->num_bands; b++) {
     269        1470 :             int band_size = c->band_start[b + 1] - c->band_start[b];
     270        1470 :             int band_type = c->band_type[band_idx + b];
     271             : 
     272        1470 :             if (!band_type) {
     273         211 :                 coeff_ptr += band_size;
     274         211 :                 continue;
     275             :             }
     276        1259 :             if (band_type < 9)
     277        1249 :                 on2avc_decode_quads(c, gb, coeff_ptr, band_size, band_type,
     278        1249 :                                     c->band_scales[band_idx + b]);
     279             :             else
     280          10 :                 on2avc_decode_pairs(c, gb, coeff_ptr, band_size, band_type,
     281          10 :                                     c->band_scales[band_idx + b]);
     282        1259 :             coeff_ptr += band_size;
     283             :         }
     284          30 :         band_idx += c->num_bands;
     285             :     }
     286             : 
     287          30 :     return 0;
     288             : }
     289             : 
     290           0 : static int on2avc_apply_ms(On2AVCContext *c)
     291             : {
     292             :     int w, b, i;
     293           0 :     int band_off = 0;
     294           0 :     float *ch0 = c->coeffs[0];
     295           0 :     float *ch1 = c->coeffs[1];
     296             : 
     297           0 :     for (w = 0; w < c->num_windows; w++) {
     298           0 :         for (b = 0; b < c->num_bands; b++) {
     299           0 :             if (c->ms_info[band_off + b]) {
     300           0 :                 for (i = c->band_start[b]; i < c->band_start[b + 1]; i++) {
     301           0 :                     float l = *ch0, r = *ch1;
     302           0 :                     *ch0++ = l + r;
     303           0 :                     *ch1++ = l - r;
     304             :                 }
     305             :             } else {
     306           0 :                 ch0 += c->band_start[b + 1] - c->band_start[b];
     307           0 :                 ch1 += c->band_start[b + 1] - c->band_start[b];
     308             :             }
     309             :         }
     310           0 :         band_off += c->num_bands;
     311             :     }
     312           0 :     return 0;
     313             : }
     314             : 
     315           0 : static void zero_head_and_tail(float *src, int len, int order0, int order1)
     316             : {
     317           0 :     memset(src,                0, sizeof(*src) * order0);
     318           0 :     memset(src + len - order1, 0, sizeof(*src) * order1);
     319           0 : }
     320             : 
     321           0 : static void pretwiddle(float *src, float *dst, int dst_len, int tab_step,
     322             :                        int step, int order0, int order1, const double * const *tabs)
     323             : {
     324             :     float *src2, *out;
     325             :     const double *tab;
     326             :     int i, j;
     327             : 
     328           0 :     out = dst;
     329           0 :     tab = tabs[0];
     330           0 :     for (i = 0; i < tab_step; i++) {
     331           0 :         double sum = 0;
     332           0 :         for (j = 0; j < order0; j++)
     333           0 :             sum += src[j] * tab[j * tab_step + i];
     334           0 :         out[i] += sum;
     335             :     }
     336             : 
     337           0 :     out = dst + dst_len - tab_step;
     338           0 :     tab = tabs[order0];
     339           0 :     src2 = src + (dst_len - tab_step) / step + 1 + order0;
     340           0 :     for (i = 0; i < tab_step; i++) {
     341           0 :         double sum = 0;
     342           0 :         for (j = 0; j < order1; j++)
     343           0 :             sum += src2[j] * tab[j * tab_step + i];
     344           0 :         out[i] += sum;
     345             :     }
     346           0 : }
     347             : 
     348           0 : static void twiddle(float *src1, float *src2, int src2_len,
     349             :                     const double *tab, int tab_len, int step,
     350             :                     int order0, int order1, const double * const *tabs)
     351             : {
     352             :     int steps;
     353             :     int mask;
     354             :     int i, j;
     355             : 
     356           0 :     steps = (src2_len - tab_len) / step + 1;
     357           0 :     pretwiddle(src1, src2, src2_len, tab_len, step, order0, order1, tabs);
     358           0 :     mask = tab_len - 1;
     359             : 
     360           0 :     for (i = 0; i < steps; i++) {
     361           0 :         float in0 = src1[order0 + i];
     362           0 :         int   pos = (src2_len - 1) & mask;
     363             : 
     364           0 :         if (pos < tab_len) {
     365           0 :             const double *t = tab;
     366           0 :             for (j = pos; j >= 0; j--)
     367           0 :                 src2[j] += in0 * *t++;
     368           0 :             for (j = 0; j < tab_len - pos - 1; j++)
     369           0 :                 src2[src2_len - j - 1] += in0 * tab[pos + 1 + j];
     370             :         } else {
     371           0 :             for (j = 0; j < tab_len; j++)
     372           0 :                 src2[pos - j] += in0 * tab[j];
     373             :         }
     374           0 :         mask = pos + step;
     375             :     }
     376           0 : }
     377             : 
     378             : #define CMUL1_R(s, t, is, it) \
     379             :     s[is + 0] * t[it + 0] - s[is + 1] * t[it + 1]
     380             : #define CMUL1_I(s, t, is, it) \
     381             :     s[is + 0] * t[it + 1] + s[is + 1] * t[it + 0]
     382             : #define CMUL2_R(s, t, is, it) \
     383             :     s[is + 0] * t[it + 0] + s[is + 1] * t[it + 1]
     384             : #define CMUL2_I(s, t, is, it) \
     385             :     s[is + 0] * t[it + 1] - s[is + 1] * t[it + 0]
     386             : 
     387             : #define CMUL0(dst, id, s0, s1, s2, s3, t0, t1, t2, t3, is, it)         \
     388             :     dst[id]     = s0[is] * t0[it]     + s1[is] * t1[it]                \
     389             :                 + s2[is] * t2[it]     + s3[is] * t3[it];               \
     390             :     dst[id + 1] = s0[is] * t0[it + 1] + s1[is] * t1[it + 1]            \
     391             :                 + s2[is] * t2[it + 1] + s3[is] * t3[it + 1];
     392             : 
     393             : #define CMUL1(dst, s0, s1, s2, s3, t0, t1, t2, t3, is, it)             \
     394             :     *dst++ = CMUL1_R(s0, t0, is, it)                                   \
     395             :            + CMUL1_R(s1, t1, is, it)                                   \
     396             :            + CMUL1_R(s2, t2, is, it)                                   \
     397             :            + CMUL1_R(s3, t3, is, it);                                  \
     398             :     *dst++ = CMUL1_I(s0, t0, is, it)                                   \
     399             :            + CMUL1_I(s1, t1, is, it)                                   \
     400             :            + CMUL1_I(s2, t2, is, it)                                   \
     401             :            + CMUL1_I(s3, t3, is, it);
     402             : 
     403             : #define CMUL2(dst, s0, s1, s2, s3, t0, t1, t2, t3, is, it)             \
     404             :     *dst++ = CMUL2_R(s0, t0, is, it)                                   \
     405             :            + CMUL2_R(s1, t1, is, it)                                   \
     406             :            + CMUL2_R(s2, t2, is, it)                                   \
     407             :            + CMUL2_R(s3, t3, is, it);                                  \
     408             :     *dst++ = CMUL2_I(s0, t0, is, it)                                   \
     409             :            + CMUL2_I(s1, t1, is, it)                                   \
     410             :            + CMUL2_I(s2, t2, is, it)                                   \
     411             :            + CMUL2_I(s3, t3, is, it);
     412             : 
     413           0 : static void combine_fft(float *s0, float *s1, float *s2, float *s3, float *dst,
     414             :                         const float *t0, const float *t1,
     415             :                         const float *t2, const float *t3, int len, int step)
     416             : {
     417             :     const float *h0, *h1, *h2, *h3;
     418             :     float *d1, *d2;
     419             :     int tmp, half;
     420           0 :     int len2 = len >> 1, len4 = len >> 2;
     421             :     int hoff;
     422             :     int i, j, k;
     423             : 
     424           0 :     tmp = step;
     425           0 :     for (half = len2; tmp > 1; half <<= 1, tmp >>= 1);
     426             : 
     427           0 :     h0 = t0 + half;
     428           0 :     h1 = t1 + half;
     429           0 :     h2 = t2 + half;
     430           0 :     h3 = t3 + half;
     431             : 
     432           0 :     CMUL0(dst, 0, s0, s1, s2, s3, t0, t1, t2, t3, 0, 0);
     433             : 
     434           0 :     hoff = 2 * step * (len4 >> 1);
     435             : 
     436           0 :     j = 2;
     437           0 :     k = 2 * step;
     438           0 :     d1 = dst + 2;
     439           0 :     d2 = dst + 2 + (len >> 1);
     440           0 :     for (i = 0; i < (len4 - 1) >> 1; i++) {
     441           0 :         CMUL1(d1, s0, s1, s2, s3, t0, t1, t2, t3, j, k);
     442           0 :         CMUL1(d2, s0, s1, s2, s3, h0, h1, h2, h3, j, k);
     443           0 :         j += 2;
     444           0 :         k += 2 * step;
     445             :     }
     446           0 :     CMUL0(dst, len4,        s0, s1, s2, s3, t0, t1, t2, t3, 1, hoff);
     447           0 :     CMUL0(dst, len4 + len2, s0, s1, s2, s3, h0, h1, h2, h3, 1, hoff);
     448             : 
     449           0 :     j = len4;
     450           0 :     k = hoff + 2 * step * len4;
     451           0 :     d1 = dst + len4 + 2;
     452           0 :     d2 = dst + len4 + 2 + len2;
     453           0 :     for (i = 0; i < (len4 - 2) >> 1; i++) {
     454           0 :         CMUL2(d1, s0, s1, s2, s3, t0, t1, t2, t3, j, k);
     455           0 :         CMUL2(d2, s0, s1, s2, s3, h0, h1, h2, h3, j, k);
     456           0 :         j -= 2;
     457           0 :         k += 2 * step;
     458             :     }
     459           0 :     CMUL0(dst, len2 + 4, s0, s1, s2, s3, t0, t1, t2, t3, 0, k);
     460           0 : }
     461             : 
     462           0 : static void wtf_end_512(On2AVCContext *c, float *out, float *src,
     463             :                         float *tmp0, float *tmp1)
     464             : {
     465           0 :     memcpy(src,        tmp0,      384 * sizeof(*tmp0));
     466           0 :     memcpy(tmp0 + 384, src + 384, 128 * sizeof(*tmp0));
     467             : 
     468           0 :     zero_head_and_tail(src,       128, 16, 4);
     469           0 :     zero_head_and_tail(src + 128, 128, 16, 4);
     470           0 :     zero_head_and_tail(src + 256, 128, 13, 7);
     471           0 :     zero_head_and_tail(src + 384, 128, 15, 5);
     472             : 
     473           0 :     c->fft128.fft_permute(&c->fft128, (FFTComplex*)src);
     474           0 :     c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 128));
     475           0 :     c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 256));
     476           0 :     c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 384));
     477           0 :     c->fft128.fft_calc(&c->fft128, (FFTComplex*)src);
     478           0 :     c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 128));
     479           0 :     c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 256));
     480           0 :     c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 384));
     481           0 :     combine_fft(src, src + 128, src + 256, src + 384, tmp1,
     482             :                 ff_on2avc_ctab_1, ff_on2avc_ctab_2,
     483             :                 ff_on2avc_ctab_3, ff_on2avc_ctab_4, 512, 2);
     484           0 :     c->fft512.fft_permute(&c->fft512, (FFTComplex*)tmp1);
     485           0 :     c->fft512.fft_calc(&c->fft512, (FFTComplex*)tmp1);
     486             : 
     487           0 :     pretwiddle(&tmp0[  0], tmp1, 512, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
     488           0 :     pretwiddle(&tmp0[128], tmp1, 512, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
     489           0 :     pretwiddle(&tmp0[256], tmp1, 512, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
     490           0 :     pretwiddle(&tmp0[384], tmp1, 512, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
     491             : 
     492           0 :     memcpy(src, tmp1, 512 * sizeof(float));
     493           0 : }
     494             : 
     495           0 : static void wtf_end_1024(On2AVCContext *c, float *out, float *src,
     496             :                          float *tmp0, float *tmp1)
     497             : {
     498           0 :     memcpy(src,        tmp0,      768 * sizeof(*tmp0));
     499           0 :     memcpy(tmp0 + 768, src + 768, 256 * sizeof(*tmp0));
     500             : 
     501           0 :     zero_head_and_tail(src,       256, 16, 4);
     502           0 :     zero_head_and_tail(src + 256, 256, 16, 4);
     503           0 :     zero_head_and_tail(src + 512, 256, 13, 7);
     504           0 :     zero_head_and_tail(src + 768, 256, 15, 5);
     505             : 
     506           0 :     c->fft256.fft_permute(&c->fft256, (FFTComplex*)src);
     507           0 :     c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 256));
     508           0 :     c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 512));
     509           0 :     c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 768));
     510           0 :     c->fft256.fft_calc(&c->fft256, (FFTComplex*)src);
     511           0 :     c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 256));
     512           0 :     c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 512));
     513           0 :     c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 768));
     514           0 :     combine_fft(src, src + 256, src + 512, src + 768, tmp1,
     515             :                 ff_on2avc_ctab_1, ff_on2avc_ctab_2,
     516             :                 ff_on2avc_ctab_3, ff_on2avc_ctab_4, 1024, 1);
     517           0 :     c->fft1024.fft_permute(&c->fft1024, (FFTComplex*)tmp1);
     518           0 :     c->fft1024.fft_calc(&c->fft1024, (FFTComplex*)tmp1);
     519             : 
     520           0 :     pretwiddle(&tmp0[  0], tmp1, 1024, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
     521           0 :     pretwiddle(&tmp0[256], tmp1, 1024, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
     522           0 :     pretwiddle(&tmp0[512], tmp1, 1024, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
     523           0 :     pretwiddle(&tmp0[768], tmp1, 1024, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
     524             : 
     525           0 :     memcpy(src, tmp1, 1024 * sizeof(float));
     526           0 : }
     527             : 
     528           0 : static void wtf_40(On2AVCContext *c, float *out, float *src, int size)
     529             : {
     530           0 :     float *tmp0 = c->temp, *tmp1 = c->temp + 1024;
     531             : 
     532           0 :     memset(tmp0, 0, sizeof(*tmp0) * 1024);
     533           0 :     memset(tmp1, 0, sizeof(*tmp1) * 1024);
     534             : 
     535           0 :     if (size == 512) {
     536           0 :         twiddle(src,       &tmp0[  0], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
     537           0 :         twiddle(src +   8, &tmp0[  0], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
     538           0 :         twiddle(src +  16, &tmp0[ 16], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
     539           0 :         twiddle(src +  24, &tmp0[ 16], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
     540           0 :         twiddle(src +  32, &tmp0[ 32], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
     541           0 :         twiddle(src +  40, &tmp0[ 32], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
     542           0 :         twiddle(src +  48, &tmp0[ 48], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
     543           0 :         twiddle(src +  56, &tmp0[ 48], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
     544           0 :         twiddle(&tmp0[ 0], &tmp1[  0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     545           0 :         twiddle(&tmp0[16], &tmp1[  0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     546           0 :         twiddle(&tmp0[32], &tmp1[ 32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     547           0 :         twiddle(&tmp0[48], &tmp1[ 32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     548           0 :         twiddle(src +  64, &tmp1[ 64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     549           0 :         twiddle(src +  80, &tmp1[ 64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     550           0 :         twiddle(src +  96, &tmp1[ 96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     551           0 :         twiddle(src + 112, &tmp1[ 96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     552           0 :         twiddle(src + 128, &tmp1[128], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     553           0 :         twiddle(src + 144, &tmp1[128], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     554           0 :         twiddle(src + 160, &tmp1[160], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     555           0 :         twiddle(src + 176, &tmp1[160], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     556             : 
     557           0 :         memset(tmp0, 0, 64 * sizeof(*tmp0));
     558             : 
     559           0 :         twiddle(&tmp1[  0], &tmp0[  0], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
     560           0 :         twiddle(&tmp1[ 32], &tmp0[  0], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
     561           0 :         twiddle(&tmp1[ 64], &tmp0[  0], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
     562           0 :         twiddle(&tmp1[ 96], &tmp0[  0], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
     563           0 :         twiddle(&tmp1[128], &tmp0[128], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
     564           0 :         twiddle(&tmp1[160], &tmp0[128], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
     565           0 :         twiddle(src + 192,  &tmp0[128], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
     566           0 :         twiddle(src + 224,  &tmp0[128], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
     567           0 :         twiddle(src + 256,  &tmp0[256], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
     568           0 :         twiddle(src + 288,  &tmp0[256], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
     569           0 :         twiddle(src + 320,  &tmp0[256], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
     570           0 :         twiddle(src + 352,  &tmp0[256], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
     571             : 
     572           0 :         wtf_end_512(c, out, src, tmp0, tmp1);
     573             :     } else {
     574           0 :         twiddle(src,       &tmp0[  0], 32, ff_on2avc_tab_20_1, 20, 2,  5,  4, ff_on2avc_tabs_9_20_1);
     575           0 :         twiddle(src +  16, &tmp0[  0], 32, ff_on2avc_tab_20_2, 20, 2,  4,  5, ff_on2avc_tabs_9_20_2);
     576           0 :         twiddle(src +  32, &tmp0[ 32], 32, ff_on2avc_tab_20_2, 20, 2,  4,  5, ff_on2avc_tabs_9_20_2);
     577           0 :         twiddle(src +  48, &tmp0[ 32], 32, ff_on2avc_tab_20_1, 20, 2,  5,  4, ff_on2avc_tabs_9_20_1);
     578           0 :         twiddle(src +  64, &tmp0[ 64], 32, ff_on2avc_tab_20_1, 20, 2,  5,  4, ff_on2avc_tabs_9_20_1);
     579           0 :         twiddle(src +  80, &tmp0[ 64], 32, ff_on2avc_tab_20_2, 20, 2,  4,  5, ff_on2avc_tabs_9_20_2);
     580           0 :         twiddle(src +  96, &tmp0[ 96], 32, ff_on2avc_tab_20_2, 20, 2,  4,  5, ff_on2avc_tabs_9_20_2);
     581           0 :         twiddle(src + 112, &tmp0[ 96], 32, ff_on2avc_tab_20_1, 20, 2,  5,  4, ff_on2avc_tabs_9_20_1);
     582           0 :         twiddle(&tmp0[ 0], &tmp1[  0], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     583           0 :         twiddle(&tmp0[32], &tmp1[  0], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     584           0 :         twiddle(&tmp0[64], &tmp1[ 64], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     585           0 :         twiddle(&tmp0[96], &tmp1[ 64], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     586           0 :         twiddle(src + 128, &tmp1[128], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     587           0 :         twiddle(src + 160, &tmp1[128], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     588           0 :         twiddle(src + 192, &tmp1[192], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     589           0 :         twiddle(src + 224, &tmp1[192], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     590           0 :         twiddle(src + 256, &tmp1[256], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     591           0 :         twiddle(src + 288, &tmp1[256], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     592           0 :         twiddle(src + 320, &tmp1[320], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     593           0 :         twiddle(src + 352, &tmp1[320], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     594             : 
     595           0 :         memset(tmp0, 0, 128 * sizeof(*tmp0));
     596             : 
     597           0 :         twiddle(&tmp1[  0], &tmp0[  0], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
     598           0 :         twiddle(&tmp1[ 64], &tmp0[  0], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
     599           0 :         twiddle(&tmp1[128], &tmp0[  0], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
     600           0 :         twiddle(&tmp1[192], &tmp0[  0], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
     601           0 :         twiddle(&tmp1[256], &tmp0[256], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
     602           0 :         twiddle(&tmp1[320], &tmp0[256], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
     603           0 :         twiddle(src + 384,  &tmp0[256], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
     604           0 :         twiddle(src + 448,  &tmp0[256], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
     605           0 :         twiddle(src + 512,  &tmp0[512], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
     606           0 :         twiddle(src + 576,  &tmp0[512], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
     607           0 :         twiddle(src + 640,  &tmp0[512], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
     608           0 :         twiddle(src + 704,  &tmp0[512], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
     609             : 
     610           0 :         wtf_end_1024(c, out, src, tmp0, tmp1);
     611             :     }
     612           0 : }
     613             : 
     614           0 : static void wtf_44(On2AVCContext *c, float *out, float *src, int size)
     615             : {
     616           0 :     float *tmp0 = c->temp, *tmp1 = c->temp + 1024;
     617             : 
     618           0 :     memset(tmp0, 0, sizeof(*tmp0) * 1024);
     619           0 :     memset(tmp1, 0, sizeof(*tmp1) * 1024);
     620             : 
     621           0 :     if (size == 512) {
     622           0 :         twiddle(src,       &tmp0[ 0], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
     623           0 :         twiddle(src +   8, &tmp0[ 0], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
     624           0 :         twiddle(src +  16, &tmp0[16], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
     625           0 :         twiddle(src +  24, &tmp0[16], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
     626           0 :         twiddle(src +  32, &tmp0[32], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
     627           0 :         twiddle(src +  40, &tmp0[32], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
     628           0 :         twiddle(src +  48, &tmp0[48], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
     629           0 :         twiddle(src +  56, &tmp0[48], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
     630           0 :         twiddle(&tmp0[ 0], &tmp1[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     631           0 :         twiddle(&tmp0[16], &tmp1[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     632           0 :         twiddle(&tmp0[32], &tmp1[32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     633           0 :         twiddle(&tmp0[48], &tmp1[32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     634           0 :         twiddle(src +  64, &tmp1[64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     635           0 :         twiddle(src +  80, &tmp1[64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     636           0 :         twiddle(src +  96, &tmp1[96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
     637           0 :         twiddle(src + 112, &tmp1[96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
     638             : 
     639           0 :         memset(tmp0, 0, 64 * sizeof(*tmp0));
     640             : 
     641           0 :         twiddle(&tmp1[ 0], &tmp0[  0], 128, ff_on2avc_tab_84_1, 84, 4, 16,  4, ff_on2avc_tabs_20_84_1);
     642           0 :         twiddle(&tmp1[32], &tmp0[  0], 128, ff_on2avc_tab_84_2, 84, 4, 16,  4, ff_on2avc_tabs_20_84_2);
     643           0 :         twiddle(&tmp1[64], &tmp0[  0], 128, ff_on2avc_tab_84_3, 84, 4, 13,  7, ff_on2avc_tabs_20_84_3);
     644           0 :         twiddle(&tmp1[96], &tmp0[  0], 128, ff_on2avc_tab_84_4, 84, 4, 15,  5, ff_on2avc_tabs_20_84_4);
     645           0 :         twiddle(src + 128, &tmp0[128], 128, ff_on2avc_tab_84_4, 84, 4, 15,  5, ff_on2avc_tabs_20_84_4);
     646           0 :         twiddle(src + 160, &tmp0[128], 128, ff_on2avc_tab_84_3, 84, 4, 13,  7, ff_on2avc_tabs_20_84_3);
     647           0 :         twiddle(src + 192, &tmp0[128], 128, ff_on2avc_tab_84_2, 84, 4, 16,  4, ff_on2avc_tabs_20_84_2);
     648           0 :         twiddle(src + 224, &tmp0[128], 128, ff_on2avc_tab_84_1, 84, 4, 16,  4, ff_on2avc_tabs_20_84_1);
     649           0 :         twiddle(src + 256, &tmp0[256], 128, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     650           0 :         twiddle(src + 320, &tmp0[256], 128, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     651             : 
     652           0 :         wtf_end_512(c, out, src, tmp0, tmp1);
     653             :     } else {
     654           0 :         twiddle(src,       &tmp0[  0], 32, ff_on2avc_tab_20_1, 20, 2,  5,  4, ff_on2avc_tabs_9_20_1);
     655           0 :         twiddle(src +  16, &tmp0[  0], 32, ff_on2avc_tab_20_2, 20, 2,  4,  5, ff_on2avc_tabs_9_20_2);
     656           0 :         twiddle(src +  32, &tmp0[ 32], 32, ff_on2avc_tab_20_2, 20, 2,  4,  5, ff_on2avc_tabs_9_20_2);
     657           0 :         twiddle(src +  48, &tmp0[ 32], 32, ff_on2avc_tab_20_1, 20, 2,  5,  4, ff_on2avc_tabs_9_20_1);
     658           0 :         twiddle(src +  64, &tmp0[ 64], 32, ff_on2avc_tab_20_1, 20, 2,  5,  4, ff_on2avc_tabs_9_20_1);
     659           0 :         twiddle(src +  80, &tmp0[ 64], 32, ff_on2avc_tab_20_2, 20, 2,  4,  5, ff_on2avc_tabs_9_20_2);
     660           0 :         twiddle(src +  96, &tmp0[ 96], 32, ff_on2avc_tab_20_2, 20, 2,  4,  5, ff_on2avc_tabs_9_20_2);
     661           0 :         twiddle(src + 112, &tmp0[ 96], 32, ff_on2avc_tab_20_1, 20, 2,  5,  4, ff_on2avc_tabs_9_20_1);
     662           0 :         twiddle(&tmp0[ 0], &tmp1[  0], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     663           0 :         twiddle(&tmp0[32], &tmp1[  0], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     664           0 :         twiddle(&tmp0[64], &tmp1[ 64], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     665           0 :         twiddle(&tmp0[96], &tmp1[ 64], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     666           0 :         twiddle(src + 128, &tmp1[128], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     667           0 :         twiddle(src + 160, &tmp1[128], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     668           0 :         twiddle(src + 192, &tmp1[192], 64, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     669           0 :         twiddle(src + 224, &tmp1[192], 64, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     670             : 
     671           0 :         memset(tmp0, 0, 128 * sizeof(*tmp0));
     672             : 
     673           0 :         twiddle(&tmp1[  0], &tmp0[  0], 256, ff_on2avc_tab_84_1, 84, 4, 16,  4, ff_on2avc_tabs_20_84_1);
     674           0 :         twiddle(&tmp1[ 64], &tmp0[  0], 256, ff_on2avc_tab_84_2, 84, 4, 16,  4, ff_on2avc_tabs_20_84_2);
     675           0 :         twiddle(&tmp1[128], &tmp0[  0], 256, ff_on2avc_tab_84_3, 84, 4, 13,  7, ff_on2avc_tabs_20_84_3);
     676           0 :         twiddle(&tmp1[192], &tmp0[  0], 256, ff_on2avc_tab_84_4, 84, 4, 15,  5, ff_on2avc_tabs_20_84_4);
     677           0 :         twiddle(src + 256,  &tmp0[256], 256, ff_on2avc_tab_84_4, 84, 4, 15,  5, ff_on2avc_tabs_20_84_4);
     678           0 :         twiddle(src + 320,  &tmp0[256], 256, ff_on2avc_tab_84_3, 84, 4, 13,  7, ff_on2avc_tabs_20_84_3);
     679           0 :         twiddle(src + 384,  &tmp0[256], 256, ff_on2avc_tab_84_2, 84, 4, 16,  4, ff_on2avc_tabs_20_84_2);
     680           0 :         twiddle(src + 448,  &tmp0[256], 256, ff_on2avc_tab_84_1, 84, 4, 16,  4, ff_on2avc_tabs_20_84_1);
     681           0 :         twiddle(src + 512,  &tmp0[512], 256, ff_on2avc_tab_40_1, 40, 2, 11,  8, ff_on2avc_tabs_19_40_1);
     682           0 :         twiddle(src + 640,  &tmp0[512], 256, ff_on2avc_tab_40_2, 40, 2,  8, 11, ff_on2avc_tabs_19_40_2);
     683             : 
     684           0 :         wtf_end_1024(c, out, src, tmp0, tmp1);
     685             :     }
     686           0 : }
     687             : 
     688           0 : static int on2avc_reconstruct_channel_ext(On2AVCContext *c, AVFrame *dst, int offset)
     689             : {
     690             :     int ch, i;
     691             : 
     692           0 :     for (ch = 0; ch < c->avctx->channels; ch++) {
     693           0 :         float *out   = (float*)dst->extended_data[ch] + offset;
     694           0 :         float *in    = c->coeffs[ch];
     695           0 :         float *saved = c->delay[ch];
     696           0 :         float *buf   = c->mdct_buf;
     697           0 :         float *wout  = out + 448;
     698             : 
     699           0 :         switch (c->window_type) {
     700           0 :         case WINDOW_TYPE_EXT7:
     701           0 :             c->mdct.imdct_half(&c->mdct, buf, in);
     702           0 :             break;
     703           0 :         case WINDOW_TYPE_EXT4:
     704           0 :             c->wtf(c, buf, in, 1024);
     705           0 :             break;
     706           0 :         case WINDOW_TYPE_EXT5:
     707           0 :             c->wtf(c, buf, in, 512);
     708           0 :             c->mdct.imdct_half(&c->mdct_half, buf + 512, in + 512);
     709           0 :             for (i = 0; i < 256; i++) {
     710           0 :                 FFSWAP(float, buf[i + 512], buf[1023 - i]);
     711             :             }
     712           0 :             break;
     713           0 :         case WINDOW_TYPE_EXT6:
     714           0 :             c->mdct.imdct_half(&c->mdct_half, buf, in);
     715           0 :             for (i = 0; i < 256; i++) {
     716           0 :                 FFSWAP(float, buf[i], buf[511 - i]);
     717             :             }
     718           0 :             c->wtf(c, buf + 512, in + 512, 512);
     719           0 :             break;
     720             :         }
     721             : 
     722           0 :         memcpy(out, saved, 448 * sizeof(float));
     723           0 :         c->fdsp->vector_fmul_window(wout, saved + 448, buf, c->short_win, 64);
     724           0 :         memcpy(wout + 128,  buf + 64,         448 * sizeof(float));
     725           0 :         memcpy(saved,       buf + 512,        448 * sizeof(float));
     726           0 :         memcpy(saved + 448, buf + 7*128 + 64,  64 * sizeof(float));
     727             :     }
     728             : 
     729           0 :     return 0;
     730             : }
     731             : 
     732             : // not borrowed from aacdec.c - the codec has original design after all
     733          30 : static int on2avc_reconstruct_channel(On2AVCContext *c, int channel,
     734             :                                       AVFrame *dst, int offset)
     735             : {
     736             :     int i;
     737          30 :     float *out   = (float*)dst->extended_data[channel] + offset;
     738          30 :     float *in    = c->coeffs[channel];
     739          30 :     float *saved = c->delay[channel];
     740          30 :     float *buf   = c->mdct_buf;
     741          30 :     float *temp  = c->temp;
     742             : 
     743          30 :     switch (c->window_type) {
     744          30 :     case WINDOW_TYPE_LONG_START:
     745             :     case WINDOW_TYPE_LONG_STOP:
     746             :     case WINDOW_TYPE_LONG:
     747          30 :         c->mdct.imdct_half(&c->mdct, buf, in);
     748          30 :         break;
     749           0 :     case WINDOW_TYPE_8SHORT:
     750           0 :         for (i = 0; i < ON2AVC_SUBFRAME_SIZE; i += ON2AVC_SUBFRAME_SIZE / 8)
     751           0 :             c->mdct_small.imdct_half(&c->mdct_small, buf + i, in + i);
     752           0 :         break;
     753             :     }
     754             : 
     755          30 :     if ((c->prev_window_type == WINDOW_TYPE_LONG ||
     756          30 :          c->prev_window_type == WINDOW_TYPE_LONG_STOP) &&
     757          30 :         (c->window_type == WINDOW_TYPE_LONG ||
     758           0 :          c->window_type == WINDOW_TYPE_LONG_START)) {
     759          30 :         c->fdsp->vector_fmul_window(out, saved, buf, c->long_win, 512);
     760             :     } else {
     761           0 :         float *wout = out + 448;
     762           0 :         memcpy(out, saved, 448 * sizeof(float));
     763             : 
     764           0 :         if (c->window_type == WINDOW_TYPE_8SHORT) {
     765           0 :             c->fdsp->vector_fmul_window(wout + 0*128, saved + 448,      buf + 0*128, c->short_win, 64);
     766           0 :             c->fdsp->vector_fmul_window(wout + 1*128, buf + 0*128 + 64, buf + 1*128, c->short_win, 64);
     767           0 :             c->fdsp->vector_fmul_window(wout + 2*128, buf + 1*128 + 64, buf + 2*128, c->short_win, 64);
     768           0 :             c->fdsp->vector_fmul_window(wout + 3*128, buf + 2*128 + 64, buf + 3*128, c->short_win, 64);
     769           0 :             c->fdsp->vector_fmul_window(temp,         buf + 3*128 + 64, buf + 4*128, c->short_win, 64);
     770           0 :             memcpy(wout + 4*128, temp, 64 * sizeof(float));
     771             :         } else {
     772           0 :             c->fdsp->vector_fmul_window(wout, saved + 448, buf, c->short_win, 64);
     773           0 :             memcpy(wout + 128, buf + 64, 448 * sizeof(float));
     774             :         }
     775             :     }
     776             : 
     777             :     // buffer update
     778          30 :     switch (c->window_type) {
     779           0 :     case WINDOW_TYPE_8SHORT:
     780           0 :         memcpy(saved,       temp + 64,         64 * sizeof(float));
     781           0 :         c->fdsp->vector_fmul_window(saved + 64,  buf + 4*128 + 64, buf + 5*128, c->short_win, 64);
     782           0 :         c->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, c->short_win, 64);
     783           0 :         c->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, c->short_win, 64);
     784           0 :         memcpy(saved + 448, buf + 7*128 + 64,  64 * sizeof(float));
     785           0 :         break;
     786           0 :     case WINDOW_TYPE_LONG_START:
     787           0 :         memcpy(saved,       buf + 512,        448 * sizeof(float));
     788           0 :         memcpy(saved + 448, buf + 7*128 + 64,  64 * sizeof(float));
     789           0 :         break;
     790          30 :     case WINDOW_TYPE_LONG_STOP:
     791             :     case WINDOW_TYPE_LONG:
     792          30 :         memcpy(saved,       buf + 512,        512 * sizeof(float));
     793          30 :         break;
     794             :     }
     795          30 :     return 0;
     796             : }
     797             : 
     798          30 : static int on2avc_decode_subframe(On2AVCContext *c, const uint8_t *buf,
     799             :                                   int buf_size, AVFrame *dst, int offset)
     800             : {
     801             :     GetBitContext gb;
     802             :     int i, ret;
     803             : 
     804          30 :     if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
     805           0 :         return ret;
     806             : 
     807          30 :     if (get_bits1(&gb)) {
     808           0 :         av_log(c->avctx, AV_LOG_ERROR, "enh bit set\n");
     809           0 :         return AVERROR_INVALIDDATA;
     810             :     }
     811          30 :     c->prev_window_type = c->window_type;
     812          30 :     c->window_type      = get_bits(&gb, 3);
     813             : 
     814          30 :     c->band_start  = c->modes[c->window_type].band_start;
     815          30 :     c->num_windows = c->modes[c->window_type].num_windows;
     816          30 :     c->num_bands   = c->modes[c->window_type].num_bands;
     817          30 :     c->is_long     = (c->window_type != WINDOW_TYPE_8SHORT);
     818             : 
     819          30 :     c->grouping[0] = 1;
     820          30 :     for (i = 1; i < c->num_windows; i++)
     821           0 :         c->grouping[i] = !get_bits1(&gb);
     822             : 
     823          30 :     on2avc_read_ms_info(c, &gb);
     824          60 :     for (i = 0; i < c->avctx->channels; i++)
     825          30 :         if ((ret = on2avc_read_channel_data(c, &gb, i)) < 0)
     826           0 :             return AVERROR_INVALIDDATA;
     827          30 :     if (c->avctx->channels == 2 && c->ms_present)
     828           0 :         on2avc_apply_ms(c);
     829          30 :     if (c->window_type < WINDOW_TYPE_EXT4) {
     830          60 :         for (i = 0; i < c->avctx->channels; i++)
     831          30 :             on2avc_reconstruct_channel(c, i, dst, offset);
     832             :     } else {
     833           0 :         on2avc_reconstruct_channel_ext(c, dst, offset);
     834             :     }
     835             : 
     836          30 :     return 0;
     837             : }
     838             : 
     839          30 : static int on2avc_decode_frame(AVCodecContext * avctx, void *data,
     840             :                                int *got_frame_ptr, AVPacket *avpkt)
     841             : {
     842          30 :     AVFrame *frame     = data;
     843          30 :     const uint8_t *buf = avpkt->data;
     844          30 :     int buf_size       = avpkt->size;
     845          30 :     On2AVCContext *c   = avctx->priv_data;
     846             :     GetByteContext gb;
     847          30 :     int num_frames = 0, frame_size, audio_off;
     848             :     int ret;
     849             : 
     850          30 :     if (c->is_av500) {
     851             :         /* get output buffer */
     852          30 :         frame->nb_samples = ON2AVC_SUBFRAME_SIZE;
     853          30 :         if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
     854           0 :             return ret;
     855             : 
     856          30 :         if ((ret = on2avc_decode_subframe(c, buf, buf_size, frame, 0)) < 0)
     857           0 :             return ret;
     858             :     } else {
     859           0 :         bytestream2_init(&gb, buf, buf_size);
     860           0 :         while (bytestream2_get_bytes_left(&gb) > 2) {
     861           0 :             frame_size = bytestream2_get_le16(&gb);
     862           0 :             if (!frame_size || frame_size > bytestream2_get_bytes_left(&gb)) {
     863           0 :                 av_log(avctx, AV_LOG_ERROR, "Invalid subframe size %d\n",
     864             :                        frame_size);
     865           0 :                 return AVERROR_INVALIDDATA;
     866             :             }
     867           0 :             num_frames++;
     868           0 :             bytestream2_skip(&gb, frame_size);
     869             :         }
     870           0 :         if (!num_frames) {
     871           0 :             av_log(avctx, AV_LOG_ERROR, "No subframes present\n");
     872           0 :             return AVERROR_INVALIDDATA;
     873             :         }
     874             : 
     875             :         /* get output buffer */
     876           0 :         frame->nb_samples = ON2AVC_SUBFRAME_SIZE * num_frames;
     877           0 :         if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
     878           0 :             return ret;
     879             : 
     880           0 :         audio_off = 0;
     881           0 :         bytestream2_init(&gb, buf, buf_size);
     882           0 :         while (bytestream2_get_bytes_left(&gb) > 2) {
     883           0 :             frame_size = bytestream2_get_le16(&gb);
     884           0 :             if ((ret = on2avc_decode_subframe(c, gb.buffer, frame_size,
     885             :                                               frame, audio_off)) < 0)
     886           0 :                 return ret;
     887           0 :             audio_off += ON2AVC_SUBFRAME_SIZE;
     888           0 :             bytestream2_skip(&gb, frame_size);
     889             :         }
     890             :     }
     891             : 
     892          30 :     *got_frame_ptr = 1;
     893             : 
     894          30 :     return buf_size;
     895             : }
     896             : 
     897           3 : static av_cold void on2avc_free_vlcs(On2AVCContext *c)
     898             : {
     899             :     int i;
     900             : 
     901           3 :     ff_free_vlc(&c->scale_diff);
     902          48 :     for (i = 1; i < 16; i++)
     903          45 :         ff_free_vlc(&c->cb_vlc[i]);
     904           3 : }
     905             : 
     906           3 : static av_cold int on2avc_decode_init(AVCodecContext *avctx)
     907             : {
     908           3 :     On2AVCContext *c = avctx->priv_data;
     909             :     int i;
     910             : 
     911           3 :     if (avctx->channels > 2U) {
     912           0 :         avpriv_request_sample(avctx, "Decoding more than 2 channels");
     913           0 :         return AVERROR_PATCHWELCOME;
     914             :     }
     915             : 
     916           3 :     c->avctx = avctx;
     917           3 :     avctx->sample_fmt     = AV_SAMPLE_FMT_FLTP;
     918           6 :     avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
     919           3 :                                                    : AV_CH_LAYOUT_MONO;
     920             : 
     921           3 :     c->is_av500 = (avctx->codec_tag == 0x500);
     922             : 
     923           3 :     if (avctx->channels == 2)
     924           0 :         av_log(avctx, AV_LOG_WARNING,
     925             :                "Stereo mode support is not good, patch is welcome\n");
     926             : 
     927             :     // We add -0.01 before ceil() to avoid any values to fall at exactly the
     928             :     // midpoint between different ceil values. The results are identical to
     929             :     // using pow(10, i / 10.0) without such bias
     930          63 :     for (i = 0; i < 20; i++)
     931          60 :         c->scale_tab[i] = ceil(ff_exp10(i * 0.1) * 16 - 0.01) / 32;
     932         327 :     for (; i < 128; i++)
     933         324 :         c->scale_tab[i] = ceil(ff_exp10(i * 0.1) * 0.5 - 0.01);
     934             : 
     935           3 :     if (avctx->sample_rate < 32000 || avctx->channels == 1)
     936           3 :         memcpy(c->long_win, ff_on2avc_window_long_24000,
     937             :                1024 * sizeof(*c->long_win));
     938             :     else
     939           0 :         memcpy(c->long_win, ff_on2avc_window_long_32000,
     940             :                1024 * sizeof(*c->long_win));
     941           3 :     memcpy(c->short_win, ff_on2avc_window_short, 128 * sizeof(*c->short_win));
     942             : 
     943           6 :     c->modes = (avctx->sample_rate <= 40000) ? ff_on2avc_modes_40
     944           3 :                                              : ff_on2avc_modes_44;
     945           3 :     c->wtf   = (avctx->sample_rate <= 40000) ? wtf_40
     946             :                                              : wtf_44;
     947             : 
     948           3 :     ff_mdct_init(&c->mdct,       11, 1, 1.0 / (32768.0 * 1024.0));
     949           3 :     ff_mdct_init(&c->mdct_half,  10, 1, 1.0 / (32768.0 * 512.0));
     950           3 :     ff_mdct_init(&c->mdct_small,  8, 1, 1.0 / (32768.0 * 128.0));
     951           3 :     ff_fft_init(&c->fft128,  6, 0);
     952           3 :     ff_fft_init(&c->fft256,  7, 0);
     953           3 :     ff_fft_init(&c->fft512,  8, 1);
     954           3 :     ff_fft_init(&c->fft1024, 9, 1);
     955           3 :     c->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
     956           3 :     if (!c->fdsp)
     957           0 :         return AVERROR(ENOMEM);
     958             : 
     959           3 :     if (init_vlc(&c->scale_diff, 9, ON2AVC_SCALE_DIFFS,
     960             :                  ff_on2avc_scale_diff_bits,  1, 1,
     961             :                  ff_on2avc_scale_diff_codes, 4, 4, 0)) {
     962           0 :         goto vlc_fail;
     963             :     }
     964          27 :     for (i = 1; i < 9; i++) {
     965          24 :         int idx = i - 1;
     966          24 :         if (ff_init_vlc_sparse(&c->cb_vlc[i], 9, ff_on2avc_quad_cb_elems[idx],
     967          24 :                                ff_on2avc_quad_cb_bits[idx],  1, 1,
     968          24 :                                ff_on2avc_quad_cb_codes[idx], 4, 4,
     969          24 :                                ff_on2avc_quad_cb_syms[idx],  2, 2, 0)) {
     970           0 :             goto vlc_fail;
     971             :         }
     972             :     }
     973          24 :     for (i = 9; i < 16; i++) {
     974          21 :         int idx = i - 9;
     975          21 :         if (ff_init_vlc_sparse(&c->cb_vlc[i], 9, ff_on2avc_pair_cb_elems[idx],
     976          21 :                                ff_on2avc_pair_cb_bits[idx],  1, 1,
     977          21 :                                ff_on2avc_pair_cb_codes[idx], 2, 2,
     978          21 :                                ff_on2avc_pair_cb_syms[idx],  2, 2, 0)) {
     979           0 :             goto vlc_fail;
     980             :         }
     981             :     }
     982             : 
     983           3 :     return 0;
     984           0 : vlc_fail:
     985           0 :     av_log(avctx, AV_LOG_ERROR, "Cannot init VLC\n");
     986           0 :     on2avc_free_vlcs(c);
     987           0 :     av_freep(&c->fdsp);
     988           0 :     return AVERROR(ENOMEM);
     989             : }
     990             : 
     991           3 : static av_cold int on2avc_decode_close(AVCodecContext *avctx)
     992             : {
     993           3 :     On2AVCContext *c = avctx->priv_data;
     994             : 
     995           3 :     ff_mdct_end(&c->mdct);
     996           3 :     ff_mdct_end(&c->mdct_half);
     997           3 :     ff_mdct_end(&c->mdct_small);
     998           3 :     ff_fft_end(&c->fft128);
     999           3 :     ff_fft_end(&c->fft256);
    1000           3 :     ff_fft_end(&c->fft512);
    1001           3 :     ff_fft_end(&c->fft1024);
    1002             : 
    1003           3 :     av_freep(&c->fdsp);
    1004             : 
    1005           3 :     on2avc_free_vlcs(c);
    1006             : 
    1007           3 :     return 0;
    1008             : }
    1009             : 
    1010             : 
    1011             : AVCodec ff_on2avc_decoder = {
    1012             :     .name           = "on2avc",
    1013             :     .long_name      = NULL_IF_CONFIG_SMALL("On2 Audio for Video Codec"),
    1014             :     .type           = AVMEDIA_TYPE_AUDIO,
    1015             :     .id             = AV_CODEC_ID_ON2AVC,
    1016             :     .priv_data_size = sizeof(On2AVCContext),
    1017             :     .init           = on2avc_decode_init,
    1018             :     .decode         = on2avc_decode_frame,
    1019             :     .close          = on2avc_decode_close,
    1020             :     .capabilities   = AV_CODEC_CAP_DR1,
    1021             :     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
    1022             :                                                       AV_SAMPLE_FMT_NONE },
    1023             : };

Generated by: LCOV version 1.13