SoDaRadio-5.0.3-master:8901fb5
ReSampler.hxx
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012,2013,2014 Matthew H. Reilly (kb1vc)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 #ifndef RESAMPLER_HDR
29 #define RESAMPLER_HDR
30 #include <complex>
31 #include <fftw3.h>
32 #include "OSFilter.hxx"
33 
34 namespace SoDa {
41  class ReSampler {
42  public:
51  ReSampler(unsigned int interp_ratio,
52  unsigned int decim_ratio,
53  unsigned int _inlen,
54  unsigned int filter_len);
55 
63  unsigned int apply(std::complex<float> * in,
64  std::complex<float> * out, float gain = 1.0);
72  unsigned int apply(float * in,
73  float * out, float gain = 1.0);
74 
75  private:
81  void CreateFilter(unsigned int filter_len);
82 
83  int filter_len;
84 
85  unsigned int iM, dN, Q, tail_index;
86  unsigned int inlen, M, N;
87  std::complex<float> ** c_filt;
88  std::complex<float> * filt_fft;
89  std::complex<float> * interp_res;
90  std::complex<float> * in_fft;
91  std::complex<float> * inbuf;
92 
93  // gain corrections and other stuff
96 
97  // we'll create plans
98  fftwf_plan in_fft_plan;
99  fftwf_plan mid_ifft_plan;
100  };
101 }
102 
103 #endif // RESAMPLER_HDR
std::complex< float > * inbuf
the fft input buffer
Definition: ReSampler.hxx:91
This is an overlap-and-save frequency domain implementation of a general FIR filter widget...
Rational Resampler.
Definition: ReSampler.hxx:41
unsigned int M
Definition: ReSampler.hxx:86
float transform_gain
Definition: ReSampler.hxx:94
std::complex< float > ** c_filt
filter bank for interp/deci filter
Definition: ReSampler.hxx:87
unsigned int iM
Definition: ReSampler.hxx:85
void CreateFilter(unsigned int filter_len)
create a filter bank for a polyphase resampler.
Definition: ReSampler.cxx:171
unsigned int dN
Definition: ReSampler.hxx:85
unsigned int inlen
Definition: ReSampler.hxx:86
unsigned int Q
Definition: ReSampler.hxx:85
std::complex< float > * in_fft
the result of the first fft stage
Definition: ReSampler.hxx:90
int filter_len
the length of the polyphase filter that we&#39;re using.
Definition: ReSampler.hxx:83
unsigned int N
Definition: ReSampler.hxx:86
unsigned int tail_index
Definition: ReSampler.hxx:85
ReSampler(unsigned int interp_ratio, unsigned int decim_ratio, unsigned int _inlen, unsigned int filter_len)
Constructor.
Definition: ReSampler.cxx:82
float gain_correction
Definition: ReSampler.hxx:95
std::complex< float > * filt_fft
the filtered image of the input stream
Definition: ReSampler.hxx:88
std::complex< float > * interp_res
the interpolation result
Definition: ReSampler.hxx:89
fftwf_plan in_fft_plan
Definition: ReSampler.hxx:98
fftwf_plan mid_ifft_plan
Definition: ReSampler.hxx:99
unsigned int apply(std::complex< float > *in, std::complex< float > *out, float gain=1.0)
apply the resampler to a buffer of IQ samples.
Definition: ReSampler.cxx:272