FFmpeg
audiodsp.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 <stdint.h>
20 
21 #include "libavutil/attributes.h"
22 #include "libavutil/common.h"
23 #include "audiodsp.h"
24 
25 static inline float clipf_c_one(float a, uint32_t mini,
26  uint32_t maxi, uint32_t maxisign)
27 {
28  uint32_t ai = av_float2int(a);
29 
30  if (ai > mini)
31  return av_int2float(mini);
32  else if ((ai ^ (1U << 31)) > maxisign)
33  return av_int2float(maxi);
34  else
35  return a;
36 }
37 
38 static void vector_clipf_c_opposite_sign(float *dst, const float *src,
39  float min, float max, int len)
40 {
41  int i;
42  uint32_t mini = av_float2int(min);
43  uint32_t maxi = av_float2int(max);
44  uint32_t maxisign = maxi ^ (1U << 31);
45 
46  for (i = 0; i < len; i += 8) {
47  dst[i + 0] = clipf_c_one(src[i + 0], mini, maxi, maxisign);
48  dst[i + 1] = clipf_c_one(src[i + 1], mini, maxi, maxisign);
49  dst[i + 2] = clipf_c_one(src[i + 2], mini, maxi, maxisign);
50  dst[i + 3] = clipf_c_one(src[i + 3], mini, maxi, maxisign);
51  dst[i + 4] = clipf_c_one(src[i + 4], mini, maxi, maxisign);
52  dst[i + 5] = clipf_c_one(src[i + 5], mini, maxi, maxisign);
53  dst[i + 6] = clipf_c_one(src[i + 6], mini, maxi, maxisign);
54  dst[i + 7] = clipf_c_one(src[i + 7], mini, maxi, maxisign);
55  }
56 }
57 
58 static void vector_clipf_c(float *dst, const float *src, int len,
59  float min, float max)
60 {
61  int i;
62 
63  if (min < 0 && max > 0) {
65  } else {
66  for (i = 0; i < len; i += 8) {
67  dst[i] = av_clipf(src[i], min, max);
68  dst[i + 1] = av_clipf(src[i + 1], min, max);
69  dst[i + 2] = av_clipf(src[i + 2], min, max);
70  dst[i + 3] = av_clipf(src[i + 3], min, max);
71  dst[i + 4] = av_clipf(src[i + 4], min, max);
72  dst[i + 5] = av_clipf(src[i + 5], min, max);
73  dst[i + 6] = av_clipf(src[i + 6], min, max);
74  dst[i + 7] = av_clipf(src[i + 7], min, max);
75  }
76  }
77 }
78 
79 static int32_t scalarproduct_int16_c(const int16_t *v1, const int16_t *v2,
80  int order)
81 {
82  unsigned res = 0;
83 
84  while (order--)
85  res += *v1++ **v2++;
86 
87  return res;
88 }
89 
90 static void vector_clip_int32_c(int32_t *dst, const int32_t *src, int32_t min,
91  int32_t max, unsigned int len)
92 {
93  do {
94  *dst++ = av_clip(*src++, min, max);
95  *dst++ = av_clip(*src++, min, max);
96  *dst++ = av_clip(*src++, min, max);
97  *dst++ = av_clip(*src++, min, max);
98  *dst++ = av_clip(*src++, min, max);
99  *dst++ = av_clip(*src++, min, max);
100  *dst++ = av_clip(*src++, min, max);
101  *dst++ = av_clip(*src++, min, max);
102  len -= 8;
103  } while (len > 0);
104 }
105 
107 {
108  c->scalarproduct_int16 = scalarproduct_int16_c;
109  c->vector_clip_int32 = vector_clip_int32_c;
110  c->vector_clipf = vector_clipf_c;
111 
112 #if ARCH_ARM
114 #elif ARCH_PPC
116 #elif ARCH_RISCV
118 #elif ARCH_X86
120 #endif
121 }
vector_clipf_c_opposite_sign
static void vector_clipf_c_opposite_sign(float *dst, const float *src, float min, float max, int len)
Definition: audiodsp.c:38
av_clip
#define av_clip
Definition: common.h:98
ff_audiodsp_init_x86
void ff_audiodsp_init_x86(AudioDSPContext *c)
Definition: audiodsp_init.c:42
ff_audiodsp_init
av_cold void ff_audiodsp_init(AudioDSPContext *c)
Definition: audiodsp.c:106
max
#define max(a, b)
Definition: cuda_runtime.h:33
ff_audiodsp_init_ppc
av_cold void ff_audiodsp_init_ppc(AudioDSPContext *c)
Definition: audiodsp.c:86
av_float2int
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
av_int2float
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
Definition: intfloat.h:40
av_cold
#define av_cold
Definition: attributes.h:90
vector_clipf_c
static void vector_clipf_c(float *dst, const float *src, int len, float min, float max)
Definition: audiodsp.c:58
ff_audiodsp_init_arm
av_cold void ff_audiodsp_init_arm(AudioDSPContext *c)
Definition: audiodsp_init_arm.c:27
av_clipf
av_clipf
Definition: af_crystalizer.c:121
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
vector_clip_int32_c
static void vector_clip_int32_c(int32_t *dst, const int32_t *src, int32_t min, int32_t max, unsigned int len)
Definition: audiodsp.c:90
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
attributes.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
common.h
len
int len
Definition: vorbis_enc_data.h:426
scalarproduct_int16_c
static int32_t scalarproduct_int16_c(const int16_t *v1, const int16_t *v2, int order)
Definition: audiodsp.c:79
U
#define U(x)
Definition: vpx_arith.h:37
audiodsp.h
clipf_c_one
static float clipf_c_one(float a, uint32_t mini, uint32_t maxi, uint32_t maxisign)
Definition: audiodsp.c:25
AudioDSPContext
Definition: audiodsp.h:24
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
int32_t
int32_t
Definition: audioconvert.c:56
ff_audiodsp_init_riscv
void ff_audiodsp_init_riscv(AudioDSPContext *c)
Definition: audiodsp_init.c:34
min
float min
Definition: vorbis_enc_data.h:429