LMMS
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/* utils.h
2
3 Computer Music Toolkit - a library of LADSPA plugins. Copyright (C)
4 2000 Richard W.E. Furse.
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public Licence as
8 published by the Free Software Foundation; either version 2 of the
9 Licence, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307, USA. */
20
21#ifndef CMT_UTILS_INCLUDED
22#define CMT_UTILS_INCLUDED
23
24/*****************************************************************************/
25
26#include <cmath>
27#include <cstdlib>
28
29/*****************************************************************************/
30
31#include "ladspa_types.h"
32
33/*****************************************************************************/
34
39inline LADSPA_Data
41 const LADSPA_Data fSampleRate) {
42 if (fTime <= 0)
43 return 0;
44 else
45 return pow(1e3, -1 / (fTime * fSampleRate));
46}
47
48/*****************************************************************************/
49
50inline LADSPA_Data
52 const LADSPA_Data fLowerBound) {
53 if (fData <= fLowerBound)
54 return fLowerBound;
55 else
56 return fData;
57}
58
60 const LADSPA_Data fUpperBound) {
61 if (fData >= fUpperBound)
62 return fUpperBound;
63 else
64 return fData;
65}
66
67inline LADSPA_Data
68BOUNDED(const LADSPA_Data fData,
69 const LADSPA_Data fLowerBound,
70 const LADSPA_Data fUpperBound) {
71 if (fData <= fLowerBound)
72 return fLowerBound;
73 else if (fData >= fUpperBound)
74 return fUpperBound;
75 else
76 return fData;
77}
78
79/*****************************************************************************/
80
81/* Take a reading from a normal RV. The algorithm works by repeated
82 sampling of the uniform distribution, the lQuality variable giving
83 the number of samples. */
84inline double
85sampleNormalDistribution(const double dMean,
86 const double dStandardDeviation,
87 const long lQuality = 12) {
88
89 double dValue = 0;
90 for (long lIter = 0; lIter < lQuality; lIter++)
91 dValue += rand();
92
93 double dSampleFromNormal01 = (dValue / RAND_MAX) - (lQuality * 0.5);
94
95 return dMean + dStandardDeviation * dSampleFromNormal01;
96}
97
98/*****************************************************************************/
99
100#endif
101
102/* EOF */
#define BOUNDED
Definition basics.h:56
LADSPA_Data BOUNDED_BELOW(const LADSPA_Data fData, const LADSPA_Data fLowerBound)
Definition utils.h:51
LADSPA_Data calculate60dBDrag(const LADSPA_Data fTime, const LADSPA_Data fSampleRate)
Definition utils.h:40
LADSPA_Data BOUNDED_ABOVE(const LADSPA_Data fData, const LADSPA_Data fUpperBound)
Definition utils.h:59
double sampleNormalDistribution(const double dMean, const double dStandardDeviation, const long lQuality=12)
Definition utils.h:85
float LADSPA_Data
Definition ladspa.h:84