xref: /haiku/src/add-ons/media/media-add-ons/mixer/Resampler.h (revision 5d9e40fe9252c8f9c5e5e41594545bfa4419fcc7)
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 conversation 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);
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	(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_int16	(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_int8	(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_uint8	(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 private:
45 	void (Resampler::*fFunc)	(const void *, int32, int32, void *, int32, int32, float);
46 };
47 
48 
49 inline void
50 Resampler::Resample(const void *src, int32 src_sample_offset, int32 src_sample_count,
51 					void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain)
52 {
53 	(this->*fFunc)(src, src_sample_offset, src_sample_count, dst, dst_sample_offset, dst_sample_count, gain);
54 }
55 
56 #endif
57