LMMS
Loading...
Searching...
No Matches
basics.h
Go to the documentation of this file.
1/*
2 basics.h
3
4 Copyright 2004-9 Tim Goetze <tim@quitte.de>
5
6 http://quitte.de/dsp/
7
8 common constants, typedefs, utility functions
9 and simplified LADSPA #defines.
10
11*/
12/*
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 02111-1307, USA or point your web browser to http://www.gnu.org.
27*/
28
29#ifndef _BASICS_H_
30#define _BASICS_H_
31
32#define _GNU_SOURCE 1
33#define _USE_GNU 1
34
35/* unlocking some standard math calls. */
36#define __USE_ISOC99 1
37#define __USE_ISOC9X 1
38#define _ISOC99_SOURCE 1
39#define _ISOC9X_SOURCE 1
40
41#include <stdlib.h>
42#include <string.h>
43
44#ifndef _USE_MATH_DEFINES
45#define _USE_MATH_DEFINES
46#endif
47#include <math.h>
48
49#include <assert.h>
50#include <stdio.h>
51#include <stdint.h>
52
53#include <ladspa.h>
54
55/* reducing LADSPA_DEFINES_WITH_LOTS_OF_CHARACTERS_REALLY verbosity */
56#define BOUNDED (LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE)
57#define INTEGER LADSPA_HINT_INTEGER
58#define LOG LADSPA_HINT_LOGARITHMIC
59#define TOGGLE LADSPA_HINT_TOGGLED
60
61#define DEFAULT_0 LADSPA_HINT_DEFAULT_0
62#define DEFAULT_1 LADSPA_HINT_DEFAULT_1
63#define DEFAULT_100 LADSPA_HINT_DEFAULT_100
64#define DEFAULT_440 LADSPA_HINT_DEFAULT_440
65#define DEFAULT_MIN LADSPA_HINT_DEFAULT_MINIMUM
66#define DEFAULT_LOW LADSPA_HINT_DEFAULT_LOW
67#define DEFAULT_MID LADSPA_HINT_DEFAULT_MIDDLE
68#define DEFAULT_HIGH LADSPA_HINT_DEFAULT_HIGH
69#define DEFAULT_MAX LADSPA_HINT_DEFAULT_MAXIMUM
70
71#define INPUT LADSPA_PORT_INPUT
72#define OUTPUT LADSPA_PORT_OUTPUT
73#define AUDIO LADSPA_PORT_AUDIO
74#define CONTROL LADSPA_PORT_CONTROL
75
76#define HARD_RT LADSPA_PROPERTY_HARD_RT_CAPABLE
77
78#define TEN_TO_THE_SIXTH 1000000
79
80#define MIN_GAIN .000001 /* -120 dB */
81
82/* smallest non-denormal 32 bit IEEE float is 1.18×10^-38 */
83#define NOISE_FLOOR .00000000000005 /* -266 dB */
84
85typedef int8_t int8;
86typedef uint8_t uint8;
87typedef int16_t int16;
89typedef int32_t int32;
91typedef int64_t int64;
92typedef uint64_t uint64;
93
99
101typedef unsigned long ulong;
102
103/* flavours for sample store functions run() and run_adding() */
105
106inline void
108{
109 s[i] = x;
110}
111
112inline void
114{
115 s[i] += gain * x;
116}
117
118#ifndef max
119
120template <class X, class Y>
121X min (X x, Y y)
122{
123 return x < y ? x : (X) y;
124}
125
126template <class X, class Y>
127X max (X x, Y y)
128{
129 return x > y ? x : (X) y;
130}
131
132#endif /* ! max */
133
134template <class T>
135T clamp (T value, T lower, T upper)
136{
137 if (value < lower) return lower;
138 if (value > upper) return upper;
139 return value;
140}
141
142static inline float
144{
145 return (float) rand() / (float) RAND_MAX;
146}
147
148/* NB: also true if 0 */
149inline bool
150is_denormal (float & f)
151{
152 int32 i = *((int32 *) &f);
153 return ((i & 0x7f800000) == 0);
154}
155
156/* todo: not sure if this double version is correct, actually ... */
157inline bool
158is_denormal (double & f)
159{
160 int64 i = *((int64 *) &f);
161 return ((i & 0x7fe0000000000000ll) == 0);
162}
163
164#ifdef __i386__
165 #define TRAP asm ("int $3;")
166#else
167 #define TRAP
168#endif
169
170/* //////////////////////////////////////////////////////////////////////// */
171
172#define CAPS "C* "
173
174class Plugin {
175 public:
176 double fs; /* sample rate */
177 double adding_gain; /* for run_adding() */
178
179 int first_run; /* 1st block after activate(), do no parameter smoothing */
180 sample_t normal; /* renormal constant */
181
183 LADSPA_PortRangeHint * ranges; /* for getport() below */
184
185 public:
186 /* get port value, mapping inf or nan to 0 */
188 {
189 sample_t v = *ports[i];
190 return (isinf (v) || isnan(v)) ? 0 : v;
191 }
192
193 /* get port value and clamp to port range */
194 inline sample_t getport (int i)
195 {
198 return clamp (v, r.LowerBound, r.UpperBound);
199 }
200};
201
202#endif /* _BASICS_H_ */
unsigned long int ulong
Definition CarlaDefines.h:328
void(* sample_func_t)(sample_t *, int, sample_t, sample_t)
Definition basics.h:104
uint8_t uint8
Definition basics.h:86
LADSPA_Data sample_t
Definition basics.h:100
static float frandom()
Definition basics.h:143
int64_t int64
Definition basics.h:91
bool is_denormal(float &f)
Definition basics.h:150
int16_t int16
Definition basics.h:87
int8_t int8
Definition basics.h:85
T clamp(T value, T lower, T upper)
Definition basics.h:135
int32_t int32
Definition basics.h:89
uint64_t uint64
Definition basics.h:92
uint16_t uint16
Definition basics.h:88
void store_func(sample_t *s, int i, sample_t x, sample_t gain)
Definition basics.h:107
uint32_t uint32
Definition basics.h:90
void adding_func(sample_t *s, int i, sample_t x, sample_t gain)
Definition basics.h:113
Definition basics.h:174
int first_run
Definition basics.h:179
sample_t normal
Definition basics.h:180
sample_t ** ports
Definition basics.h:182
double adding_gain
Definition basics.h:177
sample_t getport_unclamped(int i)
Definition basics.h:187
LADSPA_PortRangeHint * ranges
Definition basics.h:183
double fs
Definition basics.h:176
sample_t getport(int i)
Definition basics.h:194
int y
Definition inflate.c:1588
unsigned v[N_MAX]
Definition inflate.c:1584
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
unsigned x[BMAX+1]
Definition inflate.c:1586
unsigned f
Definition inflate.c:1572
static PuglViewHint int value
Definition pugl.h:1708
struct _LADSPA_PortRangeHint LADSPA_PortRangeHint
int LADSPA_PortDescriptor
Definition ladspa.h:152
float LADSPA_Data
Definition ladspa.h:84
#define X(str)
Definition juce_LV2Common.h:197
unsigned short uint16_t
Definition mid.cpp:99
int int32_t
Definition mid.cpp:97
unsigned int uint32_t
Definition mid.cpp:100
short int16_t
Definition mid.cpp:96
unsigned char uint8_t
Definition mid.cpp:98
signed char int8_t
Definition mid.cpp:95
#define min(x, y)
Definition os.h:74
#define max(x, y)
Definition os.h:78
Definition basics.h:94
LADSPA_PortDescriptor descriptor
Definition basics.h:96
const char * name
Definition basics.h:95
LADSPA_PortRangeHint range
Definition basics.h:97
int r
Definition crypt.c:458
typedef int(UZ_EXP MsgFn)()
#define void
Definition unzip.h:396