- update (C)
This commit is contained in:
parent
1dd0e16869
commit
6099b4fc04
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright(C) 2007-2014 VoIP objects (voipobjects.com)
|
/* Copyright(C) 2007-2018 VoIP objects (voipobjects.com)
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
@ -16,7 +16,7 @@ using namespace Audio;
|
||||||
#define IS_FRACTIONAL_RATE(X) (((X) % 8000) != 0)
|
#define IS_FRACTIONAL_RATE(X) (((X) % 8000) != 0)
|
||||||
|
|
||||||
SpeexResampler::SpeexResampler()
|
SpeexResampler::SpeexResampler()
|
||||||
:mContext(NULL), mErrorCode(0), mSourceRate(0), mDestRate(0), mLastSample(0)
|
:mContext(NULL), mErrorCode(0), mSourceRate(0), mDestRate(0), mLastSample(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,6 +82,7 @@ int SpeexResampler::processBuffer(const void* src, int sourceLength, int& source
|
||||||
// But no output
|
// But no output
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned outLen = getDestLength(sourceLength);
|
unsigned outLen = getDestLength(sourceLength);
|
||||||
if (outLen > (unsigned)destCapacity)
|
if (outLen > (unsigned)destCapacity)
|
||||||
return 0; // Skip resampling if not enough space
|
return 0; // Skip resampling if not enough space
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright(C) 2007-2014 VoIP objects (voipobjects.com)
|
/* Copyright(C) 2007-2018 VoIP objects (voipobjects.com)
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
namespace Audio
|
namespace Audio
|
||||||
{
|
{
|
||||||
class SpeexResampler
|
class SpeexResampler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SpeexResampler();
|
SpeexResampler();
|
||||||
~SpeexResampler();
|
~SpeexResampler();
|
||||||
|
|
||||||
|
|
@ -33,29 +33,29 @@ namespace Audio
|
||||||
// Returns instance + speex encoder size in bytes
|
// Returns instance + speex encoder size in bytes
|
||||||
int getSize() const;
|
int getSize() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void* mContext;
|
void* mContext;
|
||||||
int mErrorCode;
|
int mErrorCode;
|
||||||
int mSourceRate,
|
int mSourceRate,
|
||||||
mDestRate,
|
mDestRate,
|
||||||
mChannels;
|
mChannels;
|
||||||
short mLastSample;
|
short mLastSample;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SpeexResampler Resampler;
|
typedef SpeexResampler Resampler;
|
||||||
typedef std::shared_ptr<Resampler> PResampler;
|
typedef std::shared_ptr<Resampler> PResampler;
|
||||||
|
|
||||||
class ChannelConverter
|
class ChannelConverter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static int stereoToMono(const void* source, int sourceLength, void* dest, int destLength);
|
static int stereoToMono(const void* source, int sourceLength, void* dest, int destLength);
|
||||||
static int monoToStereo(const void* source, int sourceLength, void* dest, int destLength);
|
static int monoToStereo(const void* source, int sourceLength, void* dest, int destLength);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Operates with AUDIO_CHANNELS number of channels
|
// Operates with AUDIO_CHANNELS number of channels
|
||||||
class UniversalResampler
|
class UniversalResampler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniversalResampler();
|
UniversalResampler();
|
||||||
~UniversalResampler();
|
~UniversalResampler();
|
||||||
|
|
||||||
|
|
@ -63,39 +63,39 @@ namespace Audio
|
||||||
int getDestLength(int sourceRate, int destRate, int sourceLength);
|
int getDestLength(int sourceRate, int destRate, int sourceLength);
|
||||||
int getSourceLength(int sourceRate, int destRate, int destLength);
|
int getSourceLength(int sourceRate, int destRate, int destLength);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::pair<int, int> RatePair;
|
typedef std::pair<int, int> RatePair;
|
||||||
typedef std::map<RatePair, PResampler> ResamplerMap;
|
typedef std::map<RatePair, PResampler> ResamplerMap;
|
||||||
ResamplerMap mResamplerMap;
|
ResamplerMap mResamplerMap;
|
||||||
PResampler findResampler(int sourceRate, int destRate);
|
PResampler findResampler(int sourceRate, int destRate);
|
||||||
|
|
||||||
void preload();
|
void preload();
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef USE_WEBRTC_RESAMPLER
|
#ifdef USE_WEBRTC_RESAMPLER
|
||||||
// n*10 milliseconds buffers required!
|
// n*10 milliseconds buffers required!
|
||||||
class Resampler48kTo16k
|
class Resampler48kTo16k
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Resampler48kTo16k();
|
Resampler48kTo16k();
|
||||||
~Resampler48kTo16k();
|
~Resampler48kTo16k();
|
||||||
int process(const void* source, int sourceLen, void* dest, int destLen);
|
int process(const void* source, int sourceLen, void* dest, int destLen);
|
||||||
protected:
|
protected:
|
||||||
WebRtc_Word32 mTemp[496];
|
WebRtc_Word32 mTemp[496];
|
||||||
WebRtcSpl_State48khzTo16khz mContext;
|
WebRtcSpl_State48khzTo16khz mContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Resampler16kto48k
|
class Resampler16kto48k
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Resampler16kto48k();
|
Resampler16kto48k();
|
||||||
~Resampler16kto48k();
|
~Resampler16kto48k();
|
||||||
int process(const void* source, int sourceLen, void* dest, int destLen);
|
int process(const void* source, int sourceLen, void* dest, int destLen);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
WebRtc_Word32 mTemp[336];
|
WebRtc_Word32 mTemp[336];
|
||||||
WebRtcSpl_State16khzTo48khz mContext;
|
WebRtcSpl_State16khzTo48khz mContext;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue