2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/modules/audio_coding/main/acm2/acm_resampler.h"
16 #include "webrtc/common_audio/resampler/include/resampler.h"
17 #include "webrtc/system_wrappers/interface/logging.h"
22 ACMResampler::ACMResampler() {
25 ACMResampler::~ACMResampler() {
28 int ACMResampler::Resample10Msec(const int16_t* in_audio,
31 int num_audio_channels,
32 int out_capacity_samples,
34 int in_length = in_freq_hz * num_audio_channels / 100;
35 int out_length = out_freq_hz * num_audio_channels / 100;
36 if (in_freq_hz == out_freq_hz) {
37 if (out_capacity_samples < in_length) {
41 memcpy(out_audio, in_audio, in_length * sizeof(int16_t));
42 return in_length / num_audio_channels;
45 if (resampler_.InitializeIfNeeded(in_freq_hz, out_freq_hz,
46 num_audio_channels) != 0) {
47 LOG_FERR3(LS_ERROR, InitializeIfNeeded, in_freq_hz, out_freq_hz,
53 resampler_.Resample(in_audio, in_length, out_audio, out_capacity_samples);
54 if (out_length == -1) {
60 out_capacity_samples);
64 return out_length / num_audio_channels;