2 * Copyright (c) 2014 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/neteq/tools/resample_input_audio_file.h"
13 #include "webrtc/base/checks.h"
14 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
19 bool ResampleInputAudioFile::Read(size_t samples,
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()))
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),
34 static_cast<int>(samples),
37 CHECK_EQ(static_cast<int>(samples), output_length);