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