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/base/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 RTC_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 rtc::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(file_rate_hz_, output_rate_hz, 1); 29 size_t output_length = 0; 30 RTC_CHECK_EQ(resampler_.Push(temp_destination.get(), samples_to_read, 31 destination, samples, output_length), 32 0); 33 RTC_CHECK_EQ(samples, output_length); 34 return true; 35 } 36 37 bool ResampleInputAudioFile::Read(size_t samples, int16_t* destination) { 38 RTC_CHECK_GT(output_rate_hz_, 0) << "Output rate not set."; 39 return Read(samples, output_rate_hz_, destination); 40 } 41 42 void ResampleInputAudioFile::set_output_rate_hz(int rate_hz) { 43 output_rate_hz_ = rate_hz; 44 } 45 46 } // namespace test 47 } // namespace webrtc 48