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 #ifndef GUITARIX_AS_PLUGIN
29 #include <zita-resampler/resampler.h>
30 #else
31 #include "zita-resampler/resampler.h"
32 #endif
33 
34 namespace gx_resample {
35 
36 #define MAX_UPSAMPLE 8
37 
39  private:
40  Resampler r_up, r_down;
41  int m_fact;
42  public:
44  void setup(int sampleRate, unsigned int fact);
45  void up(int count, float *input, float *output);
46  void down(int count, float *input, float *output);
47 };
48 
49 class BufferResampler: Resampler {
50  public:
51  float *process(int fs_inp, int ilen, float *input, int fs_outp, int* olen);
52 };
53 
54 class StreamingResampler: Resampler {
55  private:
56  int ratio_a;
57  int ratio_b;
58  public:
59  bool setup(int srcRate, int dstRate, int nchan);
60  int get_max_out_size(int i_size) { return (i_size * ratio_b) / ratio_a + 1; }
61  int process(int count, float *input, float *output);
62  int flush(float *output); // check source for max. output size
63 };
64 
66 private:
67  Resampler r_up, r_down;
69 public:
70  int setup(int _inputRate, int _outputRate);
71  int up(int count, float *input, float *output);
72  void down(float *input, float *output);
73  int max_out_count(int in_count) {
74  if (inputRate > outputRate) return in_count;
75  return static_cast<int>(ceil((in_count*static_cast<double>(outputRate))/inputRate)); }
76 };
77 
78 }
79 #endif // SRC_HEADERS_GX_RESAMPLER_H_
float * process(int fs_inp, int ilen, float *input, int fs_outp, int *olen)
int max_out_count(int in_count)
Definition: gx_resampler.h:73
void down(float *input, float *output)
int up(int count, float *input, float *output)
int setup(int _inputRate, int _outputRate)
void up(int count, float *input, float *output)
void down(int count, float *input, float *output)
void setup(int sampleRate, unsigned int fact)
int process(int count, float *input, float *output)
bool setup(int srcRate, int dstRate, int nchan)
int get_max_out_size(int i_size)
Definition: gx_resampler.h:60