1 // ----------------------------------------------------------------------------
3 // Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
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 3 of the License, or
8 // (at your option) any later version.
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.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // ----------------------------------------------------------------------------
25 #include "zita-resampler/resampler-table.h"
27 using namespace ArdourZita;
29 Resampler_table *Resampler_table::_list = 0;
30 Resampler_mutex Resampler_table::_mutex;
32 static double sinc (double x)
35 if (x < 1e-6) return 1.0;
40 static double wind (double x)
43 if (x >= 1.0) return 0.0f;
45 return 0.384 + 0.500 * cos (x) + 0.116 * cos (2 * x);
48 Resampler_table::Resampler_table (double fr, unsigned int hl, unsigned int np)
59 _ctab = new float [hl * (np + 1)];
61 for (j = 0; j <= np; j++) {
62 t = (double) j / (double) np;
63 for (i = 0; i < hl; i++) {
64 p [hl - i - 1] = (float)(fr * sinc (t * fr) * wind (t / hl));
71 Resampler_table::~Resampler_table (void)
77 Resampler_table::create (double fr, unsigned int hl, unsigned int np)
84 if ((fr >= P->_fr * 0.999) && (fr <= P->_fr * 1.001) && (hl == P->_hl) && (np == P->_np)) {
91 P = new Resampler_table (fr, hl, np);
100 Resampler_table::destroy (Resampler_table *T)
102 Resampler_table *P, *Q;
112 if (Q) Q->_next = T->_next;
113 else _list = T->_next;