BEAST/BSE - Better Audio System and Sound Engine
0.8.2
|
00001 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html 00002 #ifndef __BSE_RESAMPLER_HH__ 00003 #define __BSE_RESAMPLER_HH__ 00004 00005 #include <bse/bsecxxutils.hh> 00006 00007 G_BEGIN_DECLS 00008 00009 typedef struct BseResampler2 BseResampler2; 00010 00011 typedef enum /*< skip >*/ 00012 { 00013 BSE_RESAMPLER2_MODE_UPSAMPLE, 00014 BSE_RESAMPLER2_MODE_DOWNSAMPLE 00015 } BseResampler2Mode; 00016 00017 typedef enum /*< skip >*/ 00018 { 00019 BSE_RESAMPLER2_PREC_LINEAR = 1, /* linear interpolation */ 00020 BSE_RESAMPLER2_PREC_48DB = 8, 00021 BSE_RESAMPLER2_PREC_72DB = 12, 00022 BSE_RESAMPLER2_PREC_96DB = 16, 00023 BSE_RESAMPLER2_PREC_120DB = 20, 00024 BSE_RESAMPLER2_PREC_144DB = 24 00025 } BseResampler2Precision; 00026 00027 BseResampler2* bse_resampler2_create (BseResampler2Mode mode, 00028 BseResampler2Precision precision); 00029 void bse_resampler2_destroy (BseResampler2 *resampler); 00030 void bse_resampler2_process_block (BseResampler2 *resampler, 00031 const float *input, 00032 uint n_input_samples, 00033 float *output); 00034 guint bse_resampler2_order (BseResampler2 *resampler); 00035 double bse_resampler2_delay (BseResampler2 *resampler); 00036 /* precision <-> bits conversion */ 00037 BseResampler2Precision bse_resampler2_find_precision_for_bits (guint bits); 00038 const char* bse_resampler2_precision_name (BseResampler2Precision precision); 00039 G_END_DECLS 00040 #ifdef __cplusplus 00041 #include <vector> 00042 namespace Bse { 00043 00045 namespace Resampler { 00049 class Resampler2 { 00050 public: 00054 static Resampler2* create (BseResampler2Mode mode, 00055 BseResampler2Precision precision); 00059 static BseResampler2Precision find_precision_for_bits (guint bits); 00063 static const char *precision_name (BseResampler2Precision precision); 00067 virtual ~Resampler2(); 00071 virtual void process_block (const float *input, uint n_input_samples, float *output) = 0; 00075 virtual guint order() const = 0; 00088 virtual double delay() const = 0; 00089 protected: 00090 static const double halfband_fir_linear_coeffs[2]; 00091 static const double halfband_fir_48db_coeffs[16]; 00092 static const double halfband_fir_72db_coeffs[24]; 00093 static const double halfband_fir_96db_coeffs[32]; 00094 static const double halfband_fir_120db_coeffs[42]; 00095 static const double halfband_fir_144db_coeffs[52]; 00096 00097 /* Creates implementation from filter coefficients and Filter implementation class 00098 * 00099 * Since up- and downsamplers use different (scaled) coefficients, its possible 00100 * to specify a scaling factor. Usually 2 for upsampling and 1 for downsampling. 00101 */ 00102 template<class Filter> static inline Resampler2* 00103 create_impl_with_coeffs (const double *d, 00104 guint order, 00105 double scaling) 00106 { 00107 float taps[order]; 00108 for (guint i = 0; i < order; i++) 00109 taps[i] = d[i] * scaling; 00110 00111 Resampler2 *filter = new Filter (taps); 00112 g_assert (order == filter->order()); 00113 return filter; 00114 } 00115 /* creates the actual implementation; specifying USE_SSE=true will use 00116 * SSE instructions, USE_SSE=false will use FPU instructions 00117 * 00118 * Don't use this directly - it's only to be used by 00119 * bseblockutils.cc's anonymous Impl classes. 00120 */ 00121 template<bool USE_SSE> static inline Resampler2* 00122 create_impl (BseResampler2Mode mode, 00123 BseResampler2Precision precision); 00124 }; 00125 00126 } /* namespace Resampler */ 00127 00128 } /* namespace Bse */ 00129 00130 #endif /* __cplusplus */ 00131 00132 #endif /* __BSE_RESAMPLER_HH__ */