FFmpeg
aacdec_fixed_dequant.h
Go to the documentation of this file.
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 {
39  int i, coef;
40 
41  for (i=0; i<len; i++) {
42  coef = coefs[i];
43  if (coef < 0)
44  coef = -(int)ff_cbrt_tab_fixed[(-coef) & 8191];
45  else
46  coef = (int)ff_cbrt_tab_fixed[ coef & 8191];
47  coefs[i] = coef;
48  }
49 }
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 {
60  int ssign = scale < 0 ? -1 : 1;
61  int s = FFABS(scale);
62  unsigned int round;
63  int i, out, c = exp2tab[s & 3];
64 
65  s = offset - (s >> 2);
66 
67  if (s > 31) {
68  for (i=0; i<len; i++) {
69  dst[i] = 0;
70  }
71  } else if (s > 0) {
72  round = 1 << (s-1);
73  for (i=0; i<len; i++) {
74  out = (int)(((int64_t)src[i] * c) >> 32);
75  dst[i] = ((int)(out+round) >> s) * ssign;
76  }
77  } else if (s > -32) {
78  s = s + 32;
79  round = 1U << (s-1);
80  for (i=0; i<len; i++) {
81  out = (int)((int64_t)((int64_t)src[i] * c + round) >> s);
82  dst[i] = out * (unsigned)ssign;
83  }
84  } else {
85  av_log(log_context, AV_LOG_ERROR, "Overflow in subband_scale()\n");
86  }
87 }
88 
89 static void noise_scale(int *coefs, int scale, int band_energy, int len)
90 {
91  int s = -scale;
92  unsigned int round;
93  int i, out, c = exp2tab[s & 3];
94  int nlz = 0;
95 
96  av_assert0(s >= 0);
97  while (band_energy > 0x7fff) {
98  band_energy >>= 1;
99  nlz++;
100  }
101  c /= band_energy;
102  s = 21 + nlz - (s >> 2);
103 
104  if (s > 31) {
105  for (i=0; i<len; i++) {
106  coefs[i] = 0;
107  }
108  } else if (s >= 0) {
109  round = s ? 1 << (s-1) : 0;
110  for (i=0; i<len; i++) {
111  out = (int)(((int64_t)coefs[i] * c) >> 32);
112  coefs[i] = -((int)(out+round) >> s);
113  }
114  }
115  else {
116  s = s + 32;
117  if (s > 0) {
118  round = 1 << (s-1);
119  for (i=0; i<len; i++) {
120  out = (int)((int64_t)((int64_t)coefs[i] * c + round) >> s);
121  coefs[i] = -out;
122  }
123  } else {
124  for (i=0; i<len; i++)
125  coefs[i] = -(int64_t)coefs[i] * c * (1 << -s);
126  }
127  }
128 }
129 
130 static inline int *DEC_SPAIR(int *dst, unsigned idx)
131 {
132  dst[0] = (idx & 15) - 4;
133  dst[1] = (idx >> 4 & 15) - 4;
134 
135  return dst + 2;
136 }
137 
138 static inline int *DEC_SQUAD(int *dst, unsigned idx)
139 {
140  dst[0] = (idx & 3) - 1;
141  dst[1] = (idx >> 2 & 3) - 1;
142  dst[2] = (idx >> 4 & 3) - 1;
143  dst[3] = (idx >> 6 & 3) - 1;
144 
145  return dst + 4;
146 }
147 
148 static inline int *DEC_UPAIR(int *dst, unsigned idx, unsigned sign)
149 {
150  dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE));
151  dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) * 2));
152 
153  return dst + 2;
154 }
155 
156 static inline int *DEC_UQUAD(int *dst, unsigned idx, unsigned sign)
157 {
158  unsigned nz = idx >> 12;
159 
160  dst[0] = (idx & 3) * (1 + (((int)sign >> 31) * 2));
161  sign <<= nz & 1;
162  nz >>= 1;
163  dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) * 2));
164  sign <<= nz & 1;
165  nz >>= 1;
166  dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) * 2));
167  sign <<= nz & 1;
168  nz >>= 1;
169  dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) * 2));
170 
171  return dst + 4;
172 }
173 
174 #endif /* AVCODEC_AAC_AACDEC_FIXED_DEQUANT_H */
exp2tab
static const int exp2tab[4]
Definition: aacdec_fixed_dequant.h:52
out
FILE * out
Definition: movenc.c:55
DEC_UQUAD
static int * DEC_UQUAD(int *dst, unsigned idx, unsigned sign)
Definition: aacdec_fixed_dequant.h:156
vector_pow43
static void vector_pow43(int *coefs, int len)
Definition: aacdec_fixed_dequant.h:37
DEC_SQUAD
static int * DEC_SQUAD(int *dst, unsigned idx)
Definition: aacdec_fixed_dequant.h:138
noise_scale
static void noise_scale(int *coefs, int scale, int band_energy, int len)
Definition: aacdec_fixed_dequant.h:89
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
ff_cbrt_tab_fixed
uint32_t ff_cbrt_tab_fixed[1<< 13]
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
DEC_UPAIR
static int * DEC_UPAIR(int *dst, unsigned idx, unsigned sign)
Definition: aacdec_fixed_dequant.h:148
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
subband_scale
static void subband_scale(int *dst, int *src, int scale, int offset, int len, void *log_context)
Definition: aacdec_fixed_dequant.h:57
DEC_SPAIR
static int * DEC_SPAIR(int *dst, unsigned idx)
Definition: aacdec_fixed_dequant.h:130
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
len
int len
Definition: vorbis_enc_data.h:426
U
#define U(x)
Definition: vpx_arith.h:37
aacdec_tab.h
Q31
#define Q31(x)
Definition: aac_defines.h:111
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
int
int
Definition: ffmpeg_filter.c:424