2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef _dsp_filter_h_
20 #define _dsp_filter_h_
26 #include "ardour/libardour_visibility.h"
28 namespace ARDOUR { namespace DSP {
30 /** a convenience class for lua scripts to use C memory for DSP operations.
32 * It should be allocated during dsp_init() or dsp_configure().
40 assert (sizeof(float) == sizeof (int32_t));
41 assert (sizeof(float) == sizeof (int));
48 void allocate (size_t s) {
49 _data = realloc (_data, sizeof(float) * s);
50 if (_data) { _size = s; }
54 memset (_data, 0, sizeof(float) * _size);
57 float* to_float (size_t off) {
58 if (off >= _size) { return 0; }
59 return &(((float*)_data)[off]);
62 int32_t* to_int (size_t off) {
63 if (off >= _size) { return 0; }
64 return &(((int32_t*)_data)[off]);
67 void atomic_set_int (size_t off, int32_t val) {
68 g_atomic_int_set (&(((int32_t*)_data)[off]), val);
71 int32_t atomic_get_int (size_t off) {
72 return g_atomic_int_get (&(((int32_t*)_data)[off]));
80 void memset (float *data, const float val, const uint32_t n_samples);
81 void mmult (float *data, float *mult, const uint32_t n_samples);
82 void peaks (float *data, float &min, float &max, uint32_t n_samples);
84 float log_meter (float power);
85 float log_meter_coeff (float coeff);
87 class LIBARDOUR_API LowPass {
89 LowPass (double samplerate, float freq);
90 void proc (float *data, const uint32_t n_samples);
91 void ctrl (float *data, const float val, const uint32_t n_samples);
92 void set_cutoff (float freq);
93 void reset () { _z = 0.f; }
100 class LIBARDOUR_API BiQuad {
114 BiQuad (double samplerate);
115 BiQuad (const BiQuad &other);
117 void run (float *data, const uint32_t n_samples);
118 void compute (Type, double freq, double Q, double gain);
119 void reset () { _z1 = _z2 = 0.0; }
124 double _b0, _b1, _b2;