xref: /haiku/src/add-ons/media/media-add-ons/mixer/Resampler.h (revision 4970545477381336577230bc7c5a2599265c06e1)
1575526ffSbeveloper /* Copyright (C) 2003 Marcus Overhagen
2575526ffSbeveloper  * Released under terms of the MIT license.
3575526ffSbeveloper  *
4575526ffSbeveloper  * A simple resampling class for the audio mixer.
5c6a2e89fSStefano Ceccherini  * You pick the conversion function on object creation,
6575526ffSbeveloper  * and then call the Resample() function, specifying data pointer,
7575526ffSbeveloper  * offset (in bytes) to the next sample, and count of samples for
8575526ffSbeveloper  * both source and destination.
9575526ffSbeveloper  *
10575526ffSbeveloper  */
11*49705454SStephan Aßmus #ifndef _RESAMPLER_H
12*49705454SStephan Aßmus #define _RESAMPLER_H
13*49705454SStephan Aßmus 
14*49705454SStephan Aßmus #include <SupportDefs.h>
15*49705454SStephan Aßmus 
16575526ffSbeveloper 
17575526ffSbeveloper class Resampler
18575526ffSbeveloper {
19575526ffSbeveloper public:
20f0a85f97SJérôme Duval 	Resampler(uint32 sourceformat, uint32 destformat);
21575526ffSbeveloper 	virtual ~Resampler();
22575526ffSbeveloper 
23575526ffSbeveloper 	status_t InitCheck();
24575526ffSbeveloper 
25575526ffSbeveloper 	void Resample(const void *src, int32 src_sample_offset, int32 src_sample_count,
26575526ffSbeveloper 				  void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
27575526ffSbeveloper 
28575526ffSbeveloper protected:
29575526ffSbeveloper 	virtual void float_to_float	(const void *src, int32 src_sample_offset, int32 src_sample_count,
30575526ffSbeveloper 								void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
31575526ffSbeveloper 	virtual void int32_to_float	(const void *src, int32 src_sample_offset, int32 src_sample_count,
32575526ffSbeveloper 								void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
33575526ffSbeveloper 	virtual void int16_to_float	(const void *src, int32 src_sample_offset, int32 src_sample_count,
34575526ffSbeveloper 								void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
35575526ffSbeveloper 	virtual void int8_to_float	(const void *src, int32 src_sample_offset, int32 src_sample_count,
36575526ffSbeveloper 				  				void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
37575526ffSbeveloper 	virtual void uint8_to_float	(const void *src, int32 src_sample_offset, int32 src_sample_count,
38575526ffSbeveloper 								void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
39f0a85f97SJérôme Duval 	virtual void float_to_int32	(const void *src, int32 src_sample_offset, int32 src_sample_count,
40ebc67ddeSJérôme Duval 								void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
41575526ffSbeveloper 	virtual void float_to_int16	(const void *src, int32 src_sample_offset, int32 src_sample_count,
42575526ffSbeveloper 				  				void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
43575526ffSbeveloper 	virtual void float_to_int8	(const void *src, int32 src_sample_offset, int32 src_sample_count,
44575526ffSbeveloper 			 				  	void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
45575526ffSbeveloper 	virtual void float_to_uint8	(const void *src, int32 src_sample_offset, int32 src_sample_count,
46575526ffSbeveloper 								void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
47575526ffSbeveloper private:
48575526ffSbeveloper 	void (Resampler::*fFunc)	(const void *, int32, int32, void *, int32, int32, float);
49575526ffSbeveloper };
50575526ffSbeveloper 
51575526ffSbeveloper 
52575526ffSbeveloper inline void
53575526ffSbeveloper Resampler::Resample(const void *src, int32 src_sample_offset, int32 src_sample_count,
54575526ffSbeveloper 					void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain)
55575526ffSbeveloper {
56575526ffSbeveloper 	(this->*fFunc)(src, src_sample_offset, src_sample_count, dst, dst_sample_offset, dst_sample_count, gain);
57575526ffSbeveloper }
58575526ffSbeveloper 
59*49705454SStephan Aßmus #endif // _RESAMPLER_H
60