Remove unused fluidsynth setting (since fluidsynth 2.0)
[ardour.git] / libs / ardour / iec1ppmdsp.cc
1 /*
2     Copyright (C) 2012 Fons Adriaensen <fons@linuxaudio.org>
3     Adopted for Ardour 2013 by Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <math.h>
21 #include "ardour/iec1ppmdsp.h"
22
23 float Iec1ppmdsp::_w1;
24 float Iec1ppmdsp::_w2;
25 float Iec1ppmdsp::_w3;
26 float Iec1ppmdsp::_g;
27
28 Iec1ppmdsp::Iec1ppmdsp (void)
29         : _z1 (0)
30         , _z2 (0)
31         , _m (0)
32         , _res (true)
33 {}
34
35 Iec1ppmdsp::~Iec1ppmdsp (void) {}
36
37 void
38 Iec1ppmdsp::process (float const* p, int n)
39 {
40         float z1, z2, m, t;
41
42         z1 = _z1 > 20 ? 20 : (_z1 < 0 ? 0 : _z1);
43         z2 = _z2 > 20 ? 20 : (_z2 < 0 ? 0 : _z2);
44         m = _res ? 0: _m;
45         _res = false;
46
47         n /= 4;
48         while (n--) {
49                 z1 *= _w3;
50                 z2 *= _w3;
51                 t = fabsf (*p++);
52                 if (t > z1) z1 += _w1 * (t - z1);
53                 if (t > z2) z2 += _w2 * (t - z2);
54                 t = fabsf (*p++);
55                 if (t > z1) z1 += _w1 * (t - z1);
56                 if (t > z2) z2 += _w2 * (t - z2);
57                 t = fabsf (*p++);
58                 if (t > z1) z1 += _w1 * (t - z1);
59                 if (t > z2) z2 += _w2 * (t - z2);
60                 t = fabsf (*p++);
61                 if (t > z1) z1 += _w1 * (t - z1);
62                 if (t > z2) z2 += _w2 * (t - z2);
63                 t = z1 + z2;
64                 if (t > m) m = t;
65         }
66
67         _z1 = z1 + 1e-10f;
68         _z2 = z2 + 1e-10f;
69         _m = m;
70 }
71
72 float
73 Iec1ppmdsp::read (void)
74 {
75         _res = true;
76         return _g * _m;
77 }
78
79 void
80 Iec1ppmdsp::reset ()
81 {
82         _z1 = _z2 = _m = .0f;
83         _res = true;
84 }
85
86 void
87 Iec1ppmdsp::init (float fsamp)
88 {
89         _w1 =  450.0f / fsamp;
90         _w2 = 1300.0f / fsamp;
91         _w3 = 1.0f - 5.4f / fsamp;
92         _g  = 0.5108f;
93 }