2 * Copyright (C) 2003-2012 Fons Adriaensen <fons@kokkinizita.net>
3 * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
4 * Copyright (C) 2009-2015 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "ardour/mtdm.h"
27 MTDM::MTDM (int fsamp)
48 _wlp = 200.0f / fsamp;
49 for (i = 0, F = _freq; i < 13; i++, F++)
59 int MTDM::process (size_t len, float *ip, float *op)
62 float vip, vop, a, c, s;
71 if (fabsf(vip) > peak) { peak = vip; }
72 for (i = 0, F = _freq; i < 13; i++, F++)
74 a = 2 * (float) M_PI * (F->p & 65535) / 65536.0;
78 vop += (i ? 0.01f : 0.20f) * s;
85 for (i = 0, F = _freq; i < 13; i++, F++)
87 F->x1 += _wlp * (F->xa - F->x1 + 1e-20);
88 F->y1 += _wlp * (F->ya - F->y1 + 1e-20);
89 F->x2 += _wlp * (F->x1 - F->x2 + 1e-20);
90 F->y2 += _wlp * (F->y1 - F->y2 + 1e-20);
97 if (peak > _peak) { _peak = vip; }
103 int MTDM::resolve (void)
109 if (hypot (F->x2, F->y2) < 0.001) return -1;
110 d = atan2 (F->y2, F->x2) / (2 * M_PI);
112 if (d > 0.5) d -= 1.0;
116 for (i = 0; i < 12; i++)
119 p = atan2 (F->y2, F->x2) / (2 * M_PI) - d * F->f / f0;
123 k = (int)(floor (p + 0.5));
125 if (e > _err) _err = e;
126 if (e > 0.4) return 1;