BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

math.cpp (510B)


      1 
      2 #include <stdlib.h>
      3 #include <math.h>
      4 
      5 #include "math.hpp"
      6 
      7 using namespace bogaudio::dsp;
      8 
      9 void FastTanhf::TanhfTable::_generate() {
     10 	_table[0] = -1.0f;
     11 	_table[_length - 1] = 1.0f;
     12 	for (int i = 1, n = _length - 1; i < n; ++i) {
     13 		_table[i] = tanhf((((i / (float)_length) * 2.0f) - 1.0f) * M_PI);
     14 	}
     15 }
     16 
     17 float FastTanhf::value(float radians) {
     18 	if (radians <= -M_PI) {
     19 		return -1.0f;
     20 	}
     21 	if (radians >= M_PI) {
     22 		return 1.0f;
     23 	}
     24 	return _table.value(((radians + M_PI) / (2.0f * M_PI)) * _table.length());
     25 }