2 ==============================================================================
3 This file is part of Tal-Dub-III by Patrick Kunz.
5 Copyright(c) 2005-2009 Patrick Kunz, TAL
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
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
;
82 float getValueInDecibel(float inputValue
)
91 return 20.0f
* log10f(inputValue
/ 1.0f
);
95 float getValueInDecibelFilter(float inputValue
)
104 return 5.0f
* log10f(inputValue
/ 1.0f
);
108 inline float tanhApp(float 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
++;
126 inline bool isPrime(int value
)
129 if (value
== 0) value
= 1;
130 for (int i
= 2; i
<= sqrtf((float)value
) ; i
++)