You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 lines
463 B

#ifndef __UTIL_H__
#define __UTIL_H__
#include <cmath>
inline float clamp(float x, float a, float b) {
return fminf(b, fmaxf(a, x));
}
inline float dBToGain(float dB) {
return pow(10, dB / 20.0);
}
inline float noteToFreq(float note) {
return 440 * pow(2, (note - 69) / 12.0);
}
inline float triangle(float phase) {
if(phase < M_PI) {
return phase / M_PI_2 - 1;
} else {
return 1 - (phase - M_PI) / M_PI_2;
}
}
#endif