2 Copyright (C) 2003-2012 Fons Adriaensen <fons@kokkinizita.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "ardour/mtdm.h"
24 MTDM::MTDM (int fsamp)
45 _wlp = 200.0f / fsamp;
46 for (i = 0, F = _freq; i < 13; i++, F++)
56 int MTDM::process (size_t len, float *ip, float *op)
59 float vip, vop, a, c, s;
68 if (fabsf(vip) > peak) { peak = vip; }
69 for (i = 0, F = _freq; i < 13; i++, F++)
71 a = 2 * (float) M_PI * (F->p & 65535) / 65536.0;
75 vop += (i ? 0.01f : 0.20f) * s;
82 for (i = 0, F = _freq; i < 13; i++, F++)
84 F->x1 += _wlp * (F->xa - F->x1 + 1e-20);
85 F->y1 += _wlp * (F->ya - F->y1 + 1e-20);
86 F->x2 += _wlp * (F->x1 - F->x2 + 1e-20);
87 F->y2 += _wlp * (F->y1 - F->y2 + 1e-20);
94 if (peak > _peak) { _peak = vip; }
100 int MTDM::resolve (void)
106 if (hypot (F->x2, F->y2) < 0.001) return -1;
107 d = atan2 (F->y2, F->x2) / (2 * M_PI);
109 if (d > 0.5) d -= 1.0;
113 for (i = 0; i < 12; i++)
116 p = atan2 (F->y2, F->x2) / (2 * M_PI) - d * F->f / f0;
120 k = (int)(floor (p + 0.5));
122 if (e > _err) _err = e;
123 if (e > 0.4) return 1;