libvisual  0.5.0
lv_math.c
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Chong Kai Xiong <kaixiong@codeleft.sg>
7  * Dennis Smit <ds@nerds-incorporated.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #include "config.h"
25 #include "lv_math.h"
26 #include "lv_common.h"
27 #include "lv_math_orc.h"
28 #include <math.h>
29 
31 {
32  return (n > 0) && !(n & (n - 1));
33 }
34 
35 unsigned int visual_math_round_power_of_2 (unsigned int n)
36 {
37  n--;
38  n |= n >> 1;
39  n |= n >> 2;
40  n |= n >> 4;
41  n |= n >> 8;
42  n |= n >> 16;
43 #if SIZEOF_INT > 4
44  n |= n >> 32;
45 #endif
46  n++;
47 
48  return n;
49 }
50 
51 void visual_math_simd_mul_floats_float (float *LV_RESTRICT dest, const float *LV_RESTRICT src, float k, visual_size_t count)
52 {
53  simd_mul_floats_float (dest, src, k, (int) count);
54 }
55 
56 void visual_math_simd_add_floats_float (float *LV_RESTRICT dest, const float *LV_RESTRICT src, float adder, visual_size_t count)
57 {
58  simd_add_floats_float (dest, src, adder, (int) count);
59 }
60 
61 void visual_math_simd_mul_floats_floats (float *LV_RESTRICT dest, const float *LV_RESTRICT src1, const float *LV_RESTRICT src2, visual_size_t count)
62 {
63  simd_mul_floats_floats (dest, src1, src2, (int) count);
64 }
65 
66 void visual_math_simd_floats_to_int32s (int32_t *LV_RESTRICT ints, const float *LV_RESTRICT flts, visual_size_t count)
67 {
68  simd_floats_to_int32s ((uint32_t *LV_RESTRICT) ints, flts, (int) count);
69 }
70 
71 void visual_math_simd_int32s_to_floats (float *LV_RESTRICT flts, const int32_t *LV_RESTRICT ints, visual_size_t count)
72 {
73  simd_int32s_to_floats (flts, (const uint32_t *LV_RESTRICT) ints, (int) count);
74 }
75 
76 void visual_math_simd_floats_to_int32s_mul_float (int32_t *LV_RESTRICT ints, const float *LV_RESTRICT flts, float k, visual_size_t count)
77 {
78  simd_floats_to_int32s_mul_float ((uint32_t *LV_RESTRICT) ints, flts, k, (int) count);
79 }
80 
81 void visual_math_simd_int32s_to_floats_mul_float (float *LV_RESTRICT flts, const int32_t *LV_RESTRICT ints, float k, visual_size_t count)
82 {
83  simd_int32s_to_floats_mul_float (flts, (const uint32_t *LV_RESTRICT) ints, k, (int) count);
84 }
85 
86 void visual_math_simd_denorm_floats_to_int32s (int32_t *LV_RESTRICT ints, const float *LV_RESTRICT flts, float k, visual_size_t count)
87 {
88  simd_denorm_floats_to_int32s ((uint32_t *LV_RESTRICT) ints, flts, k, (int) count);
89 }
90 
91 void visual_math_simd_denorm_neg_floats_to_int32s (int32_t *LV_RESTRICT ints, const float *LV_RESTRICT flts, float k, visual_size_t count)
92 {
93  simd_denorm_neg_floats_to_int32s ((uint32_t *LV_RESTRICT) ints, flts, k, (int) count);
94 }
95 
96 void visual_math_simd_sqrt_floats (float *LV_RESTRICT dest, const float *LV_RESTRICT src, visual_size_t count)
97 {
98  simd_sqrt_floats (dest, src, (int) count);
99 }
100 
101 void visual_math_simd_complex_norm (float *LV_RESTRICT dest, const float *LV_RESTRICT real, const float *LV_RESTRICT imag, visual_size_t count)
102 {
103  simd_complex_norm (dest, real, imag, (int) count);
104 }
105 
106 void visual_math_simd_complex_scaled_norm (float *LV_RESTRICT dest, const float *LV_RESTRICT real, const float *LV_RESTRICT imag, float k, visual_size_t count)
107 {
108  simd_complex_scaled_norm (dest, real, imag, k, (int) count);
109 }