1 /* 2 * Copyright 2012 Jérôme Leveque 3 * Copyright 2003 Marcus Overhagen 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _MULTI_AUDIO_RESAMPLER_H 7 #define _MULTI_AUDIO_RESAMPLER_H 8 9 10 #include <MediaDefs.h> 11 12 13 class Resampler { 14 public: 15 Resampler(uint32 sourceFormat, 16 uint32 destFormat); 17 18 virtual ~Resampler(); 19 20 status_t InitCheck() const; 21 22 void Resample(const void *inputData, 23 uint32 inputStride, void *outputData, 24 uint32 outputStride, uint32 sampleCount); 25 26 protected: 27 //static functions for converting datas 28 void _Void(const void *inputData, uint32 inputStride, 29 void *outputData, uint32 outputStride, 30 uint32 sampleCount); 31 virtual void _CopyFloat2Float(const void *inputData, 32 uint32 inputStride, void *outputData, 33 uint32 outputStride, uint32 sampleCount); 34 virtual void _CopyFloat2Double(const void *inputData, 35 uint32 inputStride, void *outputData, 36 uint32 outputStride, uint32 sampleCount); 37 virtual void _CopyFloat2Short(const void *inputData, 38 uint32 inputStride, void *outputData, 39 uint32 outputStride, uint32 sampleCount); 40 virtual void _CopyFloat2Int(const void *inputData, 41 uint32 inputStride, void *outputData, 42 uint32 outputStride, uint32 sampleCount); 43 virtual void _CopyFloat2UChar(const void *inputData, 44 uint32 inputStride, void *outputData, 45 uint32 outputStride, uint32 sampleCount); 46 virtual void _CopyFloat2Char(const void *inputData, 47 uint32 inputStride, void *outputData, 48 uint32 outputStride, uint32 sampleCount); 49 50 virtual void _CopyDouble2Float(const void *inputData, 51 uint32 inputStride, void *outputData, 52 uint32 outputStride, uint32 sampleCount); 53 virtual void _CopyDouble2Double(const void *inputData, 54 uint32 inputStride, void *outputData, 55 uint32 outputStride, uint32 sampleCount); 56 virtual void _CopyDouble2Short(const void *inputData, 57 uint32 inputStride, void *outputData, 58 uint32 outputStride, uint32 sampleCount); 59 virtual void _CopyDouble2Int(const void *inputData, 60 uint32 inputStride, void *outputData, 61 uint32 outputStride, uint32 sampleCount); 62 virtual void _CopyDouble2UChar(const void *inputData, 63 uint32 inputStride, void *outputData, 64 uint32 outputStride, uint32 sampleCount); 65 virtual void _CopyDouble2Char(const void *inputData, 66 uint32 inputStride, void *outputData, 67 uint32 outputStride, uint32 sampleCount); 68 69 virtual void _CopyInt2Float(const void *inputData, 70 uint32 inputStride, void *outputData, 71 uint32 outputStride, uint32 sampleCount); 72 virtual void _CopyInt2Double(const void *inputData, 73 uint32 inputStride, void *outputData, 74 uint32 outputStride, uint32 sampleCount); 75 virtual void _CopyInt2Int(const void *inputData, 76 uint32 inputStride, void *outputData, 77 uint32 outputStride, uint32 sampleCount); 78 virtual void _CopyInt2Short(const void *inputData, 79 uint32 inputStride, void *outputData, 80 uint32 outputStride, uint32 sampleCount); 81 virtual void _CopyInt2UChar(const void *inputData, 82 uint32 inputStride, void *outputData, 83 uint32 outputStride, uint32 sampleCount); 84 virtual void _CopyInt2Char(const void *inputData, 85 uint32 inputStride, void *outputData, 86 uint32 outputStride, uint32 sampleCount); 87 88 virtual void _CopyShort2Float(const void *inputData, 89 uint32 inputStride, void *outputData, 90 uint32 outputStride, uint32 sampleCount); 91 virtual void _CopyShort2Double(const void *inputData, 92 uint32 inputStride, void *outputData, 93 uint32 outputStride, uint32 sampleCount); 94 virtual void _CopyShort2Int(const void *inputData, 95 uint32 inputStride, void *outputData, 96 uint32 outputStride, uint32 sampleCount); 97 virtual void _CopyShort2Short(const void *inputData, 98 uint32 inputStride, void *outputData, 99 uint32 outputStride, uint32 sampleCount); 100 virtual void _CopyShort2UChar(const void *inputData, 101 uint32 inputStride, void *outputData, 102 uint32 outputStride, uint32 sampleCount); 103 virtual void _CopyShort2Char(const void *inputData, 104 uint32 inputStride, void *outputData, 105 uint32 outputStride, uint32 sampleCount); 106 107 virtual void _CopyUChar2Float(const void *inputData, 108 uint32 inputStride, void *outputData, 109 uint32 outputStride, uint32 sampleCount); 110 virtual void _CopyUChar2Double(const void *inputData, 111 uint32 inputStride, void *outputData, 112 uint32 outputStride, uint32 sampleCount); 113 virtual void _CopyUChar2Short(const void *inputData, 114 uint32 inputStride, void *outputData, 115 uint32 outputStride, uint32 sampleCount); 116 virtual void _CopyUChar2Int(const void *inputData, 117 uint32 inputStride, void *outputData, 118 uint32 outputStride, uint32 sampleCount); 119 virtual void _CopyUChar2UChar(const void *inputData, 120 uint32 inputStride, void *outputData, 121 uint32 outputStride, uint32 sampleCount); 122 virtual void _CopyUChar2Char(const void *inputData, 123 uint32 inputStride, void *outputData, 124 uint32 outputStride, uint32 sampleCount); 125 126 virtual void _CopyChar2Float(const void *inputData, 127 uint32 inputStride, void *outputData, 128 uint32 outputStride, uint32 sampleCount); 129 virtual void _CopyChar2Double(const void *inputData, 130 uint32 inputStride, void *outputData, 131 uint32 outputStride, uint32 sampleCount); 132 virtual void _CopyChar2Short(const void *inputData, 133 uint32 inputStride, void *outputData, 134 uint32 outputStride, uint32 sampleCount); 135 virtual void _CopyChar2Int(const void *inputData, 136 uint32 inputStride, void *outputData, 137 uint32 outputStride, uint32 sampleCount); 138 virtual void _CopyChar2UChar(const void *inputData, 139 uint32 inputStride, void *outputData, 140 uint32 outputStride, uint32 sampleCount); 141 virtual void _CopyChar2Char(const void *inputData, 142 uint32 inputStride, void *outputData, 143 uint32 outputStride, uint32 sampleCount); 144 145 private: 146 void (Resampler::*fFunc)(const void *inputData, 147 uint32 inputStride, void *outputData, 148 uint32 outputStride, uint32 sampleCount); 149 }; 150 151 152 inline void 153 Resampler::Resample(const void *inputData, uint32 inputStride, 154 void *outputData, uint32 outputStride, uint32 sampleCount) 155 { 156 (this->*fFunc)(inputData, inputStride, outputData, outputStride, 157 sampleCount); 158 } 159 160 161 #endif // _MULTI_AUDIO_RESAMPLER_H 162