| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <float.h> | ||
| 20 | #include <math.h> | ||
| 21 | |||
| 22 | #include "config.h" | ||
| 23 | |||
| 24 | #include "libavutil/macros.h" | ||
| 25 | #include "aacencdsp.h" | ||
| 26 | |||
| 27 | 555511 | static void abs_pow34_v(float *out, const float *in, const int size) | |
| 28 | { | ||
| 29 |
2/2✓ Branch 0 taken 32387264 times.
✓ Branch 1 taken 555511 times.
|
32942775 | for (int i = 0; i < size; i++) { |
| 30 | 32387264 | float a = fabsf(in[i]); | |
| 31 | 32387264 | out[i] = sqrtf(a * sqrtf(a)); | |
| 32 | } | ||
| 33 | 555511 | } | |
| 34 | |||
| 35 | 7199366 | static void quantize_bands(int *out, const float *in, const float *scaled, | |
| 36 | int size, int is_signed, int maxval, const float Q34, | ||
| 37 | const float rounding) | ||
| 38 | { | ||
| 39 |
2/2✓ Branch 0 taken 147657396 times.
✓ Branch 1 taken 7199366 times.
|
154856762 | for (int i = 0; i < size; i++) { |
| 40 | 147657396 | float qc = scaled[i] * Q34; | |
| 41 |
2/2✓ Branch 0 taken 17985246 times.
✓ Branch 1 taken 129672150 times.
|
147657396 | int tmp = (int)FFMIN((float)(qc + rounding), (float)maxval); |
| 42 |
4/4✓ Branch 0 taken 60073968 times.
✓ Branch 1 taken 87583428 times.
✓ Branch 2 taken 30032745 times.
✓ Branch 3 taken 30041223 times.
|
147657396 | if (is_signed && in[i] < 0.0f) { |
| 43 | 30032745 | tmp = -tmp; | |
| 44 | } | ||
| 45 | 147657396 | out[i] = tmp; | |
| 46 | } | ||
| 47 | 7199366 | } | |
| 48 | |||
| 49 | /* One NMR scalefactor-trellis Viterbi step, for each current-band candidate, find the | ||
| 50 | * previous-band candidate minimising dpp[op] + lamsf[d] then set | ||
| 51 | * dp[o] = node[o] + that cost and record the back-pointer bp[o] */ | ||
| 52 | 494392 | static void nmr_trellis_step_c(float *dp, uint8_t *bp, const float *dpp, | |
| 53 | const float *node, const float *lamsf, | ||
| 54 | int n_cur, int n_prev, int base, int step, int mdiff) | ||
| 55 | { | ||
| 56 |
2/2✓ Branch 0 taken 6281306 times.
✓ Branch 1 taken 494392 times.
|
6775698 | for (int o = 0; o < n_cur; o++) { |
| 57 | 6281306 | int best = -1; | |
| 58 | 6281306 | float bestc = FLT_MAX; | |
| 59 |
2/2✓ Branch 0 taken 82234225 times.
✓ Branch 1 taken 6281306 times.
|
88515531 | for (int op = 0; op < n_prev; op++) { |
| 60 | 82234225 | int d = base + (o - op) * step; | |
| 61 | float c; | ||
| 62 |
4/4✓ Branch 0 taken 81054917 times.
✓ Branch 1 taken 1179308 times.
✓ Branch 2 taken 1218588 times.
✓ Branch 3 taken 79836329 times.
|
82234225 | if (d < -mdiff || d > mdiff) |
| 63 | 2397896 | continue; | |
| 64 | 79836329 | c = dpp[op] + lamsf[d + mdiff]; | |
| 65 |
2/2✓ Branch 0 taken 60487590 times.
✓ Branch 1 taken 19348739 times.
|
79836329 | if (c < bestc) { |
| 66 | 60487590 | bestc = c; | |
| 67 | 60487590 | best = op; | |
| 68 | } | ||
| 69 | } | ||
| 70 | 6281306 | bp[o] = best < 0 ? 0 : best; | |
| 71 |
2/2✓ Branch 0 taken 6280370 times.
✓ Branch 1 taken 936 times.
|
6281306 | dp[o] = best < 0 ? FLT_MAX : node[o] + bestc; |
| 72 | } | ||
| 73 | 494392 | } | |
| 74 | |||
| 75 | 37 | void ff_aacenc_dsp_init(AACEncDSPContext *s) | |
| 76 | { | ||
| 77 | 37 | s->abs_pow34 = abs_pow34_v; | |
| 78 | 37 | s->quant_bands = quantize_bands; | |
| 79 | 37 | s->nmr_trellis_step = nmr_trellis_step_c; | |
| 80 | |||
| 81 | #if ARCH_RISCV | ||
| 82 | ff_aacenc_dsp_init_riscv(s); | ||
| 83 | #elif ARCH_X86 && HAVE_X86ASM | ||
| 84 | 37 | ff_aacenc_dsp_init_x86(s); | |
| 85 | #elif ARCH_AARCH64 | ||
| 86 | ff_aacenc_dsp_init_aarch64(s); | ||
| 87 | #endif | ||
| 88 | 37 | } | |
| 89 |