OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |