BEAST - Free Software Audio Synthesizer and Tracker  0.10.0
bseresampler.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __BSE_RESAMPLER_HH__
3 #define __BSE_RESAMPLER_HH__
4 
5 #include <bse/bsecxxutils.hh>
6 
7 G_BEGIN_DECLS
8 
9 typedef struct BseResampler2 BseResampler2;
10 
11 typedef enum /*< skip >*/
12 {
13  BSE_RESAMPLER2_MODE_UPSAMPLE,
14  BSE_RESAMPLER2_MODE_DOWNSAMPLE
15 } BseResampler2Mode;
16 
17 typedef enum /*< skip >*/
18 {
19  BSE_RESAMPLER2_PREC_LINEAR = 1, /* linear interpolation */
20  BSE_RESAMPLER2_PREC_48DB = 8,
21  BSE_RESAMPLER2_PREC_72DB = 12,
22  BSE_RESAMPLER2_PREC_96DB = 16,
23  BSE_RESAMPLER2_PREC_120DB = 20,
24  BSE_RESAMPLER2_PREC_144DB = 24
25 } BseResampler2Precision;
26 
27 BseResampler2* bse_resampler2_create (BseResampler2Mode mode,
28  BseResampler2Precision precision);
29 void bse_resampler2_destroy (BseResampler2 *resampler);
30 void bse_resampler2_process_block (BseResampler2 *resampler,
31  const float *input,
32  uint n_input_samples,
33  float *output);
34 guint bse_resampler2_order (BseResampler2 *resampler);
35 double bse_resampler2_delay (BseResampler2 *resampler);
36 /* precision <-> bits conversion */
37 BseResampler2Precision bse_resampler2_find_precision_for_bits (guint bits);
38 const char* bse_resampler2_precision_name (BseResampler2Precision precision);
39 G_END_DECLS
40 #ifdef __cplusplus
41 #include <vector>
42 namespace Bse {
43 
45 namespace Resampler {
49 class Resampler2 {
50 public:
54  static Resampler2* create (BseResampler2Mode mode,
55  BseResampler2Precision precision);
59  static BseResampler2Precision find_precision_for_bits (guint bits);
63  static const char *precision_name (BseResampler2Precision precision);
67  virtual ~Resampler2();
71  virtual void process_block (const float *input, uint n_input_samples, float *output) = 0;
75  virtual guint order() const = 0;
88  virtual double delay() const = 0;
89 protected:
90  static const double halfband_fir_linear_coeffs[2];
91  static const double halfband_fir_48db_coeffs[16];
92  static const double halfband_fir_72db_coeffs[24];
93  static const double halfband_fir_96db_coeffs[32];
94  static const double halfband_fir_120db_coeffs[42];
95  static const double halfband_fir_144db_coeffs[52];
96 
97  /* Creates implementation from filter coefficients and Filter implementation class
98  *
99  * Since up- and downsamplers use different (scaled) coefficients, its possible
100  * to specify a scaling factor. Usually 2 for upsampling and 1 for downsampling.
101  */
102  template<class Filter> static inline Resampler2*
103  create_impl_with_coeffs (const double *d,
104  guint order,
105  double scaling)
106  {
107  float taps[order];
108  for (guint i = 0; i < order; i++)
109  taps[i] = d[i] * scaling;
110 
111  Resampler2 *filter = new Filter (taps);
112  RAPICORN_ASSERT (order == filter->order());
113  return filter;
114  }
115  /* creates the actual implementation; specifying USE_SSE=true will use
116  * SSE instructions, USE_SSE=false will use FPU instructions
117  *
118  * Don't use this directly - it's only to be used by
119  * bseblockutils.cc's anonymous Impl classes.
120  */
121  template<bool USE_SSE> static inline Resampler2*
122  create_impl (BseResampler2Mode mode,
123  BseResampler2Precision precision);
124 };
125 
126 } /* namespace Resampler */
127 
128 } /* namespace Bse */
129 
130 #endif /* __cplusplus */
131 
132 #endif /* __BSE_RESAMPLER_HH__ */
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:88