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

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

Issue 1612053002: Fix a bug in InputAudioFile::Read (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
(...skipping 12 matching lines...) Expand all
23 23
24 bool InputAudioFile::Read(size_t samples, int16_t* destination) { 24 bool InputAudioFile::Read(size_t samples, int16_t* destination) {
25 if (!fp_) { 25 if (!fp_) {
26 return false; 26 return false;
27 } 27 }
28 size_t samples_read = fread(destination, sizeof(int16_t), samples, fp_); 28 size_t samples_read = fread(destination, sizeof(int16_t), samples, fp_);
29 if (samples_read < samples) { 29 if (samples_read < samples) {
30 // Rewind and read the missing samples. 30 // Rewind and read the missing samples.
31 rewind(fp_); 31 rewind(fp_);
32 size_t missing_samples = samples - samples_read; 32 size_t missing_samples = samples - samples_read;
33 if (fread(destination, sizeof(int16_t), missing_samples, fp_) < 33 if (fread(destination + samples_read, sizeof(int16_t), missing_samples,
34 missing_samples) { 34 fp_) < missing_samples) {
35 // Could not read enough even after rewinding the file. 35 // Could not read enough even after rewinding the file.
36 return false; 36 return false;
37 } 37 }
38 } 38 }
39 return true; 39 return true;
40 } 40 }
41 41
42 bool InputAudioFile::Seek(int samples) { 42 bool InputAudioFile::Seek(int samples) {
43 if (!fp_) { 43 if (!fp_) {
44 return false; 44 return false;
(...skipping 23 matching lines...) Expand all
68 // |source| and |destination| are the same array). 68 // |source| and |destination| are the same array).
69 for (int i = static_cast<int>(samples - 1); i >= 0; --i) { 69 for (int i = static_cast<int>(samples - 1); i >= 0; --i) {
70 for (int j = static_cast<int>(channels - 1); j >= 0; --j) { 70 for (int j = static_cast<int>(channels - 1); j >= 0; --j) {
71 destination[i * channels + j] = source[i]; 71 destination[i * channels + j] = source[i];
72 } 72 }
73 } 73 }
74 } 74 }
75 75
76 } // namespace test 76 } // namespace test
77 } // namespace webrtc 77 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698