/src/ffmpeg/libavcodec/lpc_functions.h
Line | Count | Source |
1 | | /* |
2 | | * LPC utility functions |
3 | | * Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com> |
4 | | * |
5 | | * This file is part of FFmpeg. |
6 | | * |
7 | | * FFmpeg is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * FFmpeg is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public |
18 | | * License along with FFmpeg; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | | */ |
21 | | |
22 | | #ifndef AVCODEC_LPC_FUNCTIONS_H |
23 | | #define AVCODEC_LPC_FUNCTIONS_H |
24 | | |
25 | | #include "libavutil/avassert.h" |
26 | | |
27 | | #ifndef LPC_USE_FIXED |
28 | 0 | #define LPC_USE_FIXED 0 |
29 | | #endif |
30 | | |
31 | | #if LPC_USE_FIXED |
32 | | typedef int LPC_TYPE; |
33 | | typedef unsigned LPC_TYPE_U; |
34 | | #else |
35 | | #ifndef LPC_SRA_R |
36 | 347M | #define LPC_SRA_R(x, y) (x) |
37 | 7.06G | #define LPC_MUL26(x, y) ((x) * (y)) |
38 | 347M | #define LPC_FIXR(x) ((float)(x)) |
39 | | #endif |
40 | | |
41 | | #ifdef LPC_USE_DOUBLE |
42 | | typedef double LPC_TYPE; |
43 | | typedef double LPC_TYPE_U; |
44 | | #else |
45 | | typedef float LPC_TYPE; |
46 | | typedef float LPC_TYPE_U; |
47 | | #endif |
48 | | #endif // USE_FIXED |
49 | | |
50 | | /** |
51 | | * Levinson-Durbin recursion. |
52 | | * Produce LPC coefficients from autocorrelation data. |
53 | | */ |
54 | | static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int i, int max_order, |
55 | | LPC_TYPE *lpc, int lpc_stride, int fail, |
56 | | int normalize, LPC_TYPE *err_ptr) |
57 | 16.9M | { |
58 | 16.9M | LPC_TYPE err = 0; |
59 | 16.9M | LPC_TYPE *lpc_last = lpc; |
60 | | |
61 | 16.9M | av_assert2(normalize || !fail); |
62 | | |
63 | 16.9M | if (normalize) { |
64 | 16.9M | if (i == 0) |
65 | 12.3M | err = *autoc++; |
66 | 4.59M | else { |
67 | 4.59M | err = *err_ptr; |
68 | 4.59M | } |
69 | 16.9M | } |
70 | | |
71 | 16.9M | if (fail && (autoc[max_order - 1] == 0 || err <= 0)) |
72 | 1.28k | return -1; |
73 | | |
74 | 365M | for( ; i < max_order; i++) { |
75 | 348M | LPC_TYPE r = LPC_SRA_R(-autoc[i], 5); |
76 | | |
77 | 348M | if (normalize) { |
78 | 7.24G | for(int j = 0; j < i; j++) |
79 | 6.89G | r -= lpc_last[j] * autoc[i-j-1]; |
80 | | |
81 | 347M | if (err) |
82 | 347M | r /= err; |
83 | 347M | err *= LPC_FIXR(1.0) - (r * r); |
84 | 347M | } |
85 | | |
86 | 348M | lpc[i] = r; |
87 | | |
88 | 3.88G | for(int j = 0; j < (i + 1) >> 1; j++) { |
89 | 3.53G | LPC_TYPE f = lpc_last[ j]; |
90 | 3.53G | LPC_TYPE b = lpc_last[i-1-j]; |
91 | 3.53G | lpc[ j] = f + (LPC_TYPE_U)LPC_MUL26(r, b); |
92 | 3.53G | lpc[i-1-j] = b + (LPC_TYPE_U)LPC_MUL26(r, f); |
93 | 3.53G | } |
94 | | |
95 | 348M | if (fail && err < 0) |
96 | 0 | return -1; |
97 | | |
98 | 348M | lpc_last = lpc; |
99 | 348M | lpc += lpc_stride; |
100 | 348M | } |
101 | | |
102 | 16.9M | if (err_ptr) |
103 | 13.7M | *err_ptr = err; |
104 | | |
105 | 16.9M | return 0; |
106 | 16.9M | } Unexecuted instantiation: lpc.c:compute_lpc_coefs Unexecuted instantiation: aacenc_tns.c:compute_lpc_coefs aacdec_fixed.c:compute_lpc_coefs Line | Count | Source | 57 | 19.1k | { | 58 | 19.1k | LPC_TYPE err = 0; | 59 | 19.1k | LPC_TYPE *lpc_last = lpc; | 60 | | | 61 | 19.1k | av_assert2(normalize || !fail); | 62 | | | 63 | 19.1k | if (normalize) { | 64 | 0 | if (i == 0) | 65 | 0 | err = *autoc++; | 66 | 0 | else { | 67 | 0 | err = *err_ptr; | 68 | 0 | } | 69 | 0 | } | 70 | | | 71 | 19.1k | if (fail && (autoc[max_order - 1] == 0 || err <= 0)) | 72 | 0 | return -1; | 73 | | | 74 | 128k | for( ; i < max_order; i++) { | 75 | 109k | LPC_TYPE r = LPC_SRA_R(-autoc[i], 5); | 76 | | | 77 | 109k | if (normalize) { | 78 | 0 | for(int j = 0; j < i; j++) | 79 | 0 | r -= lpc_last[j] * autoc[i-j-1]; | 80 | |
| 81 | 0 | if (err) | 82 | 0 | r /= err; | 83 | 0 | err *= LPC_FIXR(1.0) - (r * r); | 84 | 0 | } | 85 | | | 86 | 109k | lpc[i] = r; | 87 | | | 88 | 362k | for(int j = 0; j < (i + 1) >> 1; j++) { | 89 | 253k | LPC_TYPE f = lpc_last[ j]; | 90 | 253k | LPC_TYPE b = lpc_last[i-1-j]; | 91 | 253k | lpc[ j] = f + (LPC_TYPE_U)LPC_MUL26(r, b); | 92 | 253k | lpc[i-1-j] = b + (LPC_TYPE_U)LPC_MUL26(r, f); | 93 | 253k | } | 94 | | | 95 | 109k | if (fail && err < 0) | 96 | 0 | return -1; | 97 | | | 98 | 109k | lpc_last = lpc; | 99 | 109k | lpc += lpc_stride; | 100 | 109k | } | 101 | | | 102 | 19.1k | if (err_ptr) | 103 | 0 | *err_ptr = err; | 104 | | | 105 | 19.1k | return 0; | 106 | 19.1k | } |
aacdec_float.c:compute_lpc_coefs Line | Count | Source | 57 | 37.8k | { | 58 | 37.8k | LPC_TYPE err = 0; | 59 | 37.8k | LPC_TYPE *lpc_last = lpc; | 60 | | | 61 | 37.8k | av_assert2(normalize || !fail); | 62 | | | 63 | 37.8k | if (normalize) { | 64 | 0 | if (i == 0) | 65 | 0 | err = *autoc++; | 66 | 0 | else { | 67 | 0 | err = *err_ptr; | 68 | 0 | } | 69 | 0 | } | 70 | | | 71 | 37.8k | if (fail && (autoc[max_order - 1] == 0 || err <= 0)) | 72 | 0 | return -1; | 73 | | | 74 | 251k | for( ; i < max_order; i++) { | 75 | 213k | LPC_TYPE r = LPC_SRA_R(-autoc[i], 5); | 76 | | | 77 | 213k | if (normalize) { | 78 | 0 | for(int j = 0; j < i; j++) | 79 | 0 | r -= lpc_last[j] * autoc[i-j-1]; | 80 | |
| 81 | 0 | if (err) | 82 | 0 | r /= err; | 83 | 0 | err *= LPC_FIXR(1.0) - (r * r); | 84 | 0 | } | 85 | | | 86 | 213k | lpc[i] = r; | 87 | | | 88 | 605k | for(int j = 0; j < (i + 1) >> 1; j++) { | 89 | 392k | LPC_TYPE f = lpc_last[ j]; | 90 | 392k | LPC_TYPE b = lpc_last[i-1-j]; | 91 | 392k | lpc[ j] = f + (LPC_TYPE_U)LPC_MUL26(r, b); | 92 | 392k | lpc[i-1-j] = b + (LPC_TYPE_U)LPC_MUL26(r, f); | 93 | 392k | } | 94 | | | 95 | 213k | if (fail && err < 0) | 96 | 0 | return -1; | 97 | | | 98 | 213k | lpc_last = lpc; | 99 | 213k | lpc += lpc_stride; | 100 | 213k | } | 101 | | | 102 | 37.8k | if (err_ptr) | 103 | 0 | *err_ptr = err; | 104 | | | 105 | 37.8k | return 0; | 106 | 37.8k | } |
ra288.c:compute_lpc_coefs Line | Count | Source | 57 | 3.12M | { | 58 | 3.12M | LPC_TYPE err = 0; | 59 | 3.12M | LPC_TYPE *lpc_last = lpc; | 60 | | | 61 | 3.12M | av_assert2(normalize || !fail); | 62 | | | 63 | 3.12M | if (normalize) { | 64 | 3.12M | if (i == 0) | 65 | 3.12M | err = *autoc++; | 66 | 0 | else { | 67 | 0 | err = *err_ptr; | 68 | 0 | } | 69 | 3.12M | } | 70 | | | 71 | 3.12M | if (fail && (autoc[max_order - 1] == 0 || err <= 0)) | 72 | 1.28k | return -1; | 73 | | | 74 | 74.9M | for( ; i < max_order; i++) { | 75 | 71.7M | LPC_TYPE r = LPC_SRA_R(-autoc[i], 5); | 76 | | | 77 | 71.7M | if (normalize) { | 78 | 1.12G | for(int j = 0; j < i; j++) | 79 | 1.05G | r -= lpc_last[j] * autoc[i-j-1]; | 80 | | | 81 | 71.7M | if (err) | 82 | 71.7M | r /= err; | 83 | 71.7M | err *= LPC_FIXR(1.0) - (r * r); | 84 | 71.7M | } | 85 | | | 86 | 71.7M | lpc[i] = r; | 87 | | | 88 | 616M | for(int j = 0; j < (i + 1) >> 1; j++) { | 89 | 544M | LPC_TYPE f = lpc_last[ j]; | 90 | 544M | LPC_TYPE b = lpc_last[i-1-j]; | 91 | 544M | lpc[ j] = f + (LPC_TYPE_U)LPC_MUL26(r, b); | 92 | 544M | lpc[i-1-j] = b + (LPC_TYPE_U)LPC_MUL26(r, f); | 93 | 544M | } | 94 | | | 95 | 71.7M | if (fail && err < 0) | 96 | 0 | return -1; | 97 | | | 98 | 71.7M | lpc_last = lpc; | 99 | 71.7M | lpc += lpc_stride; | 100 | 71.7M | } | 101 | | | 102 | 3.12M | if (err_ptr) | 103 | 0 | *err_ptr = err; | 104 | | | 105 | 3.12M | return 0; | 106 | 3.12M | } |
g728dec.c:compute_lpc_coefs Line | Count | Source | 57 | 13.7M | { | 58 | 13.7M | LPC_TYPE err = 0; | 59 | 13.7M | LPC_TYPE *lpc_last = lpc; | 60 | | | 61 | 13.7M | av_assert2(normalize || !fail); | 62 | | | 63 | 13.7M | if (normalize) { | 64 | 13.7M | if (i == 0) | 65 | 9.20M | err = *autoc++; | 66 | 4.59M | else { | 67 | 4.59M | err = *err_ptr; | 68 | 4.59M | } | 69 | 13.7M | } | 70 | | | 71 | 13.7M | if (fail && (autoc[max_order - 1] == 0 || err <= 0)) | 72 | 0 | return -1; | 73 | | | 74 | 289M | for( ; i < max_order; i++) { | 75 | 275M | LPC_TYPE r = LPC_SRA_R(-autoc[i], 5); | 76 | | | 77 | 275M | if (normalize) { | 78 | 6.11G | for(int j = 0; j < i; j++) | 79 | 5.84G | r -= lpc_last[j] * autoc[i-j-1]; | 80 | | | 81 | 275M | if (err) | 82 | 275M | r /= err; | 83 | 275M | err *= LPC_FIXR(1.0) - (r * r); | 84 | 275M | } | 85 | | | 86 | 275M | lpc[i] = r; | 87 | | | 88 | 3.26G | for(int j = 0; j < (i + 1) >> 1; j++) { | 89 | 2.98G | LPC_TYPE f = lpc_last[ j]; | 90 | 2.98G | LPC_TYPE b = lpc_last[i-1-j]; | 91 | 2.98G | lpc[ j] = f + (LPC_TYPE_U)LPC_MUL26(r, b); | 92 | 2.98G | lpc[i-1-j] = b + (LPC_TYPE_U)LPC_MUL26(r, f); | 93 | 2.98G | } | 94 | | | 95 | 275M | if (fail && err < 0) | 96 | 0 | return -1; | 97 | | | 98 | 275M | lpc_last = lpc; | 99 | 275M | lpc += lpc_stride; | 100 | 275M | } | 101 | | | 102 | 13.7M | if (err_ptr) | 103 | 13.7M | *err_ptr = err; | 104 | | | 105 | 13.7M | return 0; | 106 | 13.7M | } |
|
107 | | |
108 | | #endif /* AVCODEC_LPC_FUNCTIONS_H */ |