FFmpeg
aacdec_float_prediction.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_FLOAT_PREDICTION_H
33 #define AVCODEC_AAC_AACDEC_FLOAT_PREDICTION_H
34 
35 static av_always_inline float flt16_round(float pf)
36 {
37  union av_intfloat32 tmp;
38  tmp.f = pf;
39  tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U;
40  return tmp.f;
41 }
42 
43 static av_always_inline float flt16_even(float pf)
44 {
45  union av_intfloat32 tmp;
46  tmp.f = pf;
47  tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U >> 16)) & 0xFFFF0000U;
48  return tmp.f;
49 }
50 
51 static av_always_inline float flt16_trunc(float pf)
52 {
53  union av_intfloat32 pun;
54  pun.f = pf;
55  pun.i &= 0xFFFF0000U;
56  return pun.f;
57 }
58 
59 static av_always_inline void predict(PredictorState *ps, float *coef,
60  int output_enable)
61 {
62  const float a = 0.953125; // 61.0 / 64
63  const float alpha = 0.90625; // 29.0 / 32
64  float e0, e1;
65  float pv;
66  float k1, k2;
67  float r0 = ps->r0, r1 = ps->r1;
68  float cor0 = ps->cor0, cor1 = ps->cor1;
69  float var0 = ps->var0, var1 = ps->var1;
70 
71  k1 = var0 > 1 ? cor0 * flt16_even(a / var0) : 0;
72  k2 = var1 > 1 ? cor1 * flt16_even(a / var1) : 0;
73 
74  pv = flt16_round(k1 * r0 + k2 * r1);
75  if (output_enable)
76  *coef += pv;
77 
78  e0 = *coef;
79  e1 = e0 - k1 * r0;
80 
81  ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1);
82  ps->var1 = flt16_trunc(alpha * var1 + 0.5f * (r1 * r1 + e1 * e1));
83  ps->cor0 = flt16_trunc(alpha * cor0 + r0 * e0);
84  ps->var0 = flt16_trunc(alpha * var0 + 0.5f * (r0 * r0 + e0 * e0));
85 
86  ps->r1 = flt16_trunc(a * (r0 - k1 * e0));
87  ps->r0 = flt16_trunc(a * e0);
88 }
89 
91 {
92  ps->r0 = 0.0f;
93  ps->r1 = 0.0f;
94  ps->cor0 = 0.0f;
95  ps->cor1 = 0.0f;
96  ps->var0 = 1.0f;
97  ps->var1 = 1.0f;
98 }
99 
100 #endif /* AVCODEC_AAC_AACDEC_FLOAT_PREDICTION_H */
reset_predict_state
static av_always_inline void reset_predict_state(PredictorState *ps)
Definition: aacdec_float_prediction.h:90
flt16_trunc
static av_always_inline float flt16_trunc(float pf)
Definition: aacdec_float_prediction.h:51
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
av_intfloat32::i
uint32_t i
Definition: intfloat.h:28
predict
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
Definition: aacdec_float_prediction.h:59
PredictorState::var1
float var1
Definition: aac_defines.h:134
PredictorState::cor0
float cor0
Definition: aac_defines.h:131
PredictorState
Predictor State.
Definition: aac_defines.h:130
av_intfloat32
Definition: intfloat.h:27
flt16_round
static av_always_inline float flt16_round(float pf)
Definition: aacdec_float_prediction.h:35
f
f
Definition: af_crystalizer.c:121
flt16_even
static av_always_inline float flt16_even(float pf)
Definition: aacdec_float_prediction.h:43
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
av_always_inline
#define av_always_inline
Definition: attributes.h:49
PredictorState::r1
float r1
Definition: aac_defines.h:136
pv
#define pv
Definition: regdef.h:60
PredictorState::var0
float var0
Definition: aac_defines.h:133
U
#define U(x)
Definition: vpx_arith.h:37
PredictorState::r0
float r0
Definition: aac_defines.h:135
av_intfloat32::f
float f
Definition: intfloat.h:29
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
PredictorState::cor1
float cor1
Definition: aac_defines.h:132