2013-08-21 00:54:54 +00:00
|
|
|
/*
|
|
|
|
* Rational Sample Rate Conversion
|
|
|
|
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
|
|
|
|
*
|
2019-07-22 10:05:52 +00:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1+
|
|
|
|
*
|
2013-08-21 00:54:54 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _RESAMPLER_H_
|
|
|
|
#define _RESAMPLER_H_
|
|
|
|
|
2017-06-19 22:23:59 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <complex>
|
|
|
|
|
2013-08-21 00:54:54 +00:00
|
|
|
class Resampler {
|
|
|
|
public:
|
|
|
|
/* Constructor for rational sample rate conversion
|
|
|
|
* @param p numerator of resampling ratio
|
|
|
|
* @param q denominator of resampling ratio
|
2019-07-22 10:03:39 +00:00
|
|
|
* @param filt_len length of each polyphase subfilter
|
2013-08-21 00:54:54 +00:00
|
|
|
*/
|
|
|
|
Resampler(size_t p, size_t q, size_t filt_len = 16);
|
|
|
|
~Resampler();
|
|
|
|
|
2019-10-13 17:08:00 +00:00
|
|
|
/* Initialize resampler filterbank.
|
2013-08-21 00:54:54 +00:00
|
|
|
* @param bw bandwidth factor on filter generation (pre-window)
|
|
|
|
* @return false on error, zero otherwise
|
|
|
|
*
|
|
|
|
* Automatic setting is to compute the filter to prevent aliasing with
|
2019-10-13 17:08:00 +00:00
|
|
|
* a Blackman-Harris window. Adjustment is made through a bandwidth
|
2013-08-21 00:54:54 +00:00
|
|
|
* factor to shift the cutoff and/or the constituent filter lengths.
|
|
|
|
* Calculation of specific rolloff factors or 3-dB cutoff points is
|
|
|
|
* left as an excersize for the reader.
|
|
|
|
*/
|
|
|
|
bool init(float bw = 1.0f);
|
|
|
|
|
|
|
|
/* Rotate "commutator" and drive samples through filterbank
|
|
|
|
* @param in continuous buffer of input complex float values
|
|
|
|
* @param in_len input buffer length
|
|
|
|
* @param out continuous buffer of output complex float values
|
|
|
|
* @param out_len output buffer length
|
|
|
|
* @return number of samples outputted, negative on error
|
|
|
|
*
|
|
|
|
* Input and output vector lengths must of be equal multiples of the
|
|
|
|
* rational conversion rate denominator and numerator respectively.
|
|
|
|
*/
|
2015-08-22 02:32:58 +00:00
|
|
|
int rotate(const float *in, size_t in_len, float *out, size_t out_len);
|
2013-08-21 00:54:54 +00:00
|
|
|
|
|
|
|
/* Get filter length
|
2019-07-22 10:03:39 +00:00
|
|
|
* @return number of taps in each filter partition
|
2013-08-21 00:54:54 +00:00
|
|
|
*/
|
|
|
|
size_t len();
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t p;
|
|
|
|
size_t q;
|
|
|
|
size_t filt_len;
|
2017-06-19 22:23:59 +00:00
|
|
|
std::vector<size_t> in_index;
|
|
|
|
std::vector<size_t> out_path;
|
|
|
|
std::vector<std::complex<float> *> partitions;
|
2013-08-21 00:54:54 +00:00
|
|
|
|
2017-06-19 22:23:59 +00:00
|
|
|
void initFilters(float bw);
|
2013-08-21 00:54:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _RESAMPLER_H_ */
|