Coverage Report

Created: 2025-12-31 07:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/aac/aacdec_fixed_dequant.h
Line
Count
Source
1
/*
2
 * AAC decoder
3
 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
4
 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
5
 * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com>
6
 *
7
 * AAC LATM decoder
8
 * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
9
 * Copyright (c) 2010      Janne Grunau <janne-libav@jannau.net>
10
 *
11
 * AAC decoder fixed-point implementation
12
 * Copyright (c) 2013
13
 *      MIPS Technologies, Inc., California.
14
 *
15
 * This file is part of FFmpeg.
16
 *
17
 * FFmpeg is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU Lesser General Public
19
 * License as published by the Free Software Foundation; either
20
 * version 2.1 of the License, or (at your option) any later version.
21
 *
22
 * FFmpeg is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25
 * Lesser General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Lesser General Public
28
 * License along with FFmpeg; if not, write to the Free Software
29
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30
 */
31
32
#ifndef AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H
33
#define AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H
34
35
#include "aacdec_tab.h"
36
37
static void inline vector_pow43(int *coefs, int len)
38
2.74M
{
39
2.74M
    int i, coef;
40
41
20.3M
    for (i=0; i<len; i++) {
42
17.6M
        coef = coefs[i];
43
17.6M
        if (coef < 0)
44
597k
            coef = -(int)ff_cbrt_tab_fixed[(-coef) & 8191];
45
17.0M
        else
46
17.0M
            coef =  (int)ff_cbrt_tab_fixed[  coef  & 8191];
47
17.6M
        coefs[i] = coef;
48
17.6M
    }
49
2.74M
}
50
51
/* 2^0, 2^0.25, 2^0.5, 2^0.75 */
52
static const int exp2tab[4] = {
53
    Q31(1.0000000000/2), Q31(1.1892071150/2),
54
    Q31(1.4142135624/2), Q31(1.6817928305/2)
55
};
56
57
static void inline subband_scale(int *dst, int *src, int scale,
58
                                 int offset, int len, void *log_context)
59
2.99M
{
60
2.99M
    int ssign = scale < 0 ? -1 : 1;
61
2.99M
    int s = FFABS(scale);
62
2.99M
    unsigned int round;
63
2.99M
    int i, out, c = exp2tab[s & 3];
64
65
2.99M
    s = offset - (s >> 2);
66
67
2.99M
    if (s > 31) {
68
10.2M
        for (i=0; i<len; i++) {
69
8.21M
            dst[i] = 0;
70
8.21M
        }
71
2.04M
    } else if (s > 0) {
72
463k
        round = 1 << (s-1);
73
6.22M
        for (i=0; i<len; i++) {
74
5.76M
            out = (int)(((int64_t)src[i] * c) >> 32);
75
5.76M
            dst[i] = ((int)(out+round) >> s) * ssign;
76
5.76M
        }
77
486k
    } else if (s > -32) {
78
486k
        s = s + 32;
79
486k
        round = 1U << (s-1);
80
6.51M
        for (i=0; i<len; i++) {
81
6.02M
            out = (int)((int64_t)((int64_t)src[i] * c + round) >> s);
82
6.02M
            dst[i] = out * (unsigned)ssign;
83
6.02M
        }
84
486k
    } else {
85
180
        av_log(log_context, AV_LOG_ERROR, "Overflow in subband_scale()\n");
86
180
    }
87
2.99M
}
88
89
static void noise_scale(int *coefs, int scale, int band_energy, int len)
90
4.14M
{
91
4.14M
    int s = -scale;
92
4.14M
    unsigned int round;
93
4.14M
    int i, out, c = exp2tab[s & 3];
94
4.14M
    int nlz = 0;
95
96
4.14M
    av_assert0(s >= 0);
97
62.9M
    while (band_energy > 0x7fff) {
98
58.8M
        band_energy >>= 1;
99
58.8M
        nlz++;
100
58.8M
    }
101
4.14M
    c /= band_energy;
102
4.14M
    s = 21 + nlz - (s >> 2);
103
104
4.14M
    if (s > 31) {
105
4.47M
        for (i=0; i<len; i++) {
106
4.27M
            coefs[i] = 0;
107
4.27M
        }
108
3.95M
    } else if (s >= 0) {
109
402k
        round = s ? 1 << (s-1) : 0;
110
4.65M
        for (i=0; i<len; i++) {
111
4.25M
            out = (int)(((int64_t)coefs[i] * c) >> 32);
112
4.25M
            coefs[i] = -((int)(out+round) >> s);
113
4.25M
        }
114
402k
    }
115
3.54M
    else {
116
3.54M
        s = s + 32;
117
3.54M
        if (s > 0) {
118
3.54M
            round = 1 << (s-1);
119
38.1M
            for (i=0; i<len; i++) {
120
34.6M
                out = (int)((int64_t)((int64_t)coefs[i] * c + round) >> s);
121
34.6M
                coefs[i] = -out;
122
34.6M
            }
123
3.54M
        } else {
124
1.02k
            for (i=0; i<len; i++)
125
816
                coefs[i] = -(int64_t)coefs[i] * c * (1 << -s);
126
204
        }
127
3.54M
    }
128
4.14M
}
129
130
static inline int *DEC_SPAIR(int *dst, unsigned idx)
131
227k
{
132
227k
    dst[0] = (idx & 15) - 4;
133
227k
    dst[1] = (idx >> 4 & 15) - 4;
134
135
227k
    return dst + 2;
136
227k
}
137
138
static inline int *DEC_SQUAD(int *dst, unsigned idx)
139
182k
{
140
182k
    dst[0] = (idx & 3) - 1;
141
182k
    dst[1] = (idx >> 2 & 3) - 1;
142
182k
    dst[2] = (idx >> 4 & 3) - 1;
143
182k
    dst[3] = (idx >> 6 & 3) - 1;
144
145
182k
    return dst + 4;
146
182k
}
147
148
static inline int *DEC_UPAIR(int *dst, unsigned idx, unsigned sign)
149
7.36M
{
150
7.36M
    dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE));
151
7.36M
    dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) * 2));
152
153
7.36M
    return dst + 2;
154
7.36M
}
155
156
static inline int *DEC_UQUAD(int *dst, unsigned idx, unsigned sign)
157
375k
{
158
375k
    unsigned nz = idx >> 12;
159
160
375k
    dst[0] = (idx & 3) * (1 + (((int)sign >> 31) * 2));
161
375k
    sign <<= nz & 1;
162
375k
    nz >>= 1;
163
375k
    dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) * 2));
164
375k
    sign <<= nz & 1;
165
375k
    nz >>= 1;
166
375k
    dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) * 2));
167
375k
    sign <<= nz & 1;
168
375k
    nz >>= 1;
169
375k
    dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) * 2));
170
171
375k
    return dst + 4;
172
375k
}
173
174
#endif /* AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H */