FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
celp_math.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 <math.h>
20 #include <stdint.h>
21 
22 #include "libavutil/avassert.h"
23 #include "libavutil/float_dsp.h"
24 #include "libavutil/libm.h"
25 #include "libavutil/macros.h"
26 
27 #include "libavcodec/celp_math.h"
28 
29 static inline void IsAlmostEqual(float A, float B, float epsilon)
30 {
31  float diff = fabsf(A - B);
32  float absa = fabsf(A);
33  float absb = fabsf(B);
34  float largest = (absb > absa) ? absb : absa;
35  av_assert0(diff <= largest * epsilon);
36 }
37 
38 int main(void)
39 {
40  int i;
41  const float f1[3] = {0.0, 1.1, 2.2};
42  const float f2[3] = {3.3, 4.4, 5.5};
43  const int16_t i1[3] = {6, 7, 8};
44  const int16_t i2[3] = {9, 10, 11};
45 
46  float r = ff_scalarproduct_float_c(f1, f2, FF_ARRAY_ELEMS(f1));
47  int64_t d = ff_dot_product(i1, i2, FF_ARRAY_ELEMS(i1));
48 
49  IsAlmostEqual(16.94f, r, 0.000001f);
50  av_assert0(212 == d);
51 
52  for (i = 1024; i >= 1; i/=2)
53  av_assert0(ff_log2_q15(i) == (1<<15)*((int)log2(i))+(1<<2));
54 
55  return 0;
56 }
A
#define A(x)
Definition: vpx_arith.h:28
main
int main(void)
Definition: celp_math.c:38
r
const char * r
Definition: vf_curves.c:127
libm.h
int64_t
long long int64_t
Definition: coverity.c:34
macros.h
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
avassert.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
B
#define B
Definition: huffyuv.h:42
ff_log2_q15
int ff_log2_q15(uint32_t value)
Calculate log2(x).
Definition: celp_math.c:83
float_dsp.h
ff_scalarproduct_float_c
float ff_scalarproduct_float_c(const float *v1, const float *v2, int len)
Return the scalar product of two vectors of floats.
Definition: float_scalarproduct.c:24
f
f
Definition: af_crystalizer.c:122
celp_math.h
IsAlmostEqual
static void IsAlmostEqual(float A, float B, float epsilon)
Definition: celp_math.c:29
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_dot_product
int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length)
Calculate the dot product of 2 int16_t vectors.
Definition: celp_math.c:103
log2
#define log2(x)
Definition: libm.h:406