summaryrefslogtreecommitdiffstats
path: root/lib/reverb/basics.h
diff options
context:
space:
mode:
authorRJ Ryan <rryan@mixxx.org>2015-06-09 22:50:53 -0400
committerRJ Ryan <rryan@mixxx.org>2015-06-09 22:52:10 -0400
commit2480715617c48bb2a351ea22880526fb24920c62 (patch)
treea6e72ca178b5b29b9989807ef0649a0b68274355 /lib/reverb/basics.h
parent56f586470db4b88b2c812982da8ae119f541257d (diff)
Move reverb plugin to lib/reverb.
Diffstat (limited to 'lib/reverb/basics.h')
-rw-r--r--lib/reverb/basics.h161
1 files changed, 161 insertions, 0 deletions
diff --git a/lib/reverb/basics.h b/lib/reverb/basics.h
new file mode 100644
index 0000000000..36275ae796
--- /dev/null
+++ b/lib/reverb/basics.h
@@ -0,0 +1,161 @@
+/*
+ basics.h
+
+ Copyright 2004-12 Tim Goetze <tim@quitte.de>
+
+ http://quitte.de/dsp/
+
+ Common constants, typedefs, utility functions
+ and simplified LADSPA #defines.
+
+ Some code removed by Owen Williams for port to Mixxx, mostly ladspa-specific
+ defines and i386 customizations.
+
+*/
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA or point your web browser to http://www.gnu.org.
+*/
+
+#ifndef _BASICS_H_
+#define _BASICS_H_
+
+// NOTE(rryan): 3/2014 Added for MSVC support. (missing M_PI)
+#define _USE_MATH_DEFINES
+#include <cmath>
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <math.h>
+#include <float.h>
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "util/types.h"
+typedef CSAMPLE sample_t;
+
+// NOTE(rryan): 3/2014 Added these for the MSVC build.
+#include <QtGlobal>
+typedef qint8 int8;
+typedef quint8 uint8;
+typedef qint16 int16;
+typedef quint16 uint16;
+typedef qint32 int32;
+typedef quint32 uint32;
+typedef qint64 int64;
+typedef quint64 uint64;
+
+#define MIN_GAIN .000001 /* -120 dB */
+/* smallest non-denormal 32 bit IEEE float is 1.18e-38 */
+#define NOISE_FLOOR .00000000000005 /* -266 dB */
+
+/* //////////////////////////////////////////////////////////////////////// */
+
+typedef unsigned int uint;
+typedef unsigned long ulong;
+
+/* prototype that takes a sample and yields a sample */
+typedef CSAMPLE (*clip_func_t) (CSAMPLE);
+
+/* flavours for sample store functions run() and run_adding() */
+typedef void (*yield_func_t) (CSAMPLE *, uint, CSAMPLE, CSAMPLE);
+
+inline void
+adding_func (CSAMPLE * s, uint i, CSAMPLE x, CSAMPLE gain)
+{
+ s[i] += gain * x;
+}
+
+#ifndef max
+
+template <class X, class Y>
+X min (X x, Y y)
+{
+ return x < y ? x : (X) y;
+}
+
+template <class X, class Y>
+X max (X x, Y y)
+{
+ return x > y ? x : (X) y;
+}
+
+#endif /* ! max */
+
+template <class T>
+T clamp (T value, T lower, T upper)
+{
+ if (value < lower) return lower;
+ if (value > upper) return upper;
+ return value;
+}
+
+static inline float
+frandom()
+{
+ return (float) rand() / (float) RAND_MAX;
+}
+
+/* NB: also true if 0 */
+inline bool
+is_denormal (float & f)
+{
+ int32 i = *((int32 *) &f);
+ return ((i & 0x7f800000) == 0);
+}
+
+/* not used, check validity before using */
+inline bool
+is_denormal (double & f)
+{
+ int64 i = *((int64 *) &f);
+ return ((i & 0x7fe0000000000000ll) == 0);
+}
+
+/* lovely algorithm from
+ http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2Float
+*/
+inline uint
+next_power_of_2 (uint n)
+{
+ assert (n <= 0x40000000);
+
+ --n;
+ n |= n >> 1;
+ n |= n >> 2;
+ n |= n >> 4;
+ n |= n >> 8;
+ n |= n >> 16;
+
+ return ++n;
+}
+
+inline double
+db2lin (double db)
+{
+ return pow(10, db*.05);
+}
+
+inline double
+lin2db (double lin)
+{
+ return 20*log10(lin);
+}
+
+/* //////////////////////////////////////////////////////////////////////// */
+
+#endif /* _BASICS_H_ */