Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.cc

Issue 1228843002: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h" 11 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/scoped_ptr.h" 14 #include "webrtc/base/scoped_ptr.h"
15 15
16 namespace webrtc { 16 namespace webrtc {
17 namespace test { 17 namespace test {
18 18
19 bool ResampleInputAudioFile::Read(size_t samples, 19 bool ResampleInputAudioFile::Read(size_t samples,
20 int output_rate_hz, 20 int output_rate_hz,
21 int16_t* destination) { 21 int16_t* destination) {
22 const size_t samples_to_read = samples * file_rate_hz_ / output_rate_hz; 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_) 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."; 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]); 25 rtc::scoped_ptr<int16_t[]> temp_destination(new int16_t[samples_to_read]);
26 if (!InputAudioFile::Read(samples_to_read, temp_destination.get())) 26 if (!InputAudioFile::Read(samples_to_read, temp_destination.get()))
27 return false; 27 return false;
28 resampler_.ResetIfNeeded(file_rate_hz_, output_rate_hz, 1); 28 resampler_.ResetIfNeeded(file_rate_hz_, output_rate_hz, 1);
29 int output_length = 0; 29 size_t output_length = 0;
30 CHECK_EQ(resampler_.Push(temp_destination.get(), 30 CHECK_EQ(resampler_.Push(temp_destination.get(), samples_to_read, destination,
31 static_cast<int>(samples_to_read), 31 samples, output_length),
32 destination,
33 static_cast<int>(samples),
34 output_length),
35 0); 32 0);
36 CHECK_EQ(static_cast<int>(samples), output_length); 33 CHECK_EQ(samples, output_length);
37 return true; 34 return true;
38 } 35 }
39 36
40 bool ResampleInputAudioFile::Read(size_t samples, int16_t* destination) { 37 bool ResampleInputAudioFile::Read(size_t samples, int16_t* destination) {
41 CHECK_GT(output_rate_hz_, 0) << "Output rate not set."; 38 CHECK_GT(output_rate_hz_, 0) << "Output rate not set.";
42 return Read(samples, output_rate_hz_, destination); 39 return Read(samples, output_rate_hz_, destination);
43 } 40 }
44 41
45 void ResampleInputAudioFile::set_output_rate_hz(int rate_hz) { 42 void ResampleInputAudioFile::set_output_rate_hz(int rate_hz) {
46 output_rate_hz_ = rate_hz; 43 output_rate_hz_ = rate_hz;
47 } 44 }
48 45
49 } // namespace test 46 } // namespace test
50 } // namespace webrtc 47 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698