FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac/aacdec_float_prediction.h
Date: 2025-03-23 22:11:24
Exec Total Coverage
Lines: 40 40 100.0%
Functions: 5 5 100.0%
Branches: 6 6 100.0%

Line Branch Exec 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_FLOAT_PREDICTION_H
33 #define AVCODEC_AAC_AACDEC_FLOAT_PREDICTION_H
34
35 3506976 static av_always_inline float flt16_round(float pf)
36 {
37 union av_intfloat32 tmp;
38 3506976 tmp.f = pf;
39 3506976 tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U;
40 3506976 return tmp.f;
41 }
42
43 4145212 static av_always_inline float flt16_even(float pf)
44 {
45 union av_intfloat32 tmp;
46 4145212 tmp.f = pf;
47 4145212 tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U >> 16)) & 0xFFFF0000U;
48 4145212 return tmp.f;
49 }
50
51 21041856 static av_always_inline float flt16_trunc(float pf)
52 {
53 union av_intfloat32 pun;
54 21041856 pun.f = pf;
55 21041856 pun.i &= 0xFFFF0000U;
56 21041856 return pun.f;
57 }
58
59 3506976 static av_always_inline void predict(PredictorState *ps, float *coef,
60 int output_enable)
61 {
62 3506976 const float a = 0.953125; // 61.0 / 64
63 3506976 const float alpha = 0.90625; // 29.0 / 32
64 float e0, e1;
65 float pv;
66 float k1, k2;
67 3506976 float r0 = ps->r0, r1 = ps->r1;
68 3506976 float cor0 = ps->cor0, cor1 = ps->cor1;
69 3506976 float var0 = ps->var0, var1 = ps->var1;
70
71
2/2
✓ Branch 0 taken 2072442 times.
✓ Branch 1 taken 1434534 times.
3506976 k1 = var0 > 1 ? cor0 * flt16_even(a / var0) : 0;
72
2/2
✓ Branch 0 taken 2072770 times.
✓ Branch 1 taken 1434206 times.
3506976 k2 = var1 > 1 ? cor1 * flt16_even(a / var1) : 0;
73
74 3506976 pv = flt16_round(k1 * r0 + k2 * r1);
75
2/2
✓ Branch 0 taken 181324 times.
✓ Branch 1 taken 3325652 times.
3506976 if (output_enable)
76 181324 *coef += pv;
77
78 3506976 e0 = *coef;
79 3506976 e1 = e0 - k1 * r0;
80
81 3506976 ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1);
82 3506976 ps->var1 = flt16_trunc(alpha * var1 + 0.5f * (r1 * r1 + e1 * e1));
83 3506976 ps->cor0 = flt16_trunc(alpha * cor0 + r0 * e0);
84 3506976 ps->var0 = flt16_trunc(alpha * var0 + 0.5f * (r0 * r0 + e0 * e0));
85
86 3506976 ps->r1 = flt16_trunc(a * (r0 - k1 * e0));
87 3506976 ps->r0 = flt16_trunc(a * e0);
88 3506976 }
89
90 16924 static av_always_inline void reset_predict_state(PredictorState *ps)
91 {
92 16924 ps->r0 = 0.0f;
93 16924 ps->r1 = 0.0f;
94 16924 ps->cor0 = 0.0f;
95 16924 ps->cor1 = 0.0f;
96 16924 ps->var0 = 1.0f;
97 16924 ps->var1 = 1.0f;
98 16924 }
99
100 #endif /* AVCODEC_AAC_AACDEC_FLOAT_PREDICTION_H */
101