Guitarix
gx_resampler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
4  *
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 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * --------------------------------------------------------------------------
19  */
20 
21 /* ------- This is the guitarix resampler, to use zita-resampler ------- */
22 
23 #pragma once
24 
25 #ifndef SRC_HEADERS_GX_RESAMPLER_H_
26 #define SRC_HEADERS_GX_RESAMPLER_H_
27 
28 #include <zita-resampler/resampler.h>
29 
30 namespace gx_resample {
31 
32 #define MAX_UPSAMPLE 8
33 
35  private:
36  Resampler r_up, r_down;
37  int m_fact;
38  public:
40  void setup(int sampleRate, unsigned int fact);
41  void up(int count, float *input, float *output);
42  void down(int count, float *input, float *output);
43 };
44 
45 class BufferResampler: Resampler {
46  public:
47  float *process(int fs_inp, int ilen, float *input, int fs_outp, int* olen);
48 };
49 
50 class StreamingResampler: Resampler {
51  private:
52  int ratio_a;
53  int ratio_b;
54  public:
55  bool setup(int srcRate, int dstRate, int nchan);
56  int get_max_out_size(int i_size) { return (i_size * ratio_b) / ratio_a + 1; }
57  int process(int count, float *input, float *output);
58  int flush(float *output); // check source for max. output size
59 };
60 
62 private:
63  Resampler r_up, r_down;
65 public:
66  int setup(int _inputRate, int _outputRate);
67  int up(int count, float *input, float *output);
68  void down(float *input, float *output);
69  int max_out_count(int in_count) {
70  if (inputRate > outputRate) return in_count;
71  return static_cast<int>(ceil((in_count*static_cast<double>(outputRate))/inputRate)); }
72 };
73 
74 }
75 #endif // SRC_HEADERS_GX_RESAMPLER_H_
gx_resample::FixedRateResampler::up
int up(int count, float *input, float *output)
gx_resample::FixedRateResampler::r_down
Resampler r_down
Definition: gx_resampler.h:63
gx_resample::FixedRateResampler::inputRate
int inputRate
Definition: gx_resampler.h:64
gx_resample::FixedRateResampler
Definition: gx_resampler.h:61
gx_resample::StreamingResampler::setup
bool setup(int srcRate, int dstRate, int nchan)
gx_resample::StreamingResampler
Definition: gx_resampler.h:50
gx_resample::FixedRateResampler::down
void down(float *input, float *output)
gx_resample
Definition: gx_resampler.h:30
gx_resample::FixedRateResampler::outputRate
int outputRate
Definition: gx_resampler.h:64
gx_resample::FixedRateResampler::r_up
Resampler r_up
Definition: gx_resampler.h:63
gx_resample::SimpleResampler::setup
void setup(int sampleRate, unsigned int fact)
gx_resample::SimpleResampler::SimpleResampler
SimpleResampler()
Definition: gx_resampler.h:39
gx_resample::StreamingResampler::process
int process(int count, float *input, float *output)
gx_resample::StreamingResampler::flush
int flush(float *output)
gx_resample::BufferResampler
Definition: gx_resampler.h:45
gx_resample::SimpleResampler::m_fact
int m_fact
Definition: gx_resampler.h:37
gx_resample::FixedRateResampler::max_out_count
int max_out_count(int in_count)
Definition: gx_resampler.h:69
gx_resample::SimpleResampler
Definition: gx_resampler.h:34
gx_resample::BufferResampler::process
float * process(int fs_inp, int ilen, float *input, int fs_outp, int *olen)
gx_resample::StreamingResampler::ratio_b
int ratio_b
Definition: gx_resampler.h:53
gx_resample::SimpleResampler::down
void down(int count, float *input, float *output)
gx_resample::StreamingResampler::get_max_out_size
int get_max_out_size(int i_size)
Definition: gx_resampler.h:56
gx_resample::FixedRateResampler::setup
int setup(int _inputRate, int _outputRate)
gx_resample::SimpleResampler::up
void up(int count, float *input, float *output)
gx_resample::SimpleResampler::r_up
Resampler r_up
Definition: gx_resampler.h:36
gx_resample::SimpleResampler::r_down
Resampler r_down
Definition: gx_resampler.h:36
gx_resample::StreamingResampler::ratio_a
int ratio_a
Definition: gx_resampler.h:52