Add TAL-Reverb-II plugin to test
[juce-lv2.git] / tal-reverb-2-juce / src / Engine / AudioUtils.h
blob51f489fc75c9077ed5fb7d9612576a012beb4772
1 /*
2 ==============================================================================
3 This file is part of Tal-Dub-III by Patrick Kunz.
5 Copyright(c) 2005-2009 Patrick Kunz, TAL
6 Togu Audio Line, Inc.
7 http://kunz.corrupt.ch
9 This file may be licensed under the terms of of the
10 GNU General Public License Version 2 (the ``GPL'').
12 Software distributed under the License is distributed
13 on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14 express or implied. See the GPL for the specific language
15 governing rights and limitations.
17 You should have received a copy of the GPL along with this
18 program. If not, go to http://www.gnu.org/licenses/gpl.html
19 or write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 ==============================================================================
25 #if !defined(__AudioUtils_h)
26 #define __AudioUtils_h
28 #include "Math.h"
30 class AudioUtils
32 private:
34 public:
35 AudioUtils()
39 ~AudioUtils()
43 float getLogScaledValueInDecibel(float inputValue, float maxValue)
45 float logScaled = getLogScaledVolume(inputValue, maxValue);
46 return getValueInDecibel(logScaled);
49 float getLogScaledValueInDecibelFilter(float inputValue, float maxValue)
51 float logScaled = getLogScaledVolume(inputValue, maxValue);
52 return getValueInDecibelFilter(logScaled);
55 // max value unscalled
56 float getLogScaledVolume(float inputValue, float maxValue)
58 return (expf(inputValue * maxValue * logf(20.0f)) - 1.0f) / 19.0f;
61 // max value unscalled
62 float getLogScaledValue(float inputValue)
64 // have to return a value between 0..1
65 return (expf(inputValue * logf(20.0f)) - 1.0f) / 19.0f;
68 float getLogScaledFrequency(float inputValue)
70 return 100.0f + getLogScaledValue(inputValue) * 9900.0f;
73 float getLogScaledValueInverted(float inputValue)
75 // have to return a value between 0..1
76 inputValue = 1.0f - inputValue;
77 inputValue = (expf(inputValue * logf(20.0f)) - 1.0f) / 19.0f;
78 return 1.0f - inputValue;
81 // input value >= 0
82 float getValueInDecibel(float inputValue)
84 if (inputValue <= 0)
86 return -96.0f;
88 else
90 // 1.0 --> 0dB
91 return 20.0f * log10f(inputValue / 1.0f);
95 float getValueInDecibelFilter(float inputValue)
97 if (inputValue <= 0)
99 return -18.0f;
101 else
103 // 1.0 --> 0dB
104 return 5.0f * log10f(inputValue / 1.0f);
108 inline float tanhApp(float x)
110 // Original
111 //return tanh(x);
113 // Approx
114 x*= 2.0f;
115 float a= fabs(x);
116 float b= 6.0f + a*(3.0f + a); // 6, 3
117 return (x * b)/(a * b + 12.0f);
120 inline int getNextNearPrime(int value)
122 while (!isPrime(value)) value++;
123 return value;
126 inline bool isPrime(int value)
128 bool answer = true;
129 if (value == 0) value = 1;
130 for (int i = 2; i <= sqrtf((float)value) ; i++)
132 if (value % i == 0)
134 answer = false;
135 break;
138 return answer;
141 #endif