1 /* 2 * Copyright 2003 Marcus Overhagen 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _RESAMPLER_H 6 #define _RESAMPLER_H 7 8 9 #include <SupportDefs.h> 10 11 12 class Resampler { 13 public: 14 Resampler(uint32 sourceFormat, 15 uint32 destFormat); 16 virtual ~Resampler(); 17 18 status_t InitCheck() const; 19 20 void Resample(const void* src, int32 srcSampleOffset, 21 int32 srcSampleCount, void* dest, 22 int32 destSampleOffset, 23 int32 destSampleCount, float gain); 24 25 protected: 26 virtual void float_to_float(const void* src, 27 int32 srcSampleOffset, int32 srcSampleCount, 28 void* dest, int32 destSampleOffset, 29 int32 destSampleCount, float gain); 30 virtual void int32_to_float(const void* src, 31 int32 srcSampleOffset, int32 srcSampleCount, 32 void* dest, int32 destSampleOffset, 33 int32 destSampleCount, float gain); 34 virtual void int16_to_float(const void* src, 35 int32 srcSampleOffset, int32 srcSampleCount, 36 void* dest, int32 destSampleOffset, 37 int32 destSampleCount, float gain); 38 virtual void int8_to_float(const void* src, 39 int32 srcSampleOffset, int32 srcSampleCount, 40 void* dest, int32 destSampleOffset, 41 int32 destSampleCount, float gain); 42 virtual void uint8_to_float(const void* src, 43 int32 srcSampleOffset, int32 srcSampleCount, 44 void* dest, int32 destSampleOffset, 45 int32 destSampleCount, float gain); 46 virtual void float_to_int32(const void* src, 47 int32 srcSampleOffset, int32 srcSampleCount, 48 void* dest, int32 destSampleOffset, 49 int32 destSampleCount, float gain); 50 virtual void float_to_int16(const void* src, 51 int32 srcSampleOffset, int32 srcSampleCount, 52 void* dest, int32 destSampleOffset, 53 int32 destSampleCount, float gain); 54 virtual void float_to_int8(const void* src, 55 int32 srcSampleOffset, int32 srcSampleCount, 56 void* dest, int32 destSampleOffset, 57 int32 destSampleCount, float gain); 58 virtual void float_to_uint8(const void* src, 59 int32 srcSampleOffset, int32 srcSampleCount, 60 void* dest, int32 destSampleOffset, 61 int32 destSampleCount, float gain); 62 63 private: 64 void (Resampler::*fFunc)(const void* src, 65 int32 srcSampleOffset, int32 srcSampleCount, 66 void* dest, int32 destSampleOffset, 67 int32 destSampleCount, float gain); 68 // Do nothing method to get around a bug in 69 // the gcc2 cross-compiler built on Mac OS X 70 // Lion where a compiler error occurs when 71 // assigning a member function pointer to NULL 72 // or 0: cast specifies signature type. 73 // However, this should be legal according to 74 // the C++03 standard. 75 void no_conversion(const void*, int32, int32, void*, 76 int32, int32, float) {}; 77 }; 78 79 80 inline void 81 Resampler::Resample(const void *src, int32 srcSampleOffset, 82 int32 srcSampleCount, void *dest, int32 destSampleOffset, 83 int32 destSampleCount, float gain) 84 { 85 (this->*fFunc)(src, srcSampleOffset, srcSampleCount, dest, destSampleOffset, 86 destSampleCount, gain); 87 } 88 89 #endif // _RESAMPLER_H 90