Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_coding / neteq / tools / resample_input_audio_file.cc
1 /*
2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3  *
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.
9  */
10
11 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
15
16 namespace webrtc {
17 namespace test {
18
19 bool ResampleInputAudioFile::Read(size_t samples,
20                                   int output_rate_hz,
21                                   int16_t* destination) {
22   const size_t samples_to_read = samples * file_rate_hz_ / output_rate_hz;
23   CHECK_EQ(samples_to_read * output_rate_hz, samples * file_rate_hz_)
24       << "Frame size and sample rates don't add up to an integer.";
25   scoped_ptr<int16_t[]> temp_destination(new int16_t[samples_to_read]);
26   if (!InputAudioFile::Read(samples_to_read, temp_destination.get()))
27     return false;
28   resampler_.ResetIfNeeded(
29       file_rate_hz_, output_rate_hz, kResamplerSynchronous);
30   int output_length = 0;
31   CHECK_EQ(resampler_.Push(temp_destination.get(),
32                            static_cast<int>(samples_to_read),
33                            destination,
34                            static_cast<int>(samples),
35                            output_length),
36            0);
37   CHECK_EQ(static_cast<int>(samples), output_length);
38   return true;
39 }
40
41 }  // namespace test
42 }  // namespace webrtc