![]() |
pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
|
00001 /* 00002 ------------------------------------------------------------------------------- 00003 This file is part of the Plink, Plonk, Plank libraries 00004 by Martin Robinson 00005 00006 http://code.google.com/p/pl-nk/ 00007 00008 Copyright University of the West of England, Bristol 2011-14 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 * Redistributions of source code must retain the above copyright 00015 notice, this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright 00017 notice, this list of conditions and the following disclaimer in the 00018 documentation and/or other materials provided with the distribution. 00019 * Neither the name of University of the West of England, Bristol nor 00020 the names of its contributors may be used to endorse or promote products 00021 derived from this software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 This software makes use of third party libraries. For more information see: 00035 doc/license.txt included in the distribution. 00036 ------------------------------------------------------------------------------- 00037 */ 00038 00039 #ifndef PLANK_MATHS_H 00040 #define PLANK_MATHS_H 00041 00042 00048 //3.14159265358979323846264338327950288419716939937510 00049 #define PLANK_PI_D 3.1415926535897932384626433832795 00050 #define PLANK_PI_F 3.14159265358979323846f 00051 #define PLANK_SQRT2_D 1.41421356237309514547462185873883 00052 #define PLANK_SQRT2_F 1.41421356237309514547f 00053 #define PLANK_BILLION_D 1000000000.0 00054 #define PLANK_BILLION_F 1000000000.f 00055 #define PLANK_MILLION_D 1000000.0 00056 #define PLANK_MILLION_F 1000000.f 00057 #define PLANK_440_D 440.0 00058 #define PLANK_440_F 440.f 00059 #define PLANK_360_D 360.0 00060 #define PLANK_360_F 360.f 00061 #define PLANK_69_D 69.0 00062 #define PLANK_69_F 69.f 00063 #define PLANK_20_D 20.0 00064 #define PLANK_20_F 20.f 00065 #define PLANK_12_D 12.0 00066 #define PLANK_12_F 12.f 00067 #define PLANK_2_D 2.0 00068 #define PLANK_2_F 2.f 00069 #define PLANK_1_D 1.0 00070 #define PLANK_1_F 1.f 00071 #define PLANK_0_D 0.0 00072 #define PLANK_0_F 0.f 00073 00074 #define PLANK_CHARPEAK_I CHAR_MAX 00075 #define PLANK_CHARPEAK_F ((float)PLANK_CHARPEAK_I) 00076 #define PLANK_CHARPEAK_D ((double)PLANK_CHARPEAK_I) 00077 00078 #define PLANK_SHORTPEAK_I SHRT_MAX 00079 #define PLANK_SHORTPEAK_F ((float)PLANK_SHORTPEAK_I) 00080 #define PLANK_SHORTPEAK_D ((double)PLANK_SHORTPEAK_I) 00081 00082 #define PLANK_INTPEAK_I INT_MAX 00083 #define PLANK_INTPEAK_F ((float)PLANK_INTPEAK_I) 00084 #define PLANK_INTPEAK_D ((double)PLANK_INTPEAK_I) 00085 00086 #define PLANK_INT24PEAK_I PLANK_INT24_MAX 00087 #define PLANK_INT24PEAK_F ((float)PLANK_INT24PEAK_I) 00088 #define PLANK_INT24PEAK_D ((double)PLANK_INT24PEAK_I) 00089 00090 00091 #if (defined (_WIN32) || defined (_WIN64)) 00092 // #define PLANK_INC(a) a = a + 1 00093 #define PLANK_INC(a) ++a 00094 #else 00095 #define PLANK_INC(a) ++a 00096 #endif 00097 00098 PLANK_BEGIN_C_LINKAGE 00099 00100 PlankB pl_IsInfF (float a); 00101 PlankB pl_IsInfD (double a); 00102 PlankB pl_IsNanF (float a); 00103 PlankB pl_IsNanD (double a); 00104 00105 PLANK_END_C_LINKAGE 00106 00107 00108 //#if (defined (_WIN32) || defined (_WIN64)) 00109 //static inline PlankB pl_IsInfF (float a) { return _finite ((double)a) == 0; } 00110 //static inline PlankB pl_IsInfD (double a) { return _finite (a) == 0; } 00111 //static inline PlankB pl_IsNanF (float a) { return _isnan ((double)a) != 0; } 00112 //static inline PlankB pl_IsNanD (double a) { return _isnan (a) != 0; } 00113 //#else 00114 //static inline PlankB pl_IsInfF (float a) { return isinf (a); } 00115 //static inline PlankB pl_IsInfD (double a) { return isinf (a); } 00116 //static inline PlankB pl_IsNanF (float a) { return isnan (a); } 00117 //static inline PlankB pl_IsNanD (double a) { return isnan (a); } 00118 //#endif 00119 00120 00121 // unary ops 00122 00125 static inline float pl_MoveF (float a) { return a; } 00128 static inline double pl_MoveD (double a) { return a; } 00129 00130 static inline float pl_IncF (float a) { return a + 1.f; } 00131 static inline double pl_IncD (double a) { return a + 1.0; } 00132 00133 static inline float pl_DecF (float a) { return a - 1.f; } 00134 static inline double pl_DecD (double a) { return a - 1.0; } 00135 00136 00138 static inline float pl_NegF (float a) { return -a; } 00140 static inline double pl_NegD (double a) { return -a; } 00141 00142 00144 static inline float pl_AbsF (float a) { return fabsf (a); } 00146 static inline double pl_AbsD (double a) { return fabs (a); } 00147 00148 00149 00150 #if PLANK_WIN || PLANK_ANDROID 00151 static inline float pl_Log2F (float a) { return logf (a) / logf (2.f); } 00152 static inline double pl_Log2D (double a) { return log (a) / log (2.0); } 00153 #else 00154 00155 static inline float pl_Log2F (float a) { return log2f (a); } 00157 static inline double pl_Log2D (double a) { return log2 (a); } 00158 #endif 00159 00161 static inline float pl_ReciprocalF (float a) { return 1.f / a; } 00163 static inline double pl_ReciprocalD (double a) { return 1.0 / a; } 00164 00166 static inline float pl_SinF (float a) { return sinf (a); } 00168 static inline double pl_SinD (double a) { return sin (a); } 00169 00171 static inline float pl_CosF (float a) { return cosf (a); } 00173 static inline double pl_CosD (double a) { return cos (a); } 00174 00176 static inline float pl_TanF (float a) { return tanf (a); } 00178 static inline double pl_TanD (double a) { return tan (a); } 00179 00181 static inline float pl_AsinF (float a) { return asinf (a); } 00183 static inline double pl_AsinD (double a) { return asin (a); } 00184 00186 static inline float pl_AcosF (float a) { return acosf (a); } 00188 static inline double pl_AcosD (double a) { return acos (a); } 00189 00191 static inline float pl_AtanF (float a) { return atanf (a); } 00193 static inline double pl_AtanD (double a) { return atan (a); } 00194 00196 static inline float pl_SinhF (float a) { return sinhf (a); } 00198 static inline double pl_SinhD (double a) { return sinh (a); } 00199 00201 static inline float pl_CoshF (float a) { return coshf (a); } 00203 static inline double pl_CoshD (double a) { return cosh (a); } 00204 00206 static inline float pl_TanhF (float a) { return tanhf (a); } 00208 static inline double pl_TanhD (double a) { return tanh (a); } 00209 00211 static inline float pl_SqrtF (float a) { return sqrtf (a); } 00213 static inline double pl_SqrtD (double a) { return sqrt (a); } 00214 00216 static inline float pl_LogF (float a) { return logf (a); } 00218 static inline double pl_LogD (double a) { return log (a); } 00219 00221 static inline float pl_Log10F (float a) { return log10f (a); } 00223 static inline double pl_Log10D (double a) { return log10 (a); } 00224 00226 static inline float pl_ExpF (float a) { return expf (a); } 00228 static inline double pl_ExpD (double a) { return exp (a); } 00229 00231 static inline float pl_SquaredF (float a) { return a * a; } 00233 static inline double pl_SquaredD (double a) { return a * a; } 00234 00236 static inline float pl_CubedF (float a) { return a * a * a; } 00238 static inline double pl_CubedD (double a) { return a * a * a; } 00239 00241 static inline float pl_CeilF (float a) { return ceilf (a); } 00243 static inline double pl_CeilD (double a) { return ceil (a); } 00244 00246 static inline float pl_FloorF (float a) { return floorf (a); } 00248 static inline double pl_FloorD (double a) { return floor (a); } 00249 00251 static inline float pl_FracF (float a) { return a - floorf (a); } 00253 static inline double pl_FracD (double a) { return a - floor (a); } 00254 00256 static inline float pl_SignF (float a) { return (a == 0.f) ? 0.f : (a < 0.f) ? -1.f : 1.f; } 00258 static inline double pl_SignD (double a) { return (a == 0.0) ? 0.0 : (a < 0.0) ? -1.0 : 1.0; } 00259 00261 static inline float pl_M2FF (float a) { return 440.f * powf(2.f, (a - 69.f) * (1.f / 12.f)); } 00263 static inline double pl_M2FD (double a) { return 440.0 * pow (2.0, (a - 69.0) * (1.0 / 12.0)); } 00264 00266 static inline float pl_F2MF (float a) { return pl_Log2F (a * (1.f / 440.f)) * 12.f + 69.f; } 00268 static inline double pl_F2MD (double a) { return pl_Log2D (a * (1.0 / 440.0)) * 12.0 + 69.0; } 00269 00271 static inline float pl_A2dBF (float a) { return log10f(a) * 20.f; } 00273 static inline double pl_A2dBD (double a) { return log10 (a) * 20.0; } 00274 00276 static inline float pl_dB2AF (float a) { return powf(10.f, a * (1.f / 20.f)); } 00278 static inline double pl_dB2AD (double a) { return pow (10.0, a * (1.0 / 20.0)); } 00279 00281 static inline float pl_D2RF (float a) { return a * (1.f / 360.f) * PLANK_PI_F; } 00283 static inline double pl_D2RD (double a) { return a * (1.0 / 360.0) * PLANK_PI_D; } 00284 00286 static inline float pl_R2DF (float a) { return a * (1.f / PLANK_PI_F) * 360.f; } 00288 static inline double pl_R2DD (double a) { return a * (1.0 / PLANK_PI_D) * 360.0; } 00289 00291 static inline float pl_DistortF (float a) { return a / (1.f + fabsf(a)); } 00293 static inline double pl_DistortD (double a) { return a / (1.0 + fabs (a)); } 00294 00297 static inline float pl_ZapF (float x) 00298 { 00299 float absx = pl_AbsF (x); 00300 return (absx > (float)1e-15 && absx < (float)1e15) ? x : 0.f; 00301 } 00302 00304 static inline double pl_ZapD (double x) 00305 { 00306 double absx = pl_AbsD (x); 00307 return (absx > 1e-15 && absx < 1e15) ? x : 0.0; 00308 } 00309 00310 00311 // binary ops 00312 00313 00315 static inline float pl_AddF (float a, float b) { return a + b; } 00317 static inline double pl_AddD (double a, double b) { return a + b; } 00318 00320 static inline float pl_SubF (float a, float b) { return a - b; } 00322 static inline double pl_SubD (double a, double b) { return a - b; } 00323 00325 static inline float pl_MulF (float a, float b) { return a * b; } 00327 static inline double pl_MulD (double a, double b) { return a * b; } 00328 00330 static inline float pl_DivF (float a, float b) { return a / b; } 00332 static inline double pl_DivD (double a, double b) { return a / b; } 00333 00335 static inline float pl_ModF (float a, float b) { return fmodf (a, b); } 00337 static inline double pl_ModD (double a, double b) { return fmod (a, b); } 00338 00339 00341 static inline float pl_MinF (float a, float b) { return (a > b) ? b : a; } 00343 static inline double pl_MinD (double a, double b) { return (a > b) ? b : a; } 00344 00346 static inline float pl_MaxF (float a, float b) { return (a < b) ? b : a; } 00348 static inline double pl_MaxD (double a, double b) { return (a < b) ? b : a; } 00349 00350 00352 static inline float pl_PowF (float a, float b) { return powf(a, b); } 00354 static inline double pl_PowD (double a, double b) { return pow (a, b); } 00355 00357 static inline float pl_IsEqualToF (float a, float b) { return (a == b) ? 1.f : 0.f; } 00359 static inline double pl_IsEqualToD (double a, double b) { return (a == b) ? 1.0 : 0.0; } 00360 00362 static inline float pl_IsNotEqualToF (float a, float b) { return (a != b) ? 1.f : 0.f; } 00364 static inline double pl_IsNotEqualToD (double a, double b) { return (a != b) ? 1.0 : 0.0; } 00365 00367 static inline float pl_IsGreaterThanF (float a, float b) { return (a > b) ? 1.f : 0.f; } 00369 static inline double pl_IsGreaterThanD (double a, double b) { return (a > b) ? 1.0 : 0.0; } 00370 00372 static inline float pl_IsGreaterThanOrEqualToF (float a, float b) { return (a >= b) ? 1.f : 0.f; } 00374 static inline double pl_IsGreaterThanOrEqualToD (double a, double b) { return (a >= b) ? 1.0 : 0.0; } 00375 00377 static inline float pl_IsLessThanF (float a, float b) { return (a < b) ? 1.f : 0.f; } 00379 static inline double pl_IsLessThanD (double a, double b) { return (a < b) ? 1.0 : 0.0; } 00380 00382 static inline float pl_IsLessThanOrEqualToF (float a, float b) { return (a <= b) ? 1.f : 0.f; } 00384 static inline double pl_IsLessThanOrEqualToD (double a, double b) { return (a <= b) ? 1.0 : 0.0; } 00385 00387 static inline float pl_HypotF (float a, float b) { return hypotf(a, b); } 00389 static inline double pl_HypotD (double a, double b) { return hypot (a, b); } 00390 00392 static inline float pl_Atan2F (float a, float b) { return atan2f(a, b); } 00394 static inline double pl_Atan2D (double a, double b) { return atan2 (a, b); } 00395 00397 static inline float pl_SumSqrF (float a, float b) { return a * a + b * b; } 00399 static inline double pl_SumSqrD (double a, double b) { return a * a + b * b; } 00400 00402 static inline float pl_DifSqrF (float a, float b) { return a * a - b * b; } 00404 static inline double pl_DifSqrD (double a, double b) { return a * a - b * b; } 00405 00407 static inline float pl_SqrSumF (float a, float b) { a += b; return a * a; } 00409 static inline double pl_SqrSumD (double a, double b) { a += b; return a * a; } 00410 00412 static inline float pl_SqrDifF (float a, float b) { a -= b; return a * a; } 00414 static inline double pl_SqrDifD (double a, double b) { a -= b; return a * a; } 00415 00417 static inline float pl_AbsDifF (float a, float b) { return fabsf (a - b); } 00419 static inline double pl_AbsDifD (double a, double b) { return fabs (a - b); } 00420 00422 static inline float pl_ThreshF (float a, float b) { return (a < b) ? 0.f : a; } 00424 static inline double pl_ThreshD (double a, double b) { return (a < b) ? 0.0 : a; } 00425 00426 00427 // integer versions 00428 00429 static inline short pl_MoveS (short a) { return a; } 00430 static inline int pl_MoveI (int a) { return a; } 00431 static inline PlankLL pl_MoveLL (PlankLL a) { return a; } 00432 static inline short pl_IncS (short a) { return a + 1; } 00433 static inline int pl_IncI (int a) { return a + 1; } 00434 static inline PlankLL pl_IncLL (PlankLL a) { return a + 1; } 00435 static inline short pl_DecS (short a) { return a - 1; } 00436 static inline int pl_DecI (int a) { return a - 1; } 00437 static inline PlankLL pl_DecLL (PlankLL a) { return a - 1; } 00438 static inline short pl_NegS (short a) { return -a; } 00439 static inline int pl_NegI (int a) { return -a; } 00440 static inline PlankLL pl_NegLL (PlankLL a) { return -a; } 00441 static inline short pl_AbsS (short a) { return a < 0 ? -a : a; } 00442 static inline int pl_AbsI (int a) { return a < 0 ? -a : a; } 00443 static inline PlankLL pl_AbsLL (PlankLL a) { return a < 0 ? -a : a; } 00444 static inline short pl_SquaredS (short a) { return a * a; } 00445 static inline int pl_SquaredI (int a) { return a * a; } 00446 static inline PlankLL pl_SquaredLL (PlankLL a) { return a * a; } 00447 static inline short pl_CubedS (short a) { return a * a * a; } 00448 static inline int pl_CubedI (int a) { return a * a * a; } 00449 static inline PlankLL pl_CubedLL (PlankLL a) { return a * a * a; } 00450 static inline short pl_SignS (short a) { return (a == 0) ? 0 : (a < 0) ? -1 : 1; } 00451 static inline int pl_SignI (int a) { return (a == 0) ? 0 : (a < 0) ? -1 : 1; } 00452 static inline PlankLL pl_SignLL (PlankLL a) { return (a == 0) ? 0 : (a < 0) ? -1 : 1; } 00453 static inline short pl_AddS (short a, short b) { return a + b; } 00454 static inline int pl_AddI (int a, int b) { return a + b; } 00455 static inline PlankLL pl_AddLL (PlankLL a, PlankLL b) { return a + b; } 00456 static inline short pl_SubS (short a, short b) { return a - b; } 00457 static inline int pl_SubI (int a, int b) { return a - b; } 00458 static inline PlankLL pl_SubLL (PlankLL a, PlankLL b) { return a - b; } 00459 static inline short pl_MulS (short a, short b) { return a * b; } 00460 static inline int pl_MulI (int a, int b) { return a * b; } 00461 static inline PlankLL pl_MulLL (PlankLL a, PlankLL b) { return a * b; } 00462 static inline short pl_DivS (short a, short b) { return a / b; } 00463 static inline int pl_DivI (int a, int b) { return a / b; } 00464 static inline PlankLL pl_DivLL (PlankLL a, PlankLL b) { return a / b; } 00465 static inline short pl_ModS (short a, short b) { return a % b; } 00466 static inline int pl_ModI (int a, int b) { return a % b; } 00467 static inline PlankLL pl_ModLL (PlankLL a, PlankLL b) { return a % b; } 00468 00469 static inline PlankS pl_MinS (PlankS a, PlankS b) { return (a > b) ? b : a; } 00470 static inline PlankI pl_MinI (PlankI a, PlankI b) { return (a > b) ? b : a; } 00471 static inline PlankLL pl_MinLL (PlankLL a, PlankLL b) { return (a > b) ? b : a; } 00472 static inline PlankS pl_MaxS (PlankS a, PlankS b) { return (a < b) ? b : a; } 00473 static inline PlankI pl_MaxI (PlankI a, PlankI b) { return (a < b) ? b : a; } 00474 static inline PlankLL pl_MaxLL (PlankLL a, PlankLL b) { return (a < b) ? b : a; } 00475 00476 static inline PlankUS pl_MinUS (PlankUS a, PlankUS b) { return (a > b) ? b : a; } 00477 static inline PlankUI pl_MinUI (PlankUI a, PlankUI b) { return (a > b) ? b : a; } 00478 static inline PlankULL pl_MinULL (PlankULL a, PlankULL b) { return (a > b) ? b : a; } 00479 static inline PlankUS pl_MaxUS (PlankUS a, PlankUS b) { return (a < b) ? b : a; } 00480 static inline PlankUI pl_MaxUI (PlankUI a, PlankUI b) { return (a < b) ? b : a; } 00481 static inline PlankULL pl_MaxULL (PlankULL a, PlankULL b) { return (a < b) ? b : a; } 00482 00483 static inline short pl_IsEqualToS (short a, short b) { return a == b ? 1 : 0; } 00484 static inline int pl_IsEqualToI (int a, int b) { return a == b ? 1 : 0; } 00485 static inline PlankLL pl_IsEqualToLL (PlankLL a, PlankLL b) { return a == b ? 1 : 0; } 00486 static inline short pl_IsNotEqualToS (short a, short b) { return a != b ? 1 : 0; } 00487 static inline int pl_IsNotEqualToI (int a, int b) { return a != b ? 1 : 0; } 00488 static inline PlankLL pl_IsNotEqualToLL (PlankLL a, PlankLL b) { return a != b ? 1 : 0; } 00489 static inline short pl_IsGreaterThanS (short a, short b) { return a > b ? 1 : 0; } 00490 static inline int pl_IsGreaterThanI (int a, int b) { return a > b ? 1 : 0; } 00491 static inline PlankLL pl_IsGreaterThanLL (PlankLL a, PlankLL b) { return a > b ? 1 : 0; } 00492 static inline short pl_IsGreaterThanOrEqualToS (short a, short b) { return a >= b ? 1 : 0; } 00493 static inline int pl_IsGreaterThanOrEqualToI (int a, int b) { return a >= b ? 1 : 0; } 00494 static inline PlankLL pl_IsGreaterThanOrEqualToLL (PlankLL a, PlankLL b) { return a >= b ? 1 : 0; } 00495 static inline short pl_IsLessThanS (short a, short b) { return a < b ? 1 : 0; } 00496 static inline int pl_IsLessThanI (int a, int b) { return a < b ? 1 : 0; } 00497 static inline PlankLL pl_IsLessThanLL (PlankLL a, PlankLL b) { return a < b ? 1 : 0; } 00498 static inline short pl_IsLessThanOrEqualToS (short a, short b) { return a <= b ? 1 : 0; } 00499 static inline int pl_IsLessThanOrEqualToI (int a, int b) { return a <= b ? 1 : 0; } 00500 static inline PlankLL pl_IsLessThanOrEqualToLL (PlankLL a, PlankLL b) { return a <= b ? 1 : 0; } 00501 00502 00503 static inline short pl_SumSqrS (short a, short b) { return a * a + b * b; } 00504 static inline int pl_SumSqrI (int a, int b) { return a * a + b * b; } 00505 static inline PlankLL pl_SumSqrLL (PlankLL a, PlankLL b) { return a * a + b * b; } 00506 00507 static inline short pl_DifSqrS (short a, short b) { return a * a - b * b; } 00508 static inline int pl_DifSqrI (int a, int b) { return a * a - b * b; } 00509 static inline PlankLL pl_DifSqrLL (PlankLL a, PlankLL b) { return a * a - b * b; } 00510 00511 static inline short pl_SqrSumS (short a, short b) { a += b; return a * a; } 00512 static inline int pl_SqrSumI (int a, int b) { a += b; return a * a; } 00513 static inline PlankLL pl_SqrSumLL (PlankLL a, PlankLL b) { a += b; return a * a; } 00514 00515 static inline short pl_SqrDifS (short a, short b) { a -= b; return a * a; } 00516 static inline int pl_SqrDifI (int a, int b) { a -= b; return a * a; } 00517 static inline PlankLL pl_SqrDifLL (PlankLL a, PlankLL b) { a -= b; return a * a; } 00518 00519 static inline short pl_AbsDifS (short a, short b) { return pl_AbsS (a - b); } 00520 static inline int pl_AbsDifI (int a, int b) { return pl_AbsI (a - b); } 00521 static inline PlankLL pl_AbsDifLL (PlankLL a, PlankLL b) { return pl_AbsLL (a - b); } 00522 00523 static inline short pl_ThreshS (float a, short b) { return (a < b) ? 0 : a; } 00524 static inline int pl_ThreshI (int a, int b) { return (a < b) ? 0 : a; } 00525 static inline PlankLL pl_ThreshLL (PlankLL a, PlankLL b) { return (a < b) ? 0 : a; } 00526 00527 00529 static inline PlankL pl_MinL (PlankL a, PlankL b) { return (a > b) ? b : a; } 00531 static inline PlankL pl_MaxL (PlankL a, PlankL b) { return (a < b) ? b : a; } 00532 00533 static inline float pl_ClipF (float a, float lo, float hi) { return pl_MinF (pl_MaxF (a, lo), hi); } 00534 static inline double pl_ClipD (double a, double lo, double hi) { return pl_MinD (pl_MaxD (a, lo), hi); } 00535 00536 static inline PlankI pl_ClipI (PlankI a, PlankI lo, PlankI hi) { return pl_MinI (pl_MaxI (a, lo), hi); } 00537 static inline PlankS pl_ClipS (PlankS a, PlankS lo, PlankS hi) { return pl_MinS (pl_MaxS (a, lo), hi); } 00538 static inline PlankL pl_ClipL (PlankL a, PlankL lo, PlankL hi) { return pl_MinL (pl_MaxL (a, lo), hi); } 00539 static inline PlankLL pl_ClipLL (PlankLL a, PlankLL lo, PlankLL hi) { return pl_MinLL (pl_MaxLL (a, lo), hi); } 00540 00541 //round 00542 //trunc 00543 //clip2 00544 //wrap? 00545 00546 // ternary 00547 00548 // quarternary 00549 00550 // quinary 00551 00559 static inline float pl_LinLinF (float input, 00560 float inLow, float inHigh, 00561 float outLow, float outHigh) 00562 { 00563 float inRange, outRange; 00564 inRange = inHigh - inLow; 00565 outRange = outHigh - outLow; 00566 return (input - inLow) * outRange / inRange + outLow; 00567 } 00568 00576 static inline double pl_LinLinD (double input, 00577 double inLow, double inHigh, 00578 double outLow, double outHigh) 00579 { 00580 double inRange, outRange; 00581 inRange = inHigh - inLow; 00582 outRange = outHigh - outLow; 00583 return (input - inLow) * outRange / inRange + outLow; 00584 } 00585 00595 static inline float pl_LinLin2F (float input, 00596 float inLow, float inRange, 00597 float outLow, float outRange) 00598 { 00599 return (input - inLow) * outRange / inRange + outLow; 00600 } 00601 00611 static inline double pl_LinLin2D (double input, 00612 double inLow, double inRange, 00613 double outLow, double outRange) 00614 { 00615 return (input - inLow) * outRange / inRange + outLow; 00616 } 00617 00626 static inline float pl_LinExpF (float input, 00627 float inLow, float inHigh, 00628 float outLow, float outHigh) 00629 { 00630 float outRatio, reciprocalInRange, inLowOverInRange; 00631 outRatio = outHigh / outLow; 00632 reciprocalInRange = 1.f / (inHigh - inLow); 00633 inLowOverInRange = reciprocalInRange * inLow; 00634 return outLow * powf (outRatio, input * reciprocalInRange - inLowOverInRange); 00635 } 00636 00645 static inline double pl_LinExpD (double input, 00646 double inLow, double inHigh, 00647 double outLow, double outHigh) 00648 { 00649 double outRatio, reciprocalInRange, inLowOverInRange; 00650 outRatio = outHigh / outLow; 00651 reciprocalInRange = 1.0 / (inHigh - inLow); 00652 inLowOverInRange = reciprocalInRange * inLow; 00653 return outLow * pow (outRatio, input * reciprocalInRange - inLowOverInRange); 00654 } 00655 00656 00657 //linsin 00658 //linwelch 00659 //explin 00660 00666 static inline float pl_LinInterpF (float a, float b, float frac) 00667 { 00668 return a + (frac * (b - a)); 00669 } 00670 00676 static inline double pl_LinInterpD (double a, double b, double frac) 00677 { 00678 return a + (frac * (b - a)); 00679 } 00680 00685 static inline float pl_LookupF (const float* table, float index) 00686 { 00687 int index0; 00688 float frac; 00689 index0 = (int)index; 00690 frac = index - (float)index0; 00691 return pl_LinInterpF (table[index0], table[index0 + 1], frac); 00692 } 00693 00698 static inline double pl_LookupD (const double* table, double index) 00699 { 00700 int index0; 00701 double frac; 00702 index0 = (int)index; 00703 frac = index - (double)index0; 00704 return pl_LinInterpD (table[index0], table[index0 + 1], frac); 00705 } 00706 00707 static inline short pl_LookupS (const short* table, short index) { return table[index]; } 00708 static inline int pl_LookupI (const int* table, int index) { return table[index]; } 00709 static inline PlankLL pl_LookupLL (const PlankLL* table, PlankLL index) { return table[index]; } 00710 00711 00712 static inline float pl_Lag3InterpF (float value_1, float value0, float value1, float value2, float frac) 00713 { 00714 float c0 = value0; 00715 float c1 = value1 - (1.f/3.f) * value_1 - 0.5f * value0 - (1.f/3.f) * value2; 00716 float c2 = 0.5f * (value_1 + value1) - value0; 00717 float c3 = (1.f/6.f) * (value2 - value_1) + 0.5f * (value0 - value1); 00718 return ((c3 * frac + c2) * frac + c1) * frac + c0; 00719 } 00720 00721 static inline float pl_LookupLag3F (const float* table, float index) 00722 { 00723 int index0, index1, index_1, index2; 00724 float frac; 00725 index0 = (int)index; 00726 index1 = index0 + 1; 00727 index_1 = index0 - 1; 00728 index2 = index1 + 1; 00729 frac = index - (float)index0; 00730 return pl_Lag3InterpF (table[index_1], table[index0], table[index1], table[index2], frac); 00731 } 00732 00733 00734 00736 00737 #endif // PLANK_MATHS_H 00738