FFmpeg
Loading...
Searching...
No Matches
aacencdsp.c
Go to the documentation of this file.
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
28static void abs_pow34_v(float *out, const float *in, const int size)
29{
30 for (int i = 0; i < size; i++) {
31 float a = fabsf(in[i]);
32 out[i] = sqrtf(a * sqrtf(a));
33 }
34}
35
36static 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 for (int i = 0; i < size; i++) {
41 float qc = scaled[i] * Q34;
42 int tmp = (int)FFMIN((float)(qc + rounding), (float)maxval);
43 if (is_signed && in[i] < 0.0f) {
44 tmp = -tmp;
45 }
46 out[i] = tmp;
47 }
48}
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] */
53static 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 const int dlo = FFUDIV(mdiff - base, step);
59 const int dhi = FFUDIV(mdiff + base, step);
60
61 for (int o = 0; o < n_cur; o++) {
62 const int op_end = FFMIN(n_prev, o + dhi + 1);
63 const int edge = base + o * step + mdiff;
64 int best = -1;
65 float bestc = FLT_MAX;
66 for (int op = FFMAX(0, o - dlo); op < op_end; op++) {
67 float c = dpp[op] + lamsf[edge - op * step];
68 if (c < bestc) {
69 bestc = c;
70 best = op;
71 }
72 }
73 bp[o] = best < 0 ? 0 : best;
74 dp[o] = best < 0 ? FLT_MAX : node[o] + bestc;
75 }
76}
77
79{
80 s->abs_pow34 = abs_pow34_v;
81 s->quant_bands = quantize_bands;
82 s->nmr_trellis_step = nmr_trellis_step_c;
83
84#if ARCH_RISCV
86#elif ARCH_X86 && HAVE_X86ASM
88#elif ARCH_AARCH64
90#endif
91}
void ff_aacenc_dsp_init_aarch64(AACEncDSPContext *s)
void ff_aacenc_dsp_init_riscv(AACEncDSPContext *s)
void ff_aacenc_dsp_init_x86(AACEncDSPContext *s)
static FILE * out
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
common internal and external API header
#define FFUDIV(a, b)
Definition common.h:65
static __device__ float sqrtf(float a)
static __device__ float fabsf(float a)
int a
static void nmr_trellis_step_c(float *dp, uint8_t *bp, const float *dpp, const float *node, const float *lamsf, int n_cur, int n_prev, int base, int step, int mdiff)
Definition aacencdsp.c:53
static void quantize_bands(int *out, const float *in, const float *scaled, int size, int is_signed, int maxval, const float Q34, const float rounding)
Definition aacencdsp.c:36
void ff_aacenc_dsp_init(AACEncDSPContext *s)
Definition aacencdsp.c:78
static void abs_pow34_v(float *out, const float *in, const int size)
Definition aacencdsp.c:28
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition anm.c:76
Utility Preprocessor macros.
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
static uint8_t tmp[40]
Definition aes_ctr.c:52
int size
uint8_t base
Definition vp3data.h:128
static double c[64]