FFmpeg
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/macros.h"
25 #include "aacencdsp.h"
26 
27 static void abs_pow34_v(float *out, const float *in, const int size)
28 {
29  for (int i = 0; i < size; i++) {
30  float a = fabsf(in[i]);
31  out[i] = sqrtf(a * sqrtf(a));
32  }
33 }
34 
35 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  for (int i = 0; i < size; i++) {
40  float qc = scaled[i] * Q34;
41  int tmp = (int)FFMIN((float)(qc + rounding), (float)maxval);
42  if (is_signed && in[i] < 0.0f) {
43  tmp = -tmp;
44  }
45  out[i] = tmp;
46  }
47 }
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 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  for (int o = 0; o < n_cur; o++) {
57  int best = -1;
58  float bestc = FLT_MAX;
59  for (int op = 0; op < n_prev; op++) {
60  int d = base + (o - op) * step;
61  float c;
62  if (d < -mdiff || d > mdiff)
63  continue;
64  c = dpp[op] + lamsf[d + mdiff];
65  if (c < bestc) {
66  bestc = c;
67  best = op;
68  }
69  }
70  bp[o] = best < 0 ? 0 : best;
71  dp[o] = best < 0 ? FLT_MAX : node[o] + bestc;
72  }
73 }
74 
76 {
77  s->abs_pow34 = abs_pow34_v;
78  s->quant_bands = quantize_bands;
79  s->nmr_trellis_step = nmr_trellis_step_c;
80 
81 #if ARCH_RISCV
83 #elif ARCH_X86 && HAVE_X86ASM
85 #elif ARCH_AARCH64
87 #endif
88 }
ff_aacenc_dsp_init_riscv
void ff_aacenc_dsp_init_riscv(AACEncDSPContext *s)
Definition: aacencdsp_init.c:32
out
static FILE * out
Definition: movenc.c:55
AACEncDSPContext
Definition: aacencdsp.h:24
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
base
uint8_t base
Definition: vp3data.h:128
float.h
macros.h
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
ff_aacenc_dsp_init_x86
void ff_aacenc_dsp_init_x86(AACEncDSPContext *s)
Definition: aacencdsp_init.c:37
op
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
ff_aacenc_dsp_init_aarch64
void ff_aacenc_dsp_init_aarch64(AACEncDSPContext *s)
Definition: aacencdsp_init.c:31
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
abs_pow34_v
static void abs_pow34_v(float *out, const float *in, const int size)
Definition: aacencdsp.c:27
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
f
f
Definition: af_crystalizer.c:122
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
size
int size
Definition: twinvq_data.h:10344
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
quantize_bands
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:35
nmr_trellis_step_c
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:52
aacencdsp.h
s
uint8_t s
Definition: llvidencdsp.c:39
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_aacenc_dsp_init
void ff_aacenc_dsp_init(AACEncDSPContext *s)
Definition: aacencdsp.c:75