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

Side by Side Diff: webrtc/modules/audio_coding/main/test/PCMFile.cc

Issue 1225133003: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comment Created 5 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void PCMFile::Write10MsData(AudioFrame& audio_frame) { 143 void PCMFile::Write10MsData(AudioFrame& audio_frame) {
144 if (audio_frame.num_channels_ == 1) { 144 if (audio_frame.num_channels_ == 1) {
145 if (!save_stereo_) { 145 if (!save_stereo_) {
146 if (fwrite(audio_frame.data_, sizeof(uint16_t), 146 if (fwrite(audio_frame.data_, sizeof(uint16_t),
147 audio_frame.samples_per_channel_, pcm_file_) != 147 audio_frame.samples_per_channel_, pcm_file_) !=
148 static_cast<size_t>(audio_frame.samples_per_channel_)) { 148 static_cast<size_t>(audio_frame.samples_per_channel_)) {
149 return; 149 return;
150 } 150 }
151 } else { 151 } else {
152 int16_t* stereo_audio = new int16_t[2 * audio_frame.samples_per_channel_]; 152 int16_t* stereo_audio = new int16_t[2 * audio_frame.samples_per_channel_];
153 int k; 153 size_t k;
154 for (k = 0; k < audio_frame.samples_per_channel_; k++) { 154 for (k = 0; k < audio_frame.samples_per_channel_; k++) {
155 stereo_audio[k << 1] = audio_frame.data_[k]; 155 stereo_audio[k << 1] = audio_frame.data_[k];
156 stereo_audio[(k << 1) + 1] = audio_frame.data_[k]; 156 stereo_audio[(k << 1) + 1] = audio_frame.data_[k];
157 } 157 }
158 if (fwrite(stereo_audio, sizeof(int16_t), 158 if (fwrite(stereo_audio, sizeof(int16_t),
159 2 * audio_frame.samples_per_channel_, pcm_file_) != 159 2 * audio_frame.samples_per_channel_, pcm_file_) !=
160 static_cast<size_t>(2 * audio_frame.samples_per_channel_)) { 160 static_cast<size_t>(2 * audio_frame.samples_per_channel_)) {
161 return; 161 return;
162 } 162 }
163 delete[] stereo_audio; 163 delete[] stereo_audio;
164 } 164 }
165 } else { 165 } else {
166 if (fwrite(audio_frame.data_, sizeof(int16_t), 166 if (fwrite(audio_frame.data_, sizeof(int16_t),
167 audio_frame.num_channels_ * audio_frame.samples_per_channel_, 167 audio_frame.num_channels_ * audio_frame.samples_per_channel_,
168 pcm_file_) != 168 pcm_file_) !=
169 static_cast<size_t>(audio_frame.num_channels_ * 169 static_cast<size_t>(audio_frame.num_channels_ *
170 audio_frame.samples_per_channel_)) { 170 audio_frame.samples_per_channel_)) {
171 return; 171 return;
172 } 172 }
173 } 173 }
174 } 174 }
175 175
176 void PCMFile::Write10MsData(int16_t* playout_buffer, uint16_t length_smpls) { 176 void PCMFile::Write10MsData(int16_t* playout_buffer, size_t length_smpls) {
177 if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) != 177 if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) !=
178 length_smpls) { 178 length_smpls) {
179 return; 179 return;
180 } 180 }
181 } 181 }
182 182
183 void PCMFile::Close() { 183 void PCMFile::Close() {
184 fclose(pcm_file_); 184 fclose(pcm_file_);
185 pcm_file_ = NULL; 185 pcm_file_ = NULL;
186 } 186 }
187 187
188 void PCMFile::Rewind() { 188 void PCMFile::Rewind() {
189 rewind(pcm_file_); 189 rewind(pcm_file_);
190 end_of_file_ = false; 190 end_of_file_ = false;
191 } 191 }
192 192
193 bool PCMFile::Rewinded() { 193 bool PCMFile::Rewinded() {
194 return rewinded_; 194 return rewinded_;
195 } 195 }
196 196
197 void PCMFile::SaveStereo(bool is_stereo) { 197 void PCMFile::SaveStereo(bool is_stereo) {
198 save_stereo_ = is_stereo; 198 save_stereo_ = is_stereo;
199 } 199 }
200 200
201 void PCMFile::ReadStereo(bool is_stereo) { 201 void PCMFile::ReadStereo(bool is_stereo) {
202 read_stereo_ = is_stereo; 202 read_stereo_ = is_stereo;
203 } 203 }
204 204
205 } // namespace webrtc 205 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/main/test/PCMFile.h ('k') | webrtc/modules/audio_coding/main/test/SpatialAudio.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698