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 "cresampler.h"
28 CResampler::CResampler (void) :
36 CResampler::~CResampler (void)
42 int CResampler::setup (double ratio
,
45 if (! nchan
) return 1;
48 _buff
= new float [nchan
* (3 + _inmax
)];
55 void CResampler::clear (void)
66 void CResampler::set_phase (double p
)
68 _phase
= p
- floor (p
);
72 void CResampler::set_ratio (double r
)
78 double CResampler::inpdist (void) const
80 return (int)(3 - _nread
) - _phase
;
84 int CResampler::inpsize (void) const
90 int CResampler::reset (void)
104 int 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
;
121 if (inp_count
== 0) break;
122 n
= (4 - nr
) * _nchan
;
125 for (c
= 0; c
< _nchan
; c
++) pb
[n
+ c
] = inp_data
[c
];
131 for (c
= 0; c
< _nchan
; c
++) pb
[n
+ c
] = 0;
148 m1
= b
+ (3 * b
- 1) * d
;
149 m2
= a
+ (3 * a
- 1) * d
;
151 for (c
= 0; c
< n
; c
++)
153 *out_data
++ = m0
* pb
[0]
163 for (c
= 0; c
< n
; c
++) *out_data
++ = 0;
171 nr
= (unsigned int) floor (ph
);
177 memcpy (_buff
, pb
, (4 - nr
) * _nchan
* sizeof (float));