| 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/common.h" | ||
| 25 | #include "libavutil/macros.h" | ||
| 26 | #include "aacencdsp.h" | ||
| 27 | |||
| 28 | 598324 | static void abs_pow34_v(float *out, const float *in, const int size) | |
| 29 | { | ||
| 30 |
2/2✓ Branch 0 taken 36213344 times.
✓ Branch 1 taken 598324 times.
|
36811668 | for (int i = 0; i < size; i++) { |
| 31 | 36213344 | float a = fabsf(in[i]); | |
| 32 | 36213344 | out[i] = sqrtf(a * sqrtf(a)); | |
| 33 | } | ||
| 34 | 598324 | } | |
| 35 | |||
| 36 | 9363038 | static void quantize_bands(int *out, const float *in, const float *scaled, | |
| 37 | int size, int is_signed, int maxval, const float Q34, | ||
| 38 | const float rounding) | ||
| 39 | { | ||
| 40 |
2/2✓ Branch 0 taken 176972112 times.
✓ Branch 1 taken 9363038 times.
|
186335150 | for (int i = 0; i < size; i++) { |
| 41 | 176972112 | float qc = scaled[i] * Q34; | |
| 42 |
2/2✓ Branch 0 taken 30835660 times.
✓ Branch 1 taken 146136452 times.
|
176972112 | int tmp = (int)FFMIN((float)(qc + rounding), (float)maxval); |
| 43 |
4/4✓ Branch 0 taken 67325468 times.
✓ Branch 1 taken 109646644 times.
✓ Branch 2 taken 33648353 times.
✓ Branch 3 taken 33677115 times.
|
176972112 | if (is_signed && in[i] < 0.0f) { |
| 44 | 33648353 | tmp = -tmp; | |
| 45 | } | ||
| 46 | 176972112 | out[i] = tmp; | |
| 47 | } | ||
| 48 | 9363038 | } | |
| 49 | |||
| 50 | /* One NMR scalefactor-trellis Viterbi step, for each current-band candidate, find the | ||
| 51 | * previous-band candidate minimising dpp[op] + lamsf[d] then set | ||
| 52 | * dp[o] = node[o] + that cost and record the back-pointer bp[o] */ | ||
| 53 | 1997866 | static void nmr_trellis_step_c(float *dp, uint8_t *bp, const float *dpp, | |
| 54 | const float *node, const float *lamsf, | ||
| 55 | int n_cur, int n_prev, int base, int step, int mdiff) | ||
| 56 | { | ||
| 57 | /* d = base + (o - op) * step lies in [-mdiff, mdiff] for op in [o - dlo, o + dhi] */ | ||
| 58 |
1/2✓ Branch 0 taken 1997866 times.
✗ Branch 1 not taken.
|
1997866 | const int dlo = FFUDIV(mdiff - base, step); |
| 59 |
1/2✓ Branch 0 taken 1997866 times.
✗ Branch 1 not taken.
|
1997866 | const int dhi = FFUDIV(mdiff + base, step); |
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 27861575 times.
✓ Branch 1 taken 1997866 times.
|
29859441 | for (int o = 0; o < n_cur; o++) { |
| 62 | 27861575 | const int op_end = FFMIN(n_prev, o + dhi + 1); | |
| 63 | 27861575 | const int edge = base + o * step + mdiff; | |
| 64 | 27861575 | int best = -1; | |
| 65 | 27861575 | float bestc = FLT_MAX; | |
| 66 |
2/2✓ Branch 0 taken 391549545 times.
✓ Branch 1 taken 27861575 times.
|
419411120 | for (int op = FFMAX(0, o - dlo); op < op_end; op++) { |
| 67 | 391549545 | float c = dpp[op] + lamsf[edge - op * step]; | |
| 68 |
2/2✓ Branch 0 taken 240365263 times.
✓ Branch 1 taken 151184282 times.
|
391549545 | if (c < bestc) { |
| 69 | 240365263 | bestc = c; | |
| 70 | 240365263 | best = op; | |
| 71 | } | ||
| 72 | } | ||
| 73 | 27861575 | bp[o] = best < 0 ? 0 : best; | |
| 74 |
2/2✓ Branch 0 taken 27861458 times.
✓ Branch 1 taken 117 times.
|
27861575 | dp[o] = best < 0 ? FLT_MAX : node[o] + bestc; |
| 75 | } | ||
| 76 | 1997866 | } | |
| 77 | |||
| 78 | 41 | void ff_aacenc_dsp_init(AACEncDSPContext *s) | |
| 79 | { | ||
| 80 | 41 | s->abs_pow34 = abs_pow34_v; | |
| 81 | 41 | s->quant_bands = quantize_bands; | |
| 82 | 41 | s->nmr_trellis_step = nmr_trellis_step_c; | |
| 83 | |||
| 84 | #if ARCH_RISCV | ||
| 85 | ff_aacenc_dsp_init_riscv(s); | ||
| 86 | #elif ARCH_X86 && HAVE_X86ASM | ||
| 87 | 41 | ff_aacenc_dsp_init_x86(s); | |
| 88 | #elif ARCH_AARCH64 | ||
| 89 | ff_aacenc_dsp_init_aarch64(s); | ||
| 90 | #endif | ||
| 91 | 41 | } | |
| 92 |