Directory: | ../../../ffmpeg/ |
---|---|
File: | src/libavcodec/aacpsdsp_template.c |
Date: | 2022-07-04 19:11:22 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 122 | 124 | 98.4% |
Branches: | 26 | 26 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | * | ||
20 | * Note: Rounding-to-nearest used unless otherwise stated | ||
21 | * | ||
22 | */ | ||
23 | #include <stdint.h> | ||
24 | |||
25 | #include "config.h" | ||
26 | #include "libavutil/attributes.h" | ||
27 | #include "aacpsdsp.h" | ||
28 | |||
29 | 116779 | static void ps_add_squares_c(INTFLOAT *dst, const INTFLOAT (*src)[2], int n) | |
30 | { | ||
31 | int i; | ||
32 |
2/2✓ Branch 0 taken 3749120 times.
✓ Branch 1 taken 116779 times.
|
3865899 | for (i = 0; i < n; i++) |
33 | 3749120 | dst[i] += (UINTFLOAT)AAC_MADD28(src[i][0], src[i][0], src[i][1], src[i][1]); | |
34 | 116779 | } | |
35 | |||
36 | 66259 | static void ps_mul_pair_single_c(INTFLOAT (*dst)[2], INTFLOAT (*src0)[2], INTFLOAT *src1, | |
37 | int n) | ||
38 | { | ||
39 | int i; | ||
40 |
2/2✓ Branch 0 taken 2132480 times.
✓ Branch 1 taken 66259 times.
|
2198739 | for (i = 0; i < n; i++) { |
41 | 2132480 | dst[i][0] = AAC_MUL16(src0[i][0], src1[i]); | |
42 | 2132480 | dst[i][1] = AAC_MUL16(src0[i][1], src1[i]); | |
43 | } | ||
44 | 66259 | } | |
45 | |||
46 | 64771 | static void ps_hybrid_analysis_c(INTFLOAT (*out)[2], INTFLOAT (*in)[2], | |
47 | const INTFLOAT (*filter)[8][2], | ||
48 | ptrdiff_t stride, int n) | ||
49 | { | ||
50 | int i, j; | ||
51 | |||
52 |
2/2✓ Branch 0 taken 492128 times.
✓ Branch 1 taken 64771 times.
|
556899 | for (i = 0; i < n; i++) { |
53 | 492128 | INT64FLOAT sum_re = (INT64FLOAT)filter[i][6][0] * in[6][0]; | |
54 | 492128 | INT64FLOAT sum_im = (INT64FLOAT)filter[i][6][0] * in[6][1]; | |
55 | |||
56 |
2/2✓ Branch 0 taken 2952768 times.
✓ Branch 1 taken 492128 times.
|
3444896 | for (j = 0; j < 6; j++) { |
57 | 2952768 | INT64FLOAT in0_re = in[j][0]; | |
58 | 2952768 | INT64FLOAT in0_im = in[j][1]; | |
59 | 2952768 | INT64FLOAT in1_re = in[12-j][0]; | |
60 | 2952768 | INT64FLOAT in1_im = in[12-j][1]; | |
61 | 2952768 | sum_re += (INT64FLOAT)filter[i][j][0] * (in0_re + in1_re) - | |
62 | 2952768 | (INT64FLOAT)filter[i][j][1] * (in0_im - in1_im); | |
63 | 2952768 | sum_im += (INT64FLOAT)filter[i][j][0] * (in0_im + in1_im) + | |
64 | 2952768 | (INT64FLOAT)filter[i][j][1] * (in0_re - in1_re); | |
65 | } | ||
66 | #if USE_FIXED | ||
67 | ✗ | out[i * stride][0] = (int)((sum_re + 0x40000000) >> 31); | |
68 | ✗ | out[i * stride][1] = (int)((sum_im + 0x40000000) >> 31); | |
69 | #else | ||
70 | 492128 | out[i * stride][0] = sum_re; | |
71 | 492128 | out[i * stride][1] = sum_im; | |
72 | #endif /* USE_FIXED */ | ||
73 | } | ||
74 | 64771 | } | |
75 | |||
76 | 1622 | static void ps_hybrid_analysis_ileave_c(INTFLOAT (*out)[32][2], INTFLOAT L[2][38][64], | |
77 | int i, int len) | ||
78 | { | ||
79 | int j; | ||
80 | |||
81 |
2/2✓ Branch 0 taken 98732 times.
✓ Branch 1 taken 1622 times.
|
100354 | for (; i < 64; i++) { |
82 |
2/2✓ Branch 0 taken 3159424 times.
✓ Branch 1 taken 98732 times.
|
3258156 | for (j = 0; j < len; j++) { |
83 | 3159424 | out[i][j][0] = L[0][j][i]; | |
84 | 3159424 | out[i][j][1] = L[1][j][i]; | |
85 | } | ||
86 | } | ||
87 | 1622 | } | |
88 | |||
89 | 3238 | static void ps_hybrid_synthesis_deint_c(INTFLOAT out[2][38][64], | |
90 | INTFLOAT (*in)[32][2], | ||
91 | int i, int len) | ||
92 | { | ||
93 | int n; | ||
94 | |||
95 |
2/2✓ Branch 0 taken 197104 times.
✓ Branch 1 taken 3238 times.
|
200342 | for (; i < 64; i++) { |
96 |
2/2✓ Branch 0 taken 6307328 times.
✓ Branch 1 taken 197104 times.
|
6504432 | for (n = 0; n < len; n++) { |
97 | 6307328 | out[0][n][i] = in[i][n][0]; | |
98 | 6307328 | out[1][n][i] = in[i][n][1]; | |
99 | } | ||
100 | } | ||
101 | 3238 | } | |
102 | |||
103 | 50520 | static void ps_decorrelate_c(INTFLOAT (*out)[2], INTFLOAT (*delay)[2], | |
104 | INTFLOAT (*ap_delay)[PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2], | ||
105 | const INTFLOAT phi_fract[2], const INTFLOAT (*Q_fract)[2], | ||
106 | const INTFLOAT *transient_gain, | ||
107 | INTFLOAT g_decay_slope, | ||
108 | int len) | ||
109 | { | ||
110 | static const INTFLOAT a[] = { Q31(0.65143905753106f), | ||
111 | Q31(0.56471812200776f), | ||
112 | Q31(0.48954165955695f) }; | ||
113 | INTFLOAT ag[PS_AP_LINKS]; | ||
114 | int m, n; | ||
115 | |||
116 |
2/2✓ Branch 0 taken 151560 times.
✓ Branch 1 taken 50520 times.
|
202080 | for (m = 0; m < PS_AP_LINKS; m++) |
117 | 151560 | ag[m] = AAC_MUL30(a[m], g_decay_slope); | |
118 | |||
119 |
2/2✓ Branch 0 taken 1616640 times.
✓ Branch 1 taken 50520 times.
|
1667160 | for (n = 0; n < len; n++) { |
120 | 1616640 | INTFLOAT in_re = AAC_MSUB30(delay[n][0], phi_fract[0], delay[n][1], phi_fract[1]); | |
121 | 1616640 | INTFLOAT in_im = AAC_MADD30(delay[n][0], phi_fract[1], delay[n][1], phi_fract[0]); | |
122 |
2/2✓ Branch 0 taken 4849920 times.
✓ Branch 1 taken 1616640 times.
|
6466560 | for (m = 0; m < PS_AP_LINKS; m++) { |
123 | 4849920 | INTFLOAT a_re = AAC_MUL31(ag[m], in_re); | |
124 | 4849920 | INTFLOAT a_im = AAC_MUL31(ag[m], in_im); | |
125 | 4849920 | INTFLOAT link_delay_re = ap_delay[m][n+2-m][0]; | |
126 | 4849920 | INTFLOAT link_delay_im = ap_delay[m][n+2-m][1]; | |
127 | 4849920 | INTFLOAT fractional_delay_re = Q_fract[m][0]; | |
128 | 4849920 | INTFLOAT fractional_delay_im = Q_fract[m][1]; | |
129 | 4849920 | INTFLOAT apd_re = in_re; | |
130 | 4849920 | INTFLOAT apd_im = in_im; | |
131 | 4849920 | in_re = AAC_MSUB30(link_delay_re, fractional_delay_re, | |
132 | link_delay_im, fractional_delay_im); | ||
133 | 4849920 | in_re -= (UINTFLOAT)a_re; | |
134 | 4849920 | in_im = AAC_MADD30(link_delay_re, fractional_delay_im, | |
135 | link_delay_im, fractional_delay_re); | ||
136 | 4849920 | in_im -= (UINTFLOAT)a_im; | |
137 | 4849920 | ap_delay[m][n+5][0] = apd_re + (UINTFLOAT)AAC_MUL31(ag[m], in_re); | |
138 | 4849920 | ap_delay[m][n+5][1] = apd_im + (UINTFLOAT)AAC_MUL31(ag[m], in_im); | |
139 | } | ||
140 | 1616640 | out[n][0] = AAC_MUL16(transient_gain[n], in_re); | |
141 | 1616640 | out[n][1] = AAC_MUL16(transient_gain[n], in_im); | |
142 | } | ||
143 | 50520 | } | |
144 | |||
145 | 141042 | static void ps_stereo_interpolate_c(INTFLOAT (*l)[2], INTFLOAT (*r)[2], | |
146 | INTFLOAT h[2][4], INTFLOAT h_step[2][4], | ||
147 | int len) | ||
148 | { | ||
149 | 141042 | INTFLOAT h0 = h[0][0]; | |
150 | 141042 | INTFLOAT h1 = h[0][1]; | |
151 | 141042 | INTFLOAT h2 = h[0][2]; | |
152 | 141042 | INTFLOAT h3 = h[0][3]; | |
153 | 141042 | UINTFLOAT hs0 = h_step[0][0]; | |
154 | 141042 | UINTFLOAT hs1 = h_step[0][1]; | |
155 | 141042 | UINTFLOAT hs2 = h_step[0][2]; | |
156 | 141042 | UINTFLOAT hs3 = h_step[0][3]; | |
157 | int n; | ||
158 | |||
159 |
2/2✓ Branch 0 taken 3628704 times.
✓ Branch 1 taken 141042 times.
|
3769746 | for (n = 0; n < len; n++) { |
160 | //l is s, r is d | ||
161 | 3628704 | INTFLOAT l_re = l[n][0]; | |
162 | 3628704 | INTFLOAT l_im = l[n][1]; | |
163 | 3628704 | INTFLOAT r_re = r[n][0]; | |
164 | 3628704 | INTFLOAT r_im = r[n][1]; | |
165 | 3628704 | h0 += hs0; | |
166 | 3628704 | h1 += hs1; | |
167 | 3628704 | h2 += hs2; | |
168 | 3628704 | h3 += hs3; | |
169 | 3628704 | l[n][0] = AAC_MADD30(h0, l_re, h2, r_re); | |
170 | 3628704 | l[n][1] = AAC_MADD30(h0, l_im, h2, r_im); | |
171 | 3628704 | r[n][0] = AAC_MADD30(h1, l_re, h3, r_re); | |
172 | 3628704 | r[n][1] = AAC_MADD30(h1, l_im, h3, r_im); | |
173 | } | ||
174 | 141042 | } | |
175 | |||
176 | 7387 | static void ps_stereo_interpolate_ipdopd_c(INTFLOAT (*l)[2], INTFLOAT (*r)[2], | |
177 | INTFLOAT h[2][4], INTFLOAT h_step[2][4], | ||
178 | int len) | ||
179 | { | ||
180 | 7387 | INTFLOAT h00 = h[0][0], h10 = h[1][0]; | |
181 | 7387 | INTFLOAT h01 = h[0][1], h11 = h[1][1]; | |
182 | 7387 | INTFLOAT h02 = h[0][2], h12 = h[1][2]; | |
183 | 7387 | INTFLOAT h03 = h[0][3], h13 = h[1][3]; | |
184 | 7387 | UINTFLOAT hs00 = h_step[0][0], hs10 = h_step[1][0]; | |
185 | 7387 | UINTFLOAT hs01 = h_step[0][1], hs11 = h_step[1][1]; | |
186 | 7387 | UINTFLOAT hs02 = h_step[0][2], hs12 = h_step[1][2]; | |
187 | 7387 | UINTFLOAT hs03 = h_step[0][3], hs13 = h_step[1][3]; | |
188 | int n; | ||
189 | |||
190 |
2/2✓ Branch 0 taken 132704 times.
✓ Branch 1 taken 7387 times.
|
140091 | for (n = 0; n < len; n++) { |
191 | //l is s, r is d | ||
192 | 132704 | INTFLOAT l_re = l[n][0]; | |
193 | 132704 | INTFLOAT l_im = l[n][1]; | |
194 | 132704 | INTFLOAT r_re = r[n][0]; | |
195 | 132704 | INTFLOAT r_im = r[n][1]; | |
196 | 132704 | h00 += hs00; | |
197 | 132704 | h01 += hs01; | |
198 | 132704 | h02 += hs02; | |
199 | 132704 | h03 += hs03; | |
200 | 132704 | h10 += hs10; | |
201 | 132704 | h11 += hs11; | |
202 | 132704 | h12 += hs12; | |
203 | 132704 | h13 += hs13; | |
204 | |||
205 | 132704 | l[n][0] = AAC_MSUB30_V8(h00, l_re, h02, r_re, h10, l_im, h12, r_im); | |
206 | 132704 | l[n][1] = AAC_MADD30_V8(h00, l_im, h02, r_im, h10, l_re, h12, r_re); | |
207 | 132704 | r[n][0] = AAC_MSUB30_V8(h01, l_re, h03, r_re, h11, l_im, h13, r_im); | |
208 | 132704 | r[n][1] = AAC_MADD30_V8(h01, l_im, h03, r_im, h11, l_re, h13, r_re); | |
209 | } | ||
210 | 7387 | } | |
211 | |||
212 | 373 | av_cold void AAC_RENAME(ff_psdsp_init)(PSDSPContext *s) | |
213 | { | ||
214 | 373 | s->add_squares = ps_add_squares_c; | |
215 | 373 | s->mul_pair_single = ps_mul_pair_single_c; | |
216 | 373 | s->hybrid_analysis = ps_hybrid_analysis_c; | |
217 | 373 | s->hybrid_analysis_ileave = ps_hybrid_analysis_ileave_c; | |
218 | 373 | s->hybrid_synthesis_deint = ps_hybrid_synthesis_deint_c; | |
219 | 373 | s->decorrelate = ps_decorrelate_c; | |
220 | 373 | s->stereo_interpolate[0] = ps_stereo_interpolate_c; | |
221 | 373 | s->stereo_interpolate[1] = ps_stereo_interpolate_ipdopd_c; | |
222 | |||
223 | #if !USE_FIXED | ||
224 | #if ARCH_ARM | ||
225 | ff_psdsp_init_arm(s); | ||
226 | #elif ARCH_AARCH64 | ||
227 | ff_psdsp_init_aarch64(s); | ||
228 | #elif ARCH_MIPS | ||
229 | ff_psdsp_init_mips(s); | ||
230 | #elif ARCH_X86 | ||
231 | 340 | ff_psdsp_init_x86(s); | |
232 | #endif | ||
233 | #endif /* !USE_FIXED */ | ||
234 | 373 | } | |
235 |