sipxmedialib  Version 3.3
MpResampler.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007-2008 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2007-2008 SIPez LLC.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 // Author: Alexander Chemeris <Alexander DOT Chemeris AT SIPez DOT com> and Keith Kyzivat <kkyzivat AT SIPez DOT com>
12 
13 #ifndef _MpResamplerBase_h_
14 #define _MpResamplerBase_h_
15 
16 // SYSTEM INCLUDES
17 // APPLICATION INCLUDES
18 #include <mp/MpTypes.h>
19 #include <os/OsStatus.h>
20 #include <mp/MpMisc.h>
21 
22 // DEFINES
23 // MACROS
24 // EXTERNAL FUNCTIONS
25 // EXTERNAL VARIABLES
26 // CONSTANTS
27 // STRUCTS
28 // TYPEDEFS
29 // FORWARD DECLARATIONS
30 
35 {
36 /* //////////////////////////////// PUBLIC //////////////////////////////// */
37 public:
38 
39 /* =============================== CREATORS =============================== */
41 
42 
43  static
44  MpResamplerBase *createResampler(uint32_t numChannels,
45  uint32_t inputRate,
46  uint32_t outputRate,
47  int32_t quality = -1);
48 
50  MpResamplerBase(uint32_t numChannels,
51  uint32_t inputRate,
52  uint32_t outputRate,
53  int32_t quality);
63  virtual ~MpResamplerBase();
65 
67 
68 /* ============================= MANIPULATORS ============================= */
70 
71 
73  virtual OsStatus resetStream();
74 
76  virtual OsStatus resample(uint32_t channelIndex,
77  const MpAudioSample* pInBuf,
78  uint32_t inBufLength,
79  uint32_t& inSamplesProcessed,
80  MpAudioSample* pOutBuf,
81  uint32_t outBufLength,
82  uint32_t& outSamplesWritten);
88  virtual OsStatus resampleInterleavedStereo(const MpAudioSample* pInBuf,
90  uint32_t inBufLength,
91  uint32_t& inSamplesProcessed,
92  MpAudioSample* pOutBuf,
93  uint32_t outBufLength,
94  uint32_t& outSamplesWritten);
109  OsStatus resampleBufPtr(const MpAudioBufPtr& inBuf, MpAudioBufPtr& outBuf,
111  uint32_t inRate, uint32_t outRate,
112  UtlString optionalIdStr = "");
129  virtual OsStatus setInputRate(const uint32_t inputRate);
135  virtual OsStatus setOutputRate(const uint32_t outputRate);
141  virtual OsStatus setQuality(const int32_t quality);
149 
150 /* ============================== ACCESSORS =============================== */
152 
153 
155  uint32_t getInputRate() const;
156 
158  uint32_t getOutputRate() const;
159 
161  int32_t getQuality() const;
162 
163  static inline
164  int getNumSamplesConverted(uint32_t inputRate, uint32_t outputRate,
165  int numInputSamples, int &remainingSamplesNum);
166 
167  static inline
168  int getNumSamplesOriginal(uint32_t inputRate, uint32_t outputRate,
169  int numOutputSamples, int &remainingSamplesNum);
170 
172 
173 /* =============================== INQUIRY ================================ */
175 
176 
177 
179 
180 /* ////////////////////////////// PROTECTED /////////////////////////////// */
181 protected:
182  uint32_t mNumChannels;
183  uint32_t mInputRate;
184  uint32_t mOutputRate;
185  int32_t mQuality;
186 
187 /* /////////////////////////////// PRIVATE //////////////////////////////// */
188 private:
189 
190 
191 };
192 
193 /* ============================ INLINE METHODS ============================ */
194 
195 int MpResamplerBase::getNumSamplesConverted(uint32_t inputRate, uint32_t outputRate,
196  int numInputSamples, int &remainingSamplesNum)
197 {
198  int numOutputSamples = outputRate*numInputSamples/inputRate;
199  remainingSamplesNum = numInputSamples - inputRate*numOutputSamples/outputRate;
200  return numOutputSamples;
201 }
202 
203 int MpResamplerBase::getNumSamplesOriginal(uint32_t inputRate, uint32_t outputRate,
204  int numOutputSamples, int &remainingSamplesNum)
205 {
206  int numInputSamples = inputRate*numOutputSamples/outputRate;
207  remainingSamplesNum = numOutputSamples - outputRate*numInputSamples/inputRate;
208  return numInputSamples;
209 }
210 
211 #endif // _MpResamplerBase_h_
uint32_t getInputRate() const
Return input sampling rate.
Definition: MpResampler.cpp:242
Generic audio resampler.
Definition: MpResampler.h:34
virtual OsStatus resampleInterleavedStereo(const MpAudioSample *pInBuf, uint32_t inBufLength, uint32_t &inSamplesProcessed, MpAudioSample *pOutBuf, uint32_t outBufLength, uint32_t &outSamplesWritten)
Resample interleaved stereo audio data.
Definition: MpResampler.cpp:129
static int getNumSamplesConverted(uint32_t inputRate, uint32_t outputRate, int numInputSamples, int &remainingSamplesNum)
Definition: MpResampler.h:195
virtual OsStatus resample(uint32_t channelIndex, const MpAudioSample *pInBuf, uint32_t inBufLength, uint32_t &inSamplesProcessed, MpAudioSample *pOutBuf, uint32_t outBufLength, uint32_t &outSamplesWritten)
Resample audio data coming from the specified channel.
Definition: MpResampler.cpp:72
uint32_t mOutputRate
Definition: MpResampler.h:184
virtual OsStatus setOutputRate(const uint32_t outputRate)
Set the output sample rate, in Hz.
Definition: MpResampler.cpp:228
static MpResamplerBase * createResampler(uint32_t numChannels, uint32_t inputRate, uint32_t outputRate, int32_t quality=-1)
Definition: MpResampler.cpp:33
int32_t getQuality() const
Return quality of resampling conversion.
Definition: MpResampler.cpp:253
virtual OsStatus resetStream()
Reset resampler state to prepare for processing new (unrelated) stream.
Definition: MpResampler.cpp:65
MpResamplerBase(uint32_t numChannels, uint32_t inputRate, uint32_t outputRate, int32_t quality)
Constructor.
Definition: MpResampler.cpp:47
int16_t MpAudioSample
Definition: MpTypes.h:44
Smart pointer to MpAudioBuf.
Definition: MpAudioBuf.h:168
uint32_t getOutputRate() const
Return output sampling rate.
Definition: MpResampler.cpp:247
OsStatus resampleBufPtr(const MpAudioBufPtr &inBuf, MpAudioBufPtr &outBuf, uint32_t inRate, uint32_t outRate, UtlString optionalIdStr="")
resample the buffer given, and return a new resampled one.
Definition: MpResampler.cpp:140
uint32_t mInputRate
Definition: MpResampler.h:183
virtual OsStatus setInputRate(const uint32_t inputRate)
Set the input sample rate, in Hz.
Definition: MpResampler.cpp:222
virtual ~MpResamplerBase()
Destructor.
Definition: MpResampler.cpp:58
virtual OsStatus setQuality(const int32_t quality)
Set the quality of resampling conversion.
Definition: MpResampler.cpp:234
int32_t mQuality
Definition: MpResampler.h:185
uint32_t mNumChannels
Definition: MpResampler.h:182
static int getNumSamplesOriginal(uint32_t inputRate, uint32_t outputRate, int numOutputSamples, int &remainingSamplesNum)
Definition: MpResampler.h:203