libvisual  0.5.0
lv_math.h
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Dennis Smit <ds@nerds-incorporated.org>
7  * Chong Kai Xiong <kaixiong@codeleft.sg>
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 #ifndef _LV_MATH_H
25 #define _LV_MATH_H
26 
27 #include <libvisual/lvconfig.h>
28 #include <libvisual/lv_defines.h>
29 #include <libvisual/lv_types.h>
30 
31 #ifdef __cplusplus
32 
33 #include <algorithm>
34 
35 namespace LV {
36 
37  template <typename T>
38  T clamp (T value, T lower, T upper)
39  {
40  return std::max (lower, std::min (upper, value));
41  }
42 
43 } // LV namespce
44 
45 #endif /* __cplusplus */
46 
52 #define VISUAL_MATH_PI 3.141592653589793238462643383279502884197169399f
53 
54 LV_BEGIN_DECLS
55 
63 LV_API int visual_math_is_power_of_2 (int n);
64 
72 LV_API unsigned int visual_math_round_power_of_2 (unsigned int n);
73 
84 LV_API void visual_math_simd_mul_floats_float (float *LV_RESTRICT dest, const float *LV_RESTRICT src, float k, visual_size_t count);
85 
96 LV_API void visual_math_simd_add_floats_float (float *LV_RESTRICT dest, const float *LV_RESTRICT src, float k, visual_size_t count);
97 
98 LV_API 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);
99 
107 LV_API void visual_math_simd_floats_to_int32s (int32_t *LV_RESTRICT ints, const float *LV_RESTRICT flts, visual_size_t count);
108 
116 LV_API void visual_math_simd_int32s_to_floats (float *LV_RESTRICT flts, const int32_t *LV_RESTRICT ints, visual_size_t count);
117 
127 LV_API 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);
128 
137 LV_API 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);
138 
149 LV_API void visual_math_simd_denorm_floats_to_int32s (int32_t *LV_RESTRICT ints, const float *LV_RESTRICT flts, float k, visual_size_t count);
150 
163 LV_API 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);
164 
174 LV_API void visual_math_simd_sqrt_floats (float *LV_RESTRICT dest, const float *LV_RESTRICT src, visual_size_t count);
175 
185 LV_API void visual_math_simd_complex_norm (float *LV_RESTRICT dest, const float *LV_RESTRICT real, const float *LV_RESTRICT imag, visual_size_t count);
186 
197 LV_API 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);
198 
199 LV_END_DECLS
200 
205 #endif /* _LV_MATH_H */