Replace the old resampler with SincResampler in the voice engine signal path.

* The old resampler was found to have a wraparound bug.
* Remove support for the old resampler from PushResampler.
* Use PushResampler in AudioCodingModule.
* The old resampler must still be removed from the file utility.

BUG=webrtc:1867,webrtc:827
TESTED=unit tests, Chrome using apprtc and voe_cmd_test to verify wrap-around is corrected, voe_cmd_test running through all supported codec sample rates and channels to verify good quality audio
R=henrika@webrtc.org, turaj@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1590004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4156 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org
2013-06-03 19:00:29 +00:00
parent 31c5f1c91a
commit c1eb560a5c
7 changed files with 37 additions and 159 deletions

View File

@ -12,19 +12,15 @@
#include <string.h>
#include "webrtc/common_audio/resampler/include/resampler.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
#include "webrtc/common_audio/resampler/include/push_resampler.h"
#include "webrtc/system_wrappers/interface/logging.h"
namespace webrtc {
ACMResampler::ACMResampler()
: resampler_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()) {
ACMResampler::ACMResampler() {
}
ACMResampler::~ACMResampler() {
delete resampler_crit_sect_;
}
int16_t ACMResampler::Resample10Msec(const int16_t* in_audio,
@ -32,42 +28,32 @@ int16_t ACMResampler::Resample10Msec(const int16_t* in_audio,
int16_t* out_audio,
int32_t out_freq_hz,
uint8_t num_audio_channels) {
CriticalSectionScoped cs(resampler_crit_sect_);
if (in_freq_hz == out_freq_hz) {
size_t length = static_cast<size_t>(in_freq_hz * num_audio_channels / 100);
memcpy(out_audio, in_audio, length * sizeof(int16_t));
return static_cast<int16_t>(in_freq_hz / 100);
}
// |maxLen| is maximum number of samples for 10ms at 48kHz.
int max_len = 480 * num_audio_channels;
int length_in = (int16_t)(in_freq_hz / 100) * num_audio_channels;
int out_len;
// |max_length| is the maximum number of samples for 10ms at 48kHz.
// TODO(turajs): is this actually the capacity of the |out_audio| buffer?
int max_length = 480 * num_audio_channels;
int in_length = in_freq_hz / 100 * num_audio_channels;
int32_t ret;
ResamplerType type;
type = (num_audio_channels == 1) ? kResamplerSynchronous :
kResamplerSynchronousStereo;
ret = resampler_.ResetIfNeeded(in_freq_hz, out_freq_hz, type);
if (ret < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, 0,
"Error in reset of resampler");
if (resampler_.InitializeIfNeeded(in_freq_hz, out_freq_hz,
num_audio_channels) != 0) {
LOG_FERR3(LS_ERROR, InitializeIfNeeded, in_freq_hz, out_freq_hz,
num_audio_channels);
return -1;
}
ret = resampler_.Push(in_audio, length_in, out_audio, max_len, out_len);
if (ret < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, 0,
"Error in resampler: resampler.Push");
int out_length = resampler_.Resample(in_audio, in_length, out_audio,
max_length);
if (out_length == -1) {
LOG_FERR4(LS_ERROR, Resample, in_audio, in_length, out_audio, max_length);
return -1;
}
int16_t out_audio_len_smpl = (int16_t) out_len /
num_audio_channels;
return out_audio_len_smpl;
return out_length / num_audio_channels;
}
} // namespace webrtc

View File

@ -11,13 +11,11 @@
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RESAMPLER_H_
#include "webrtc/common_audio/resampler/include/resampler.h"
#include "webrtc/common_audio/resampler/include/push_resampler.h"
#include "webrtc/typedefs.h"
namespace webrtc {
class CriticalSectionWrapper;
class ACMResampler {
public:
ACMResampler();
@ -30,9 +28,7 @@ class ACMResampler {
uint8_t num_audio_channels);
private:
// Use the Resampler class.
Resampler resampler_;
CriticalSectionWrapper* resampler_crit_sect_;
PushResampler resampler_;
};
} // namespace webrtc