|
libpsynth 0.2.1
|
00001 00012 /* 00013 * Copyright (C) 2007, 2009 Juan Pedro BolĂvar Puente 00014 * 00015 * This file is part of Psychosynth. 00016 * 00017 * Psychosynth is free software: you can redistribute it and/or modify 00018 * it under the terms of the GNU General Public License as published by 00019 * the Free Software Foundation, either version 3 of the License, or 00020 * (at your option) any later version. 00021 * 00022 * Psychosynth is distributed in the hope that it will be useful, 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 * GNU General Public License for more details. 00026 * 00027 * You should have received a copy of the GNU General Public License 00028 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00029 * 00030 */ 00031 00032 #ifndef PSYNTH_MISC_H 00033 #define PSYNTH_MISC_H 00034 00035 #include <string> 00036 00037 namespace psynth 00038 { 00039 namespace base 00040 { 00041 00042 template <class T> 00043 inline T clamp (T x, T min, T max) 00044 { 00045 return std::min (max, std::max (min, x)); 00046 } 00047 00051 template <typename T> 00052 inline T sign (T x) 00053 { 00054 return x > 0 ? +1 : (x < 0 ? -1 : 0); 00055 } 00056 00061 template <class T> 00062 inline T phase (T x) 00063 { 00064 return x - (x >= 0 ? 00065 static_cast<int>(x) : 00066 static_cast<int>(x) - 1); 00067 } 00068 00075 template <class T> 00076 inline T linear_interp (T val, T next, T delta) 00077 { 00078 return val + delta * (next - val); 00079 } 00080 00089 char* itoa (int val, int base); 00090 00099 char* ftoa (double f, double sigfigs); 00100 00106 int strcmp_i (const char* a, const char* b); 00107 00113 std::string dirname_str (std::string str); 00114 00120 const char* get_extension (const char* file); 00121 00122 } /* namespace base */ 00123 } /* namespace psynth */ 00124 00125 #endif /* PSYNTH_MISC_H */
1.7.4