1 // ----------------------------------------------------------------------------
3 // Copyright (C) 2013 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/cresampler.h"
27 using namespace ArdourZita;
29 CResampler::CResampler (void)
36 CResampler::~CResampler (void)
42 CResampler::setup (double ratio,
45 if (! nchan) return 1;
48 _buff = new float [nchan * (3 + _inmax)];
55 CResampler::clear (void)
66 CResampler::set_phase (double p)
68 _phase = p - floor (p);
72 CResampler::set_ratio (double r)
78 CResampler::inpdist (void) const
80 return (int)(3 - _nread) - _phase;
84 CResampler::inpsize (void) const
90 CResampler::reset (void)
104 CResampler::process (void)
106 unsigned int in, nr, n, c;
109 float *pb, a, b, d, m0, m1, m2, m3;
115 pb = _buff + in * _nchan;
119 if (inp_count == 0) break;
120 n = (4 - nr) * _nchan;
122 for (c = 0; c < _nchan; c++) pb [n + c] = inp_data [c];
126 for (c = 0; c < _nchan; c++) pb [n + c] = 0;
139 m1 = b + (3 * b - 1) * d;
140 m2 = a + (3 * a - 1) * d;
142 for (c = 0; c < n; c++) {
143 *out_data++ = m0 * pb [0]
151 for (c = 0; c < n; c++) *out_data++ = 0;
158 nr = (unsigned int) floor (ph);
163 memcpy (_buff, pb, (4 - nr) * _nchan * sizeof (float));