Beast - Music Synthesizer and Composer  0.11.1+10.g2da35
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 typedef struct BseResampler2 BseResampler2;
8 
9 typedef enum /*< skip >*/
10 {
11  BSE_RESAMPLER2_MODE_UPSAMPLE,
12  BSE_RESAMPLER2_MODE_DOWNSAMPLE
13 } BseResampler2Mode;
14 
15 typedef enum /*< skip >*/
16 {
17  BSE_RESAMPLER2_PREC_LINEAR = 1, /* linear interpolation */
18  BSE_RESAMPLER2_PREC_48DB = 8,
19  BSE_RESAMPLER2_PREC_72DB = 12,
20  BSE_RESAMPLER2_PREC_96DB = 16,
21  BSE_RESAMPLER2_PREC_120DB = 20,
22  BSE_RESAMPLER2_PREC_144DB = 24
23 } BseResampler2Precision;
24 
25 BseResampler2* bse_resampler2_create (BseResampler2Mode mode,
26  BseResampler2Precision precision);
27 void bse_resampler2_destroy (BseResampler2 *resampler);
28 void bse_resampler2_process_block (BseResampler2 *resampler,
29  const float *input,
30  uint n_input_samples,
31  float *output);
32 guint bse_resampler2_order (BseResampler2 *resampler);
33 double bse_resampler2_delay (BseResampler2 *resampler);
34 /* precision <-> bits conversion */
35 BseResampler2Precision bse_resampler2_find_precision_for_bits (guint bits);
36 const char* bse_resampler2_precision_name (BseResampler2Precision precision);
37 #ifdef __cplusplus
38 #include <vector>
39 namespace Bse {
40 
42 namespace Resampler {
46 class Resampler2 {
47 public:
51  static Resampler2* create (BseResampler2Mode mode,
52  BseResampler2Precision precision);
56  static BseResampler2Precision find_precision_for_bits (guint bits);
60  static const char *precision_name (BseResampler2Precision precision);
64  virtual ~Resampler2();
68  virtual void process_block (const float *input, uint n_input_samples, float *output) = 0;
72  virtual guint order() const = 0;
85  virtual double delay() const = 0;
86 protected:
87  static const double halfband_fir_linear_coeffs[2];
88  static const double halfband_fir_48db_coeffs[16];
89  static const double halfband_fir_72db_coeffs[24];
90  static const double halfband_fir_96db_coeffs[32];
91  static const double halfband_fir_120db_coeffs[42];
92  static const double halfband_fir_144db_coeffs[52];
93 
94  /* Creates implementation from filter coefficients and Filter implementation class
95  *
96  * Since up- and downsamplers use different (scaled) coefficients, its possible
97  * to specify a scaling factor. Usually 2 for upsampling and 1 for downsampling.
98  */
99  template<class Filter> static inline Resampler2*
100  create_impl_with_coeffs (const double *d,
101  guint order,
102  double scaling)
103  {
104  float taps[order];
105  for (guint i = 0; i < order; i++)
106  taps[i] = d[i] * scaling;
107 
108  Resampler2 *filter = new Filter (taps);
109  RAPICORN_ASSERT (order == filter->order());
110  return filter;
111  }
112  /* creates the actual implementation; specifying USE_SSE=true will use
113  * SSE instructions, USE_SSE=false will use FPU instructions
114  *
115  * Don't use this directly - it's only to be used by
116  * bseblockutils.cc's anonymous Impl classes.
117  */
118  template<bool USE_SSE> static inline Resampler2*
119  create_impl (BseResampler2Mode mode,
120  BseResampler2Precision precision);
121 };
122 
123 } /* namespace Resampler */
124 
125 } /* namespace Bse */
126 
127 #endif /* __cplusplus */
128 
129 #endif /* __BSE_RESAMPLER_HH__ */
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:91
#define RAPICORN_ASSERT(cond)