FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/opus_pvq.c
Date: 2023-12-04 05:51:44
Exec Total Coverage
Lines: 398 500 79.6%
Functions: 20 28 71.4%
Branches: 262 346 75.7%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2007-2008 CSIRO
3 * Copyright (c) 2007-2009 Xiph.Org Foundation
4 * Copyright (c) 2008-2009 Gregory Maxwell
5 * Copyright (c) 2012 Andrew D'Addesio
6 * Copyright (c) 2013-2014 Mozilla Corporation
7 * Copyright (c) 2017 Rostislav Pehlivanov <atomnuker@gmail.com>
8 *
9 * This file is part of FFmpeg.
10 *
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #include <float.h>
27
28 #include "config_components.h"
29
30 #include "mathops.h"
31 #include "opustab.h"
32 #include "opus_pvq.h"
33
34 #define ROUND_MUL16(a,b) ((MUL16(a, b) + 16384) >> 15)
35
36 #define CELT_PVQ_U(n, k) (ff_celt_pvq_u_row[FFMIN(n, k)][FFMAX(n, k)])
37 #define CELT_PVQ_V(n, k) (CELT_PVQ_U(n, k) + CELT_PVQ_U(n, (k) + 1))
38
39 1039102 static inline int16_t celt_cos(int16_t x)
40 {
41 1039102 x = (MUL16(x, x) + 4096) >> 13;
42 1039102 x = (32767-x) + ROUND_MUL16(x, (-7651 + ROUND_MUL16(x, (8277 + ROUND_MUL16(-626, x)))));
43 1039102 return x + 1;
44 }
45
46 519551 static inline int celt_log2tan(int isin, int icos)
47 {
48 int lc, ls;
49 519551 lc = opus_ilog(icos);
50 519551 ls = opus_ilog(isin);
51 519551 icos <<= 15 - lc;
52 519551 isin <<= 15 - ls;
53 519551 return (ls << 11) - (lc << 11) +
54 1039102 ROUND_MUL16(isin, ROUND_MUL16(isin, -2597) + 7932) -
55 519551 ROUND_MUL16(icos, ROUND_MUL16(icos, -2597) + 7932);
56 }
57
58 1007694 static inline int celt_bits2pulses(const uint8_t *cache, int bits)
59 {
60 // TODO: Find the size of cache and make it into an array in the parameters list
61 1007694 int i, low = 0, high;
62
63 1007694 high = cache[0];
64 1007694 bits--;
65
66
2/2
✓ Branch 0 taken 6046164 times.
✓ Branch 1 taken 1007694 times.
7053858 for (i = 0; i < 6; i++) {
67 6046164 int center = (low + high + 1) >> 1;
68
2/2
✓ Branch 0 taken 3424102 times.
✓ Branch 1 taken 2622062 times.
6046164 if (cache[center] >= bits)
69 3424102 high = center;
70 else
71 2622062 low = center;
72 }
73
74
4/4
✓ Branch 0 taken 861380 times.
✓ Branch 1 taken 146314 times.
✓ Branch 2 taken 408572 times.
✓ Branch 3 taken 599122 times.
1007694 return (bits - (low == 0 ? -1 : cache[low]) <= cache[high] - bits) ? low : high;
75 }
76
77 1019453 static inline int celt_pulses2bits(const uint8_t *cache, int pulses)
78 {
79 // TODO: Find the size of cache and make it into an array in the parameters list
80
2/2
✓ Branch 0 taken 880651 times.
✓ Branch 1 taken 138802 times.
1019453 return (pulses == 0) ? 0 : cache[pulses] + 1;
81 }
82
83 868892 static inline void celt_normalize_residual(const int * av_restrict iy, float * av_restrict X,
84 int N, float g)
85 {
86 int i;
87
2/2
✓ Branch 0 taken 7350932 times.
✓ Branch 1 taken 868892 times.
8219824 for (i = 0; i < N; i++)
88 7350932 X[i] = g * iy[i];
89 868892 }
90
91 376059 static void celt_exp_rotation_impl(float *X, uint32_t len, uint32_t stride,
92 float c, float s)
93 {
94 float *Xptr;
95 int i;
96
97 376059 Xptr = X;
98
2/2
✓ Branch 0 taken 5067813 times.
✓ Branch 1 taken 376059 times.
5443872 for (i = 0; i < len - stride; i++) {
99 5067813 float x1 = Xptr[0];
100 5067813 float x2 = Xptr[stride];
101 5067813 Xptr[stride] = c * x2 + s * x1;
102 5067813 *Xptr++ = c * x1 - s * x2;
103 }
104
105 376059 Xptr = &X[len - 2 * stride - 1];
106
2/2
✓ Branch 0 taken 4223222 times.
✓ Branch 1 taken 376059 times.
4599281 for (i = len - 2 * stride - 1; i >= 0; i--) {
107 4223222 float x1 = Xptr[0];
108 4223222 float x2 = Xptr[stride];
109 4223222 Xptr[stride] = c * x2 + s * x1;
110 4223222 *Xptr-- = c * x1 - s * x2;
111 }
112 376059 }
113
114 868892 static inline void celt_exp_rotation(float *X, uint32_t len,
115 uint32_t stride, uint32_t K,
116 enum CeltSpread spread, const int encode)
117 {
118 868892 uint32_t stride2 = 0;
119 float c, s;
120 float gain, theta;
121 int i;
122
123
4/4
✓ Branch 0 taken 169420 times.
✓ Branch 1 taken 699472 times.
✓ Branch 2 taken 5544 times.
✓ Branch 3 taken 163876 times.
868892 if (2*K >= len || spread == CELT_SPREAD_NONE)
124 705016 return;
125
126 163876 gain = (float)len / (len + (20 - 5*spread) * K);
127 163876 theta = M_PI * gain * gain / 4;
128
129 163876 c = cosf(theta);
130 163876 s = sinf(theta);
131
132
2/2
✓ Branch 0 taken 139366 times.
✓ Branch 1 taken 24510 times.
163876 if (len >= stride << 3) {
133 139366 stride2 = 1;
134 /* This is just a simple (equivalent) way of computing sqrt(len/stride) with rounding.
135 It's basically incrementing long as (stride2+0.5)^2 < len/stride. */
136
2/2
✓ Branch 0 taken 452565 times.
✓ Branch 1 taken 139366 times.
591931 while ((stride2 * stride2 + stride2) * stride + (stride >> 2) < len)
137 452565 stride2++;
138 }
139
140 163876 len /= stride;
141
2/2
✓ Branch 0 taken 221705 times.
✓ Branch 1 taken 163876 times.
385581 for (i = 0; i < stride; i++) {
142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 221705 times.
221705 if (encode) {
143 celt_exp_rotation_impl(X + i * len, len, 1, c, -s);
144 if (stride2)
145 celt_exp_rotation_impl(X + i * len, len, stride2, s, -c);
146 } else {
147
2/2
✓ Branch 0 taken 154354 times.
✓ Branch 1 taken 67351 times.
221705 if (stride2)
148 154354 celt_exp_rotation_impl(X + i * len, len, stride2, s, c);
149 221705 celt_exp_rotation_impl(X + i * len, len, 1, c, s);
150 }
151 }
152 }
153
154 868892 static inline uint32_t celt_extract_collapse_mask(const int *iy, uint32_t N, uint32_t B)
155 {
156 868892 int i, j, N0 = N / B;
157 868892 uint32_t collapse_mask = 0;
158
159
2/2
✓ Branch 0 taken 742013 times.
✓ Branch 1 taken 126879 times.
868892 if (B <= 1)
160 742013 return 1;
161
162
2/2
✓ Branch 0 taken 408468 times.
✓ Branch 1 taken 126879 times.
535347 for (i = 0; i < B; i++)
163
2/2
✓ Branch 0 taken 1118808 times.
✓ Branch 1 taken 408468 times.
1527276 for (j = 0; j < N0; j++)
164 1118808 collapse_mask |= (!!iy[i*N0+j]) << i;
165 126879 return collapse_mask;
166 }
167
168 186299 static inline void celt_stereo_merge(float *X, float *Y, float mid, int N)
169 {
170 int i;
171 186299 float xp = 0, side = 0;
172 float E[2];
173 float mid2;
174 float gain[2];
175
176 /* Compute the norm of X+Y and X-Y as |X|^2 + |Y|^2 +/- sum(xy) */
177
2/2
✓ Branch 0 taken 4294876 times.
✓ Branch 1 taken 186299 times.
4481175 for (i = 0; i < N; i++) {
178 4294876 xp += X[i] * Y[i];
179 4294876 side += Y[i] * Y[i];
180 }
181
182 /* Compensating for the mid normalization */
183 186299 xp *= mid;
184 186299 mid2 = mid;
185 186299 E[0] = mid2 * mid2 + side - 2 * xp;
186 186299 E[1] = mid2 * mid2 + side + 2 * xp;
187
4/4
✓ Branch 0 taken 186227 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 186143 times.
186299 if (E[0] < 6e-4f || E[1] < 6e-4f) {
188
2/2
✓ Branch 0 taken 998 times.
✓ Branch 1 taken 156 times.
1154 for (i = 0; i < N; i++)
189 998 Y[i] = X[i];
190 156 return;
191 }
192
193 186143 gain[0] = 1.0f / sqrtf(E[0]);
194 186143 gain[1] = 1.0f / sqrtf(E[1]);
195
196
2/2
✓ Branch 0 taken 4293878 times.
✓ Branch 1 taken 186143 times.
4480021 for (i = 0; i < N; i++) {
197 float value[2];
198 /* Apply mid scaling (side is already scaled) */
199 4293878 value[0] = mid * X[i];
200 4293878 value[1] = Y[i];
201 4293878 X[i] = gain[0] * (value[0] - value[1]);
202 4293878 Y[i] = gain[1] * (value[0] + value[1]);
203 }
204 }
205
206 140404 static void celt_interleave_hadamard(float *tmp, float *X, int N0,
207 int stride, int hadamard)
208 {
209 140404 int i, j, N = N0*stride;
210
2/2
✓ Branch 0 taken 76152 times.
✓ Branch 1 taken 64252 times.
140404 const uint8_t *order = &ff_celt_hadamard_order[hadamard ? stride - 2 : 30];
211
212
2/2
✓ Branch 0 taken 747146 times.
✓ Branch 1 taken 140404 times.
887550 for (i = 0; i < stride; i++)
213
2/2
✓ Branch 0 taken 3664528 times.
✓ Branch 1 taken 747146 times.
4411674 for (j = 0; j < N0; j++)
214 3664528 tmp[j*stride+i] = X[order[i]*N0+j];
215
216 140404 memcpy(X, tmp, N*sizeof(float));
217 140404 }
218
219 91020 static void celt_deinterleave_hadamard(float *tmp, float *X, int N0,
220 int stride, int hadamard)
221 {
222 91020 int i, j, N = N0*stride;
223
2/2
✓ Branch 0 taken 50902 times.
✓ Branch 1 taken 40118 times.
91020 const uint8_t *order = &ff_celt_hadamard_order[hadamard ? stride - 2 : 30];
224
225
2/2
✓ Branch 0 taken 467136 times.
✓ Branch 1 taken 91020 times.
558156 for (i = 0; i < stride; i++)
226
2/2
✓ Branch 0 taken 2285770 times.
✓ Branch 1 taken 467136 times.
2752906 for (j = 0; j < N0; j++)
227 2285770 tmp[order[i]*N0+j] = X[j*stride+i];
228
229 91020 memcpy(X, tmp, N*sizeof(float));
230 91020 }
231
232 356997 static void celt_haar1(float *X, int N0, int stride)
233 {
234 int i, j;
235 356997 N0 >>= 1;
236
2/2
✓ Branch 0 taken 676243 times.
✓ Branch 1 taken 356997 times.
1033240 for (i = 0; i < stride; i++) {
237
2/2
✓ Branch 0 taken 5132312 times.
✓ Branch 1 taken 676243 times.
5808555 for (j = 0; j < N0; j++) {
238 5132312 float x0 = X[stride * (2 * j + 0) + i];
239 5132312 float x1 = X[stride * (2 * j + 1) + i];
240 5132312 X[stride * (2 * j + 0) + i] = (x0 + x1) * M_SQRT1_2;
241 5132312 X[stride * (2 * j + 1) + i] = (x0 - x1) * M_SQRT1_2;
242 }
243 }
244 356997 }
245
246 575935 static inline int celt_compute_qn(int N, int b, int offset, int pulse_cap,
247 int stereo)
248 {
249 int qn, qb;
250 575935 int N2 = 2 * N - 1;
251
4/4
✓ Branch 0 taken 188735 times.
✓ Branch 1 taken 387200 times.
✓ Branch 2 taken 48661 times.
✓ Branch 3 taken 140074 times.
575935 if (stereo && N == 2)
252 48661 N2--;
253
254 /* The upper limit ensures that in a stereo split with itheta==16384, we'll
255 * always have enough bits left over to code at least one pulse in the
256 * side; otherwise it would collapse, since it doesn't get folded. */
257 575935 qb = FFMIN3(b - pulse_cap - (4 << 3), (b + N2 * offset) / N2, 8 << 3);
258
2/2
✓ Branch 0 taken 574220 times.
✓ Branch 1 taken 1715 times.
575935 qn = (qb < (1 << 3 >> 1)) ? 1 : ((ff_celt_qn_exp2[qb & 0x7] >> (14 - (qb >> 3))) + 1) >> 1 << 1;
259 575935 return qn;
260 }
261
262 /* Convert the quantized vector to an index */
263 static inline uint32_t celt_icwrsi(uint32_t N, uint32_t K, const int *y)
264 {
265 int i, idx = 0, sum = 0;
266 for (i = N - 1; i >= 0; i--) {
267 const uint32_t i_s = CELT_PVQ_U(N - i, sum + FFABS(y[i]) + 1);
268 idx += CELT_PVQ_U(N - i, sum) + (y[i] < 0)*i_s;
269 sum += FFABS(y[i]);
270 }
271 return idx;
272 }
273
274 // this code was adapted from libopus
275 868892 static inline uint64_t celt_cwrsi(uint32_t N, uint32_t K, uint32_t i, int *y)
276 {
277 868892 uint64_t norm = 0;
278 uint32_t q, p;
279 int s, val;
280 int k0;
281
282
2/2
✓ Branch 0 taken 5613148 times.
✓ Branch 1 taken 868892 times.
6482040 while (N > 2) {
283 /*Lots of pulses case:*/
284
2/2
✓ Branch 0 taken 1668292 times.
✓ Branch 1 taken 3944856 times.
5613148 if (K >= N) {
285 1668292 const uint32_t *row = ff_celt_pvq_u_row[N];
286
287 /* Are the pulses in this dimension negative? */
288 1668292 p = row[K + 1];
289 1668292 s = -(i >= p);
290 1668292 i -= p & s;
291
292 /*Count how many pulses were placed in this dimension.*/
293 1668292 k0 = K;
294 1668292 q = row[N];
295
2/2
✓ Branch 0 taken 269151 times.
✓ Branch 1 taken 1399141 times.
1668292 if (q > i) {
296 269151 K = N;
297 do {
298 387560 p = ff_celt_pvq_u_row[--K][N];
299
2/2
✓ Branch 0 taken 118409 times.
✓ Branch 1 taken 269151 times.
387560 } while (p > i);
300 } else
301
2/2
✓ Branch 0 taken 7353979 times.
✓ Branch 1 taken 1399141 times.
8753120 for (p = row[K]; p > i; p = row[K])
302 7353979 K--;
303
304 1668292 i -= p;
305 1668292 val = (k0 - K + s) ^ s;
306 1668292 norm += val * val;
307 1668292 *y++ = val;
308 } else { /*Lots of dimensions case:*/
309 /*Are there any pulses in this dimension at all?*/
310 3944856 p = ff_celt_pvq_u_row[K ][N];
311 3944856 q = ff_celt_pvq_u_row[K + 1][N];
312
313
4/4
✓ Branch 0 taken 3392797 times.
✓ Branch 1 taken 552059 times.
✓ Branch 2 taken 2840145 times.
✓ Branch 3 taken 552652 times.
3944856 if (p <= i && i < q) {
314 2840145 i -= p;
315 2840145 *y++ = 0;
316 } else {
317 /*Are the pulses in this dimension negative?*/
318 1104711 s = -(i >= q);
319 1104711 i -= q & s;
320
321 /*Count how many pulses were placed in this dimension.*/
322 1104711 k0 = K;
323 1286305 do p = ff_celt_pvq_u_row[--K][N];
324
2/2
✓ Branch 0 taken 181594 times.
✓ Branch 1 taken 1104711 times.
1286305 while (p > i);
325
326 1104711 i -= p;
327 1104711 val = (k0 - K + s) ^ s;
328 1104711 norm += val * val;
329 1104711 *y++ = val;
330 }
331 }
332 5613148 N--;
333 }
334
335 /* N == 2 */
336 868892 p = 2 * K + 1;
337 868892 s = -(i >= p);
338 868892 i -= p & s;
339 868892 k0 = K;
340 868892 K = (i + 1) / 2;
341
342
2/2
✓ Branch 0 taken 612521 times.
✓ Branch 1 taken 256371 times.
868892 if (K)
343 612521 i -= 2 * K - 1;
344
345 868892 val = (k0 - K + s) ^ s;
346 868892 norm += val * val;
347 868892 *y++ = val;
348
349 /* N==1 */
350 868892 s = -i;
351 868892 val = (K + s) ^ s;
352 868892 norm += val * val;
353 868892 *y = val;
354
355 868892 return norm;
356 }
357
358 static inline void celt_encode_pulses(OpusRangeCoder *rc, int *y, uint32_t N, uint32_t K)
359 {
360 ff_opus_rc_enc_uint(rc, celt_icwrsi(N, K, y), CELT_PVQ_V(N, K));
361 }
362
363 868892 static inline float celt_decode_pulses(OpusRangeCoder *rc, int *y, uint32_t N, uint32_t K)
364 {
365
4/4
✓ Branch 0 taken 313633 times.
✓ Branch 1 taken 555259 times.
✓ Branch 2 taken 281486 times.
✓ Branch 3 taken 587406 times.
868892 const uint32_t idx = ff_opus_rc_dec_uint(rc, CELT_PVQ_V(N, K));
366 868892 return celt_cwrsi(N, K, idx, y);
367 }
368
369 #if CONFIG_OPUS_ENCODER
370 /*
371 * Faster than libopus's search, operates entirely in the signed domain.
372 * Slightly worse/better depending on N, K and the input vector.
373 */
374 static float ppp_pvq_search_c(float *X, int *y, int K, int N)
375 {
376 int i, y_norm = 0;
377 float res = 0.0f, xy_norm = 0.0f;
378
379 for (i = 0; i < N; i++)
380 res += FFABS(X[i]);
381
382 res = K/(res + FLT_EPSILON);
383
384 for (i = 0; i < N; i++) {
385 y[i] = lrintf(res*X[i]);
386 y_norm += y[i]*y[i];
387 xy_norm += y[i]*X[i];
388 K -= FFABS(y[i]);
389 }
390
391 while (K) {
392 int max_idx = 0, phase = FFSIGN(K);
393 float max_num = 0.0f;
394 float max_den = 1.0f;
395 y_norm += 1.0f;
396
397 for (i = 0; i < N; i++) {
398 /* If the sum has been overshot and the best place has 0 pulses allocated
399 * to it, attempting to decrease it further will actually increase the
400 * sum. Prevent this by disregarding any 0 positions when decrementing. */
401 const int ca = 1 ^ ((y[i] == 0) & (phase < 0));
402 const int y_new = y_norm + 2*phase*FFABS(y[i]);
403 float xy_new = xy_norm + 1*phase*FFABS(X[i]);
404 xy_new = xy_new * xy_new;
405 if (ca && (max_den*xy_new) > (y_new*max_num)) {
406 max_den = y_new;
407 max_num = xy_new;
408 max_idx = i;
409 }
410 }
411
412 K -= phase;
413
414 phase *= FFSIGN(X[max_idx]);
415 xy_norm += 1*phase*X[max_idx];
416 y_norm += 2*phase*y[max_idx];
417 y[max_idx] += phase;
418 }
419
420 return (float)y_norm;
421 }
422 #endif
423
424 static uint32_t celt_alg_quant(OpusRangeCoder *rc, float *X, uint32_t N, uint32_t K,
425 enum CeltSpread spread, uint32_t blocks, float gain,
426 CeltPVQ *pvq)
427 {
428 int *y = pvq->qcoeff;
429
430 celt_exp_rotation(X, N, blocks, K, spread, 1);
431 gain /= sqrtf(pvq->pvq_search(X, y, K, N));
432 celt_encode_pulses(rc, y, N, K);
433 celt_normalize_residual(y, X, N, gain);
434 celt_exp_rotation(X, N, blocks, K, spread, 0);
435 return celt_extract_collapse_mask(y, N, blocks);
436 }
437
438 /** Decode pulse vector and combine the result with the pitch vector to produce
439 the final normalised signal in the current band. */
440 868892 static uint32_t celt_alg_unquant(OpusRangeCoder *rc, float *X, uint32_t N, uint32_t K,
441 enum CeltSpread spread, uint32_t blocks, float gain,
442 CeltPVQ *pvq)
443 {
444 868892 int *y = pvq->qcoeff;
445
446 868892 gain /= sqrtf(celt_decode_pulses(rc, y, N, K));
447 868892 celt_normalize_residual(y, X, N, gain);
448 868892 celt_exp_rotation(X, N, blocks, K, spread, 0);
449 868892 return celt_extract_collapse_mask(y, N, blocks);
450 }
451
452 static int celt_calc_theta(const float *X, const float *Y, int coupling, int N)
453 {
454 int i;
455 float e[2] = { 0.0f, 0.0f };
456 if (coupling) { /* Coupling case */
457 for (i = 0; i < N; i++) {
458 e[0] += (X[i] + Y[i])*(X[i] + Y[i]);
459 e[1] += (X[i] - Y[i])*(X[i] - Y[i]);
460 }
461 } else {
462 for (i = 0; i < N; i++) {
463 e[0] += X[i]*X[i];
464 e[1] += Y[i]*Y[i];
465 }
466 }
467 return lrintf(32768.0f*atan2f(sqrtf(e[1]), sqrtf(e[0]))/M_PI);
468 }
469
470 static void celt_stereo_is_decouple(float *X, float *Y, float e_l, float e_r, int N)
471 {
472 int i;
473 const float energy_n = 1.0f/(sqrtf(e_l*e_l + e_r*e_r) + FLT_EPSILON);
474 e_l *= energy_n;
475 e_r *= energy_n;
476 for (i = 0; i < N; i++)
477 X[i] = e_l*X[i] + e_r*Y[i];
478 }
479
480 static void celt_stereo_ms_decouple(float *X, float *Y, int N)
481 {
482 int i;
483 for (i = 0; i < N; i++) {
484 const float Xret = X[i];
485 X[i] = (X[i] + Y[i])*M_SQRT1_2;
486 Y[i] = (Y[i] - Xret)*M_SQRT1_2;
487 }
488 }
489
490 1745036 static av_always_inline uint32_t quant_band_template(CeltPVQ *pvq, CeltFrame *f,
491 OpusRangeCoder *rc,
492 const int band, float *X,
493 float *Y, int N, int b,
494 uint32_t blocks, float *lowband,
495 int duration, float *lowband_out,
496 int level, float gain,
497 float *lowband_scratch,
498 int fill, int quant)
499 {
500 int i;
501 const uint8_t *cache;
502 1745036 int stereo = !!Y, split = stereo;
503 1745036 int imid = 0, iside = 0;
504 1745036 uint32_t N0 = N;
505 1745036 int N_B = N / blocks;
506 1745036 int N_B0 = N_B;
507 1745036 int B0 = blocks;
508 1745036 int time_divide = 0;
509 1745036 int recombine = 0;
510 1745036 int inv = 0;
511 1745036 float mid = 0, side = 0;
512 1745036 int longblocks = (B0 == 1);
513 1745036 uint32_t cm = 0;
514
515
2/2
✓ Branch 0 taken 109648 times.
✓ Branch 1 taken 1635388 times.
1745036 if (N == 1) {
516 109648 float *x = X;
517
2/2
✓ Branch 0 taken 176024 times.
✓ Branch 1 taken 109648 times.
285672 for (i = 0; i <= stereo; i++) {
518 176024 int sign = 0;
519
2/2
✓ Branch 0 taken 169213 times.
✓ Branch 1 taken 6811 times.
176024 if (f->remaining2 >= 1 << 3) {
520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 169213 times.
169213 if (quant) {
521 sign = x[0] < 0;
522 ff_opus_rc_put_raw(rc, sign, 1);
523 } else {
524 169213 sign = ff_opus_rc_get_raw(rc, 1);
525 }
526 169213 f->remaining2 -= 1 << 3;
527 }
528 176024 x[0] = 1.0f - 2.0f*sign;
529 176024 x = Y;
530 }
531
1/2
✓ Branch 0 taken 109648 times.
✗ Branch 1 not taken.
109648 if (lowband_out)
532 109648 lowband_out[0] = X[0];
533 109648 return 1;
534 }
535
536
4/4
✓ Branch 0 taken 1394894 times.
✓ Branch 1 taken 240494 times.
✓ Branch 2 taken 620494 times.
✓ Branch 3 taken 774400 times.
1635388 if (!stereo && level == 0) {
537 620494 int tf_change = f->tf_change[band];
538 int k;
539
2/2
✓ Branch 0 taken 40217 times.
✓ Branch 1 taken 580277 times.
620494 if (tf_change > 0)
540 40217 recombine = tf_change;
541 /* Band recombining to increase frequency resolution */
542
543
4/4
✓ Branch 0 taken 371425 times.
✓ Branch 1 taken 249069 times.
✓ Branch 2 taken 345583 times.
✓ Branch 3 taken 25842 times.
620494 if (lowband &&
544
6/6
✓ Branch 0 taken 334650 times.
✓ Branch 1 taken 10933 times.
✓ Branch 2 taken 275618 times.
✓ Branch 3 taken 59032 times.
✓ Branch 4 taken 23601 times.
✓ Branch 5 taken 262950 times.
345583 (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) {
545
2/2
✓ Branch 0 taken 2682290 times.
✓ Branch 1 taken 108475 times.
2790765 for (i = 0; i < N; i++)
546 2682290 lowband_scratch[i] = lowband[i];
547 108475 lowband = lowband_scratch;
548 }
549
550
2/2
✓ Branch 0 taken 67800 times.
✓ Branch 1 taken 620494 times.
688294 for (k = 0; k < recombine; k++) {
551
3/4
✓ Branch 0 taken 67800 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42647 times.
✓ Branch 3 taken 25153 times.
67800 if (quant || lowband)
552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42647 times.
42647 celt_haar1(quant ? X : lowband, N >> k, 1 << k);
553 67800 fill = ff_celt_bit_interleave[fill & 0xF] | ff_celt_bit_interleave[fill >> 4] << 2;
554 }
555 620494 blocks >>= recombine;
556 620494 N_B <<= recombine;
557
558 /* Increasing the time resolution */
559
4/4
✓ Branch 0 taken 719652 times.
✓ Branch 1 taken 50519 times.
✓ Branch 2 taken 149677 times.
✓ Branch 3 taken 569975 times.
770171 while ((N_B & 1) == 0 && tf_change < 0) {
560
3/4
✓ Branch 0 taken 149677 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96873 times.
✓ Branch 3 taken 52804 times.
149677 if (quant || lowband)
561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96873 times.
96873 celt_haar1(quant ? X : lowband, N_B, blocks);
562 149677 fill |= fill << blocks;
563 149677 blocks <<= 1;
564 149677 N_B >>= 1;
565 149677 time_divide++;
566 149677 tf_change++;
567 }
568 620494 B0 = blocks;
569 620494 N_B0 = N_B;
570
571 /* Reorganize the samples in time order instead of frequency order */
572
5/6
✓ Branch 0 taken 140404 times.
✓ Branch 1 taken 480090 times.
✓ Branch 2 taken 140404 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 91020 times.
✓ Branch 5 taken 49384 times.
620494 if (B0 > 1 && (quant || lowband))
573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 91020 times.
91020 celt_deinterleave_hadamard(pvq->hadamard_tmp, quant ? X : lowband,
574 N_B >> recombine, B0 << recombine,
575 longblocks);
576 }
577
578 /* If we need 1.5 more bit than we can produce, split the band in two. */
579 1635388 cache = ff_celt_cache_bits +
580 1635388 ff_celt_cache_index[(duration + 1) * CELT_MAX_BANDS + band];
581
8/8
✓ Branch 0 taken 1394894 times.
✓ Branch 1 taken 240494 times.
✓ Branch 2 taken 1195112 times.
✓ Branch 3 taken 199782 times.
✓ Branch 4 taken 441684 times.
✓ Branch 5 taken 753428 times.
✓ Branch 6 taken 387200 times.
✓ Branch 7 taken 54484 times.
1635388 if (!stereo && duration >= 0 && b > cache[cache[0]] + 12 && N > 2) {
582 387200 N >>= 1;
583 387200 Y = X + N;
584 387200 split = 1;
585 387200 duration -= 1;
586
2/2
✓ Branch 0 taken 245873 times.
✓ Branch 1 taken 141327 times.
387200 if (blocks == 1)
587 245873 fill = (fill & 1) | (fill << 1);
588 387200 blocks = (blocks + 1) >> 1;
589 }
590
591
2/2
✓ Branch 0 taken 627694 times.
✓ Branch 1 taken 1007694 times.
1635388 if (split) {
592 int qn;
593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 627694 times.
627694 int itheta = quant ? celt_calc_theta(X, Y, stereo, N) : 0;
594 int mbits, sbits, delta;
595 int qalloc;
596 int pulse_cap;
597 int offset;
598 int orig_fill;
599 int tell;
600
601 /* Decide on the resolution to give to the split parameter theta */
602 627694 pulse_cap = ff_celt_log_freq_range[band] + duration * 8;
603
4/4
✓ Branch 0 taken 240494 times.
✓ Branch 1 taken 387200 times.
✓ Branch 2 taken 54195 times.
✓ Branch 3 taken 186299 times.
627694 offset = (pulse_cap >> 1) - (stereo && N == 2 ? CELT_QTHETA_OFFSET_TWOPHASE :
604 CELT_QTHETA_OFFSET);
605
4/4
✓ Branch 0 taken 240494 times.
✓ Branch 1 taken 387200 times.
✓ Branch 2 taken 188735 times.
✓ Branch 3 taken 51759 times.
627694 qn = (stereo && band >= f->intensity_stereo) ? 1 :
606 575935 celt_compute_qn(N, b, offset, pulse_cap, stereo);
607 627694 tell = opus_rc_tell_frac(rc);
608
2/2
✓ Branch 0 taken 574220 times.
✓ Branch 1 taken 53474 times.
627694 if (qn != 1) {
609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 574220 times.
574220 if (quant)
610 itheta = (itheta*qn + 8192) >> 14;
611 /* Entropy coding of the angle. We use a uniform pdf for the
612 * time split, a step for stereo, and a triangular one for the rest. */
613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 574220 times.
574220 if (quant) {
614 if (stereo && N > 2)
615 ff_opus_rc_enc_uint_step(rc, itheta, qn / 2);
616 else if (stereo || B0 > 1)
617 ff_opus_rc_enc_uint(rc, itheta, qn + 1);
618 else
619 ff_opus_rc_enc_uint_tri(rc, itheta, qn);
620 itheta = itheta * 16384 / qn;
621 if (stereo) {
622 if (itheta == 0)
623 celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band],
624 f->block[1].lin_energy[band], N);
625 else
626 celt_stereo_ms_decouple(X, Y, N);
627 }
628 } else {
629
4/4
✓ Branch 0 taken 187020 times.
✓ Branch 1 taken 387200 times.
✓ Branch 2 taken 138861 times.
✓ Branch 3 taken 48159 times.
574220 if (stereo && N > 2)
630 138861 itheta = ff_opus_rc_dec_uint_step(rc, qn / 2);
631
4/4
✓ Branch 0 taken 387200 times.
✓ Branch 1 taken 48159 times.
✓ Branch 2 taken 141327 times.
✓ Branch 3 taken 245873 times.
435359 else if (stereo || B0 > 1)
632 189486 itheta = ff_opus_rc_dec_uint(rc, qn+1);
633 else
634 245873 itheta = ff_opus_rc_dec_uint_tri(rc, qn);
635 574220 itheta = itheta * 16384 / qn;
636 }
637
1/2
✓ Branch 0 taken 53474 times.
✗ Branch 1 not taken.
53474 } else if (stereo) {
638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53474 times.
53474 if (quant) {
639 inv = f->apply_phase_inv ? itheta > 8192 : 0;
640 if (inv) {
641 for (i = 0; i < N; i++)
642 Y[i] *= -1;
643 }
644 celt_stereo_is_decouple(X, Y, f->block[0].lin_energy[band],
645 f->block[1].lin_energy[band], N);
646
647 if (b > 2 << 3 && f->remaining2 > 2 << 3) {
648 ff_opus_rc_enc_log(rc, inv, 2);
649 } else {
650 inv = 0;
651 }
652 } else {
653
3/4
✓ Branch 0 taken 19635 times.
✓ Branch 1 taken 33839 times.
✓ Branch 2 taken 19635 times.
✗ Branch 3 not taken.
53474 inv = (b > 2 << 3 && f->remaining2 > 2 << 3) ? ff_opus_rc_dec_log(rc, 2) : 0;
654
1/2
✓ Branch 0 taken 53474 times.
✗ Branch 1 not taken.
53474 inv = f->apply_phase_inv ? inv : 0;
655 }
656 53474 itheta = 0;
657 }
658 627694 qalloc = opus_rc_tell_frac(rc) - tell;
659 627694 b -= qalloc;
660
661 627694 orig_fill = fill;
662
2/2
✓ Branch 0 taken 105759 times.
✓ Branch 1 taken 521935 times.
627694 if (itheta == 0) {
663 105759 imid = 32767;
664 105759 iside = 0;
665 105759 fill = av_mod_uintp2(fill, blocks);
666 105759 delta = -16384;
667
2/2
✓ Branch 0 taken 2384 times.
✓ Branch 1 taken 519551 times.
521935 } else if (itheta == 16384) {
668 2384 imid = 0;
669 2384 iside = 32767;
670 2384 fill &= ((1 << blocks) - 1) << blocks;
671 2384 delta = 16384;
672 } else {
673 519551 imid = celt_cos(itheta);
674 519551 iside = celt_cos(16384-itheta);
675 /* This is the mid vs side allocation that minimizes squared error
676 in that band. */
677 519551 delta = ROUND_MUL16((N - 1) << 7, celt_log2tan(iside, imid));
678 }
679
680 627694 mid = imid / 32768.0f;
681 627694 side = iside / 32768.0f;
682
683 /* This is a special case for N=2 that only works for stereo and takes
684 advantage of the fact that mid and side are orthogonal to encode
685 the side with just one bit. */
686
4/4
✓ Branch 0 taken 104284 times.
✓ Branch 1 taken 523410 times.
✓ Branch 2 taken 54195 times.
✓ Branch 3 taken 50089 times.
627694 if (N == 2 && stereo) {
687 int c;
688 54195 int sign = 0;
689 float tmp;
690 float *x2, *y2;
691 54195 mbits = b;
692 /* Only need one bit for the side */
693
4/4
✓ Branch 0 taken 30179 times.
✓ Branch 1 taken 24016 times.
✓ Branch 2 taken 28840 times.
✓ Branch 3 taken 1339 times.
54195 sbits = (itheta != 0 && itheta != 16384) ? 1 << 3 : 0;
694 54195 mbits -= sbits;
695 54195 c = (itheta > 8192);
696 54195 f->remaining2 -= qalloc+sbits;
697
698
2/2
✓ Branch 0 taken 11376 times.
✓ Branch 1 taken 42819 times.
54195 x2 = c ? Y : X;
699
2/2
✓ Branch 0 taken 11376 times.
✓ Branch 1 taken 42819 times.
54195 y2 = c ? X : Y;
700
2/2
✓ Branch 0 taken 28840 times.
✓ Branch 1 taken 25355 times.
54195 if (sbits) {
701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28840 times.
28840 if (quant) {
702 sign = x2[0]*y2[1] - x2[1]*y2[0] < 0;
703 ff_opus_rc_put_raw(rc, sign, 1);
704 } else {
705 28840 sign = ff_opus_rc_get_raw(rc, 1);
706 }
707 }
708 54195 sign = 1 - 2 * sign;
709 /* We use orig_fill here because we want to fold the side, but if
710 itheta==16384, we'll have cleared the low bits of fill. */
711 54195 cm = pvq->quant_band(pvq, f, rc, band, x2, NULL, N, mbits, blocks, lowband, duration,
712 lowband_out, level, gain, lowband_scratch, orig_fill);
713 /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse),
714 and there's no need to worry about mixing with the other channel. */
715 54195 y2[0] = -sign * x2[1];
716 54195 y2[1] = sign * x2[0];
717 54195 X[0] *= mid;
718 54195 X[1] *= mid;
719 54195 Y[0] *= side;
720 54195 Y[1] *= side;
721 54195 tmp = X[0];
722 54195 X[0] = tmp - Y[0];
723 54195 Y[0] = tmp + Y[0];
724 54195 tmp = X[1];
725 54195 X[1] = tmp - Y[1];
726 54195 Y[1] = tmp + Y[1];
727 } else {
728 /* "Normal" split code */
729 573499 float *next_lowband2 = NULL;
730 573499 float *next_lowband_out1 = NULL;
731 573499 int next_level = 0;
732 int rebalance;
733 uint32_t cmt;
734
735 /* Give more bits to low-energy MDCTs than they would
736 * otherwise deserve */
737
6/6
✓ Branch 0 taken 170425 times.
✓ Branch 1 taken 403074 times.
✓ Branch 2 taken 141327 times.
✓ Branch 3 taken 29098 times.
✓ Branch 4 taken 140343 times.
✓ Branch 5 taken 984 times.
573499 if (B0 > 1 && !stereo && (itheta & 0x3fff)) {
738
2/2
✓ Branch 0 taken 61276 times.
✓ Branch 1 taken 79067 times.
140343 if (itheta > 8192)
739 /* Rough approximation for pre-echo masking */
740 61276 delta -= delta >> (4 - duration);
741 else
742 /* Corresponds to a forward-masking slope of
743 * 1.5 dB per 10 ms */
744 79067 delta = FFMIN(0, delta + (N << 3 >> (5 - duration)));
745 }
746 573499 mbits = av_clip((b - delta) / 2, 0, b);
747 573499 sbits = b - mbits;
748 573499 f->remaining2 -= qalloc;
749
750
4/4
✓ Branch 0 taken 452857 times.
✓ Branch 1 taken 120642 times.
✓ Branch 2 taken 292705 times.
✓ Branch 3 taken 160152 times.
573499 if (lowband && !stereo)
751 292705 next_lowband2 = lowband + N; /* >32-bit split case */
752
753 /* Only stereo needs to pass on lowband_out.
754 * Otherwise, it's handled at the end */
755
2/2
✓ Branch 0 taken 186299 times.
✓ Branch 1 taken 387200 times.
573499 if (stereo)
756 186299 next_lowband_out1 = lowband_out;
757 else
758 387200 next_level = level + 1;
759
760 573499 rebalance = f->remaining2;
761
2/2
✓ Branch 0 taken 351878 times.
✓ Branch 1 taken 221621 times.
573499 if (mbits >= sbits) {
762 /* In stereo mode, we do not apply a scaling to the mid
763 * because we need the normalized mid for folding later */
764
2/2
✓ Branch 0 taken 202679 times.
✓ Branch 1 taken 149199 times.
351878 cm = pvq->quant_band(pvq, f, rc, band, X, NULL, N, mbits, blocks,
765 lowband, duration, next_lowband_out1, next_level,
766 stereo ? 1.0f : (gain * mid), lowband_scratch, fill);
767 351878 rebalance = mbits - (rebalance - f->remaining2);
768
4/4
✓ Branch 0 taken 95802 times.
✓ Branch 1 taken 256076 times.
✓ Branch 2 taken 86613 times.
✓ Branch 3 taken 9189 times.
351878 if (rebalance > 3 << 3 && itheta != 0)
769 86613 sbits += rebalance - (3 << 3);
770
771 /* For a stereo split, the high bits of fill are always zero,
772 * so no folding will be done to the side. */
773 351878 cmt = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks,
774 next_lowband2, duration, NULL, next_level,
775 gain * side, NULL, fill >> blocks);
776 351878 cm |= cmt << ((B0 >> 1) & (stereo - 1));
777 } else {
778 /* For a stereo split, the high bits of fill are always zero,
779 * so no folding will be done to the side. */
780 221621 cm = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks,
781 next_lowband2, duration, NULL, next_level,
782 gain * side, NULL, fill >> blocks);
783 221621 cm <<= ((B0 >> 1) & (stereo - 1));
784 221621 rebalance = sbits - (rebalance - f->remaining2);
785
4/4
✓ Branch 0 taken 81295 times.
✓ Branch 1 taken 140326 times.
✓ Branch 2 taken 81050 times.
✓ Branch 3 taken 245 times.
221621 if (rebalance > 3 << 3 && itheta != 16384)
786 81050 mbits += rebalance - (3 << 3);
787
788 /* In stereo mode, we do not apply a scaling to the mid because
789 * we need the normalized mid for folding later */
790
2/2
✓ Branch 0 taken 184521 times.
✓ Branch 1 taken 37100 times.
221621 cm |= pvq->quant_band(pvq, f, rc, band, X, NULL, N, mbits, blocks,
791 lowband, duration, next_lowband_out1, next_level,
792 stereo ? 1.0f : (gain * mid), lowband_scratch, fill);
793 }
794 }
795 } else {
796 /* This is the basic no-split case */
797 1007694 uint32_t q = celt_bits2pulses(cache, b);
798 1007694 uint32_t curr_bits = celt_pulses2bits(cache, q);
799 1007694 f->remaining2 -= curr_bits;
800
801 /* Ensures we can never bust the budget */
802
4/4
✓ Branch 0 taken 14994 times.
✓ Branch 1 taken 1004459 times.
✓ Branch 2 taken 11759 times.
✓ Branch 3 taken 3235 times.
1019453 while (f->remaining2 < 0 && q > 0) {
803 11759 f->remaining2 += curr_bits;
804 11759 curr_bits = celt_pulses2bits(cache, --q);
805 11759 f->remaining2 -= curr_bits;
806 }
807
808
2/2
✓ Branch 0 taken 868892 times.
✓ Branch 1 taken 138802 times.
1007694 if (q != 0) {
809 /* Finally do the actual (de)quantization */
810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 868892 times.
868892 if (quant) {
811 cm = celt_alg_quant(rc, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1),
812 f->spread, blocks, gain, pvq);
813 } else {
814
2/2
✓ Branch 0 taken 558333 times.
✓ Branch 1 taken 310559 times.
868892 cm = celt_alg_unquant(rc, X, N, (q < 8) ? q : (8 + (q & 7)) << ((q >> 3) - 1),
815 f->spread, blocks, gain, pvq);
816 }
817 } else {
818 /* If there's no pulse, fill the band anyway */
819 138802 uint32_t cm_mask = (1 << blocks) - 1;
820 138802 fill &= cm_mask;
821
2/2
✓ Branch 0 taken 54173 times.
✓ Branch 1 taken 84629 times.
138802 if (fill) {
822
2/2
✓ Branch 0 taken 9195 times.
✓ Branch 1 taken 44978 times.
54173 if (!lowband) {
823 /* Noise */
824
2/2
✓ Branch 0 taken 212472 times.
✓ Branch 1 taken 9195 times.
221667 for (i = 0; i < N; i++)
825 212472 X[i] = (((int32_t)celt_rng(f)) >> 20);
826 9195 cm = cm_mask;
827 } else {
828 /* Folded spectrum */
829
2/2
✓ Branch 0 taken 1772186 times.
✓ Branch 1 taken 44978 times.
1817164 for (i = 0; i < N; i++) {
830 /* About 48 dB below the "normal" folding level */
831
2/2
✓ Branch 1 taken 887413 times.
✓ Branch 2 taken 884773 times.
1772186 X[i] = lowband[i] + (((celt_rng(f)) & 0x8000) ? 1.0f / 256 : -1.0f / 256);
832 }
833 44978 cm = fill;
834 }
835 54173 celt_renormalize_vector(X, N, gain);
836 } else {
837 84629 memset(X, 0, N*sizeof(float));
838 }
839 }
840 }
841
842 /* This code is used by the decoder and by the resynthesis-enabled encoder */
843
2/2
✓ Branch 0 taken 240494 times.
✓ Branch 1 taken 1394894 times.
1635388 if (stereo) {
844
2/2
✓ Branch 0 taken 186299 times.
✓ Branch 1 taken 54195 times.
240494 if (N > 2)
845 186299 celt_stereo_merge(X, Y, mid, N);
846
2/2
✓ Branch 0 taken 6978 times.
✓ Branch 1 taken 233516 times.
240494 if (inv) {
847
2/2
✓ Branch 0 taken 391242 times.
✓ Branch 1 taken 6978 times.
398220 for (i = 0; i < N; i++)
848 391242 Y[i] *= -1;
849 }
850
2/2
✓ Branch 0 taken 620494 times.
✓ Branch 1 taken 774400 times.
1394894 } else if (level == 0) {
851 int k;
852
853 /* Undo the sample reorganization going from time order to frequency order */
854
2/2
✓ Branch 0 taken 140404 times.
✓ Branch 1 taken 480090 times.
620494 if (B0 > 1)
855 140404 celt_interleave_hadamard(pvq->hadamard_tmp, X, N_B >> recombine,
856 B0 << recombine, longblocks);
857
858 /* Undo time-freq changes that we did earlier */
859 620494 N_B = N_B0;
860 620494 blocks = B0;
861
2/2
✓ Branch 0 taken 149677 times.
✓ Branch 1 taken 620494 times.
770171 for (k = 0; k < time_divide; k++) {
862 149677 blocks >>= 1;
863 149677 N_B <<= 1;
864 149677 cm |= cm >> blocks;
865 149677 celt_haar1(X, N_B, blocks);
866 }
867
868
2/2
✓ Branch 0 taken 67800 times.
✓ Branch 1 taken 620494 times.
688294 for (k = 0; k < recombine; k++) {
869 67800 cm = ff_celt_bit_deinterleave[cm];
870 67800 celt_haar1(X, N0>>k, 1<<k);
871 }
872 620494 blocks <<= recombine;
873
874 /* Scale output for later folding */
875
2/2
✓ Branch 0 taken 434195 times.
✓ Branch 1 taken 186299 times.
620494 if (lowband_out) {
876 434195 float n = sqrtf(N0);
877
2/2
✓ Branch 0 taken 7769770 times.
✓ Branch 1 taken 434195 times.
8203965 for (i = 0; i < N0; i++)
878 7769770 lowband_out[i] = n * X[i];
879 }
880 620494 cm = av_mod_uintp2(cm, blocks);
881 }
882
883 1635388 return cm;
884 }
885
886 1745036 static QUANT_FN(pvq_decode_band)
887 {
888 #if CONFIG_OPUS_DECODER
889 1745036 return quant_band_template(pvq, f, rc, band, X, Y, N, b, blocks, lowband, duration,
890 lowband_out, level, gain, lowband_scratch, fill, 0);
891 #else
892 return 0;
893 #endif
894 }
895
896 static QUANT_FN(pvq_encode_band)
897 {
898 #if CONFIG_OPUS_ENCODER
899 return quant_band_template(pvq, f, rc, band, X, Y, N, b, blocks, lowband, duration,
900 lowband_out, level, gain, lowband_scratch, fill, 1);
901 #else
902 return 0;
903 #endif
904 }
905
906 58 int av_cold ff_celt_pvq_init(CeltPVQ **pvq, int encode)
907 {
908 58 CeltPVQ *s = av_malloc(sizeof(CeltPVQ));
909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
58 if (!s)
910 return AVERROR(ENOMEM);
911
912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
58 s->quant_band = encode ? pvq_encode_band : pvq_decode_band;
913
914 #if CONFIG_OPUS_ENCODER
915 58 s->pvq_search = ppp_pvq_search_c;
916 #if ARCH_X86
917 58 ff_celt_pvq_init_x86(s);
918 #endif
919 #endif
920
921 58 *pvq = s;
922
923 58 return 0;
924 }
925
926 58 void av_cold ff_celt_pvq_uninit(CeltPVQ **pvq)
927 {
928 58 av_freep(pvq);
929 58 }
930