FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac/aacdec_float_prediction.h
Date: 2024-07-16 12:46:59
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 4047936 static av_always_inline float flt16_round(float pf)
36 {
37 union av_intfloat32 tmp;
38 4047936 tmp.f = pf;
39 4047936 tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U;
40 4047936 return tmp.f;
41 }
42
43 5085872 static av_always_inline float flt16_even(float pf)
44 {
45 union av_intfloat32 tmp;
46 5085872 tmp.f = pf;
47 5085872 tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U >> 16)) & 0xFFFF0000U;
48 5085872 return tmp.f;
49 }
50
51 24287616 static av_always_inline float flt16_trunc(float pf)
52 {
53 union av_intfloat32 pun;
54 24287616 pun.f = pf;
55 24287616 pun.i &= 0xFFFF0000U;
56 24287616 return pun.f;
57 }
58
59 4047936 static av_always_inline void predict(PredictorState *ps, float *coef,
60 int output_enable)
61 {
62 4047936 const float a = 0.953125; // 61.0 / 64
63 4047936 const float alpha = 0.90625; // 29.0 / 32
64 float e0, e1;
65 float pv;
66 float k1, k2;
67 4047936 float r0 = ps->r0, r1 = ps->r1;
68 4047936 float cor0 = ps->cor0, cor1 = ps->cor1;
69 4047936 float var0 = ps->var0, var1 = ps->var1;
70
71
2/2
✓ Branch 0 taken 2542772 times.
✓ Branch 1 taken 1505164 times.
4047936 k1 = var0 > 1 ? cor0 * flt16_even(a / var0) : 0;
72
2/2
✓ Branch 0 taken 2543100 times.
✓ Branch 1 taken 1504836 times.
4047936 k2 = var1 > 1 ? cor1 * flt16_even(a / var1) : 0;
73
74 4047936 pv = flt16_round(k1 * r0 + k2 * r1);
75
2/2
✓ Branch 0 taken 271896 times.
✓ Branch 1 taken 3776040 times.
4047936 if (output_enable)
76 271896 *coef += pv;
77
78 4047936 e0 = *coef;
79 4047936 e1 = e0 - k1 * r0;
80
81 4047936 ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1);
82 4047936 ps->var1 = flt16_trunc(alpha * var1 + 0.5f * (r1 * r1 + e1 * e1));
83 4047936 ps->cor0 = flt16_trunc(alpha * cor0 + r0 * e0);
84 4047936 ps->var0 = flt16_trunc(alpha * var0 + 0.5f * (r0 * r0 + e0 * e0));
85
86 4047936 ps->r1 = flt16_trunc(a * (r0 - k1 * e0));
87 4047936 ps->r0 = flt16_trunc(a * e0);
88 4047936 }
89
90 38542 static av_always_inline void reset_predict_state(PredictorState *ps)
91 {
92 38542 ps->r0 = 0.0f;
93 38542 ps->r1 = 0.0f;
94 38542 ps->cor0 = 0.0f;
95 38542 ps->cor1 = 0.0f;
96 38542 ps->var0 = 1.0f;
97 38542 ps->var1 = 1.0f;
98 38542 }
99
100 #endif /* AVCODEC_AAC_AACDEC_FLOAT_PREDICTION_H */
101