1 #ifndef _RESAMPLER_H 2 #define _RESAMPLER_H 3 /* Copyright (C) 2003 Marcus Overhagen 4 * Released under terms of the MIT license. 5 * 6 * A simple resampling class for the audio mixer. 7 * You pick the conversion function on object creation, 8 * and then call the Resample() function, specifying data pointer, 9 * offset (in bytes) to the next sample, and count of samples for 10 * both source and destination. 11 * 12 */ 13 14 class Resampler 15 { 16 public: 17 Resampler(uint32 sourceformat, uint32 destformat, int16 dst_valid_bits); 18 virtual ~Resampler(); 19 20 status_t InitCheck(); 21 22 void Resample(const void *src, int32 src_sample_offset, int32 src_sample_count, 23 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 24 25 protected: 26 virtual void float_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count, 27 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 28 virtual void int32_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count, 29 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 30 virtual void int16_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count, 31 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 32 virtual void int8_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count, 33 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 34 virtual void uint8_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count, 35 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 36 virtual void float_to_int32_32 (const void *src, int32 src_sample_offset, int32 src_sample_count, 37 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 38 virtual void float_to_int32_24 (const void *src, int32 src_sample_offset, int32 src_sample_count, 39 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 40 virtual void float_to_int32_20 (const void *src, int32 src_sample_offset, int32 src_sample_count, 41 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 42 virtual void float_to_int16 (const void *src, int32 src_sample_offset, int32 src_sample_count, 43 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 44 virtual void float_to_int8 (const void *src, int32 src_sample_offset, int32 src_sample_count, 45 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 46 virtual void float_to_uint8 (const void *src, int32 src_sample_offset, int32 src_sample_count, 47 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); 48 private: 49 void (Resampler::*fFunc) (const void *, int32, int32, void *, int32, int32, float); 50 }; 51 52 53 inline void 54 Resampler::Resample(const void *src, int32 src_sample_offset, int32 src_sample_count, 55 void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain) 56 { 57 (this->*fFunc)(src, src_sample_offset, src_sample_count, dst, dst_sample_offset, dst_sample_count, gain); 58 } 59 60 #endif 61