| 1 | /*---------------------------------------------------------------------------- |
| 2 | ChucK Strongly-timed Audio Programming Language |
| 3 | Compiler, Virtual Machine, and Synthesis Engine |
| 4 | |
| 5 | Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved. |
| 6 | http://chuck.stanford.edu/ |
| 7 | http://chuck.cs.princeton.edu/ |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the dual-license terms of EITHER the MIT License OR the GNU |
| 11 | General Public License (the latter as published by the Free Software |
| 12 | Foundation; either version 2 of the License or, at your option, any |
| 13 | later version). |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful and/or |
| 16 | interesting, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 17 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | MIT Licence and/or the GNU General Public License for details. |
| 19 | |
| 20 | You should have received a copy of the MIT License and the GNU General |
| 21 | Public License (GPL) along with this program; a copy of the GPL can also |
| 22 | be obtained by writing to the Free Software Foundation, Inc., 59 Temple |
| 23 | Place, Suite 330, Boston, MA 02111-1307 U.S.A. |
| 24 | -----------------------------------------------------------------------------*/ |
| 25 | |
| 26 | //----------------------------------------------------------------------------- |
| 27 | // name: util_math.h |
| 28 | // desc: a mini-compatibility library for math functions |
| 29 | // |
| 30 | // author: Ge Wang ([email protected] | [email protected]) |
| 31 | // Philip Davidson ([email protected]) |
| 32 | // date: Spring 2004 |
| 33 | //----------------------------------------------------------------------------- |
| 34 | #ifndef __UTIL_MATH_H__ |
| 35 | #define __UTIL_MATH_H__ |
| 36 | |
| 37 | #include <math.h> |
| 38 | #include "chuck_def.h" // 1.4.1.0 (ge) for t_CKINT |
| 39 | |
| 40 | #if defined (__cplusplus) || defined(_cplusplus) |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
| 44 | // 1.4.1.1 (ge) removed -- seems no longer needed on more modern windows |
| 45 | #ifdef __PLATFORM_WINDOWS__ |
| 46 | #ifdef __CK_MATH_DEFINE_ROUND_TRUNC__ |
| 47 | double round( double a ); |
| 48 | double trunc( double a ); |
| 49 | #endif |
| 50 | #endif |
| 51 | |
| 52 | // 1.4.1.0 (ge) need this since remainder still not found (VC++ 2010) |
| 53 | double ck_remainder( double a, double b ); |
| 54 | |
| 55 | |
| 56 | // chuck random wrapper, return t_CKINT in [0,CK_RANDOM_MAX] |
| 57 | t_CKINT ck_random(); |
| 58 | // chuck random float wrapper, return t_CKFLOAT in [0,1] |
| 59 | t_CKFLOAT ck_random_f(); |
| 60 | // chuck srandom wrapper |
| 61 | void ck_srandom( unsigned seed ); |
| 62 | // randomizer wrapper (use this instead of seeding for initial) |
| 63 | void ck_randomize(); |
| 64 | |
| 65 | |
| 66 | //----------------------------------------------------------------------------- |
| 67 | #ifndef __OLDSCHOOL_RANDOM__ |
| 68 | //----------------------------------------------------------------------------- |
| 69 | #define CK_RANDOM_MAX 0x7fffffff |
| 70 | //----------------------------------------------------------------------------- |
| 71 | #else // __OLDSCHOOL_RANDOM__ (enable only for compatibility pre-c++11) |
| 72 | //----------------------------------------------------------------------------- |
| 73 | #ifndef __PLATFORM_WINDOWS__ |
| 74 | #define CK_RANDOM_MAX 0x7fffffff |
| 75 | #else // __PLATFORM_WINDOWS__ |
| 76 | #define CK_RANDOM_MAX RAND_MAX |
| 77 | #endif |
| 78 | //----------------------------------------------------------------------------- |
| 79 | #endif // __OLDSCHOOL_RANDOM__ |
| 80 | //----------------------------------------------------------------------------- |
| 81 | |
| 82 | |
| 83 | // mtof |
| 84 | double ck_mtof( double f ); |
| 85 | // ftom |
| 86 | double ck_ftom( double f ); |
| 87 | // powtodb |
| 88 | double ck_powtodb( double f ); |
| 89 | // rmstodb |
| 90 | double ck_rmstodb( double f ); |
| 91 | // dbtopow |
| 92 | double ck_dbtopow( double f ); |
| 93 | // dbtorms |
| 94 | double ck_dbtorms( double f ); |
| 95 | // nextpow2 |
| 96 | unsigned long ck_nextpow2( unsigned long i ); |
| 97 | // ensurepow2 |
| 98 | unsigned long ck_ensurepow2( unsigned long i ); |
| 99 | |
| 100 | // floating point equals |
| 101 | t_CKBOOL ck_equals( t_CKFLOAT lhs, t_CKFLOAT rhs ); |
| 102 | t_CKBOOL ck_equals_ex( t_CKFLOAT lhs, t_CKFLOAT rhs, t_CKFLOAT epsilon ); |
| 103 | // magnitude of complex number |
| 104 | t_CKFLOAT ck_complex_magnitude( const t_CKCOMPLEX & cmp ); |
| 105 | // phase of complex number |
| 106 | t_CKFLOAT ck_complex_phase( const t_CKCOMPLEX & cmp ); |
| 107 | // magnitude of vec2 |
| 108 | t_CKFLOAT ck_vec2_magnitude( const t_CKVEC2 & v ); |
| 109 | // phase of vec2 |
| 110 | t_CKFLOAT ck_vec2_phase( const t_CKVEC2 & v ); |
| 111 | // magnitude of vec3 |
| 112 | t_CKFLOAT ck_vec3_magnitude( const t_CKVEC3 & v ); |
| 113 | // magnitude of vec4 |
| 114 | t_CKFLOAT ck_vec4_magnitude( const t_CKVEC4 & v ); |
| 115 | // integer factorial (for up to 12! which is the largest factorial that can fit inside a 32-bit integer) |
| 116 | t_CKINT ck_factorial32( t_CKINT n ); |
| 117 | // associated legendre for spherical harmonics | (added) 1.5.5.8 by everett 2026 |
| 118 | t_CKFLOAT ck_associated_legendre( const t_CKINT m, const t_CKINT l, const t_CKFLOAT x ); |
| 119 | // spherical harmonics | (added) 1.5.5.8 by everett 2026 |
| 120 | void ck_SH( t_CKFLOAT* output, const t_CKUINT order_, const t_CKFLOAT azimuth_, const t_CKFLOAT zenith_, const t_CKBOOL n3d ); |
| 121 | |
| 122 | #if defined (__cplusplus) || defined(_cplusplus) |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | #endif |