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

Side by Side Diff: webrtc/modules/audio_coding/test/opus_test.cc

Issue 1534193008: Misc. small cleanups (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Unnecessary parens 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
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 // Close the files. 200 // Close the files.
201 in_file_stereo_.Close(); 201 in_file_stereo_.Close();
202 in_file_mono_.Close(); 202 in_file_mono_.Close();
203 out_file_.Close(); 203 out_file_.Close();
204 out_file_standalone_.Close(); 204 out_file_standalone_.Close();
205 #endif 205 #endif
206 } 206 }
207 207
208 void OpusTest::Run(TestPackStereo* channel, int channels, int bitrate, 208 void OpusTest::Run(TestPackStereo* channel, int channels, int bitrate,
209 int frame_length, int percent_loss) { 209 size_t frame_length, int percent_loss) {
210 AudioFrame audio_frame; 210 AudioFrame audio_frame;
211 int32_t out_freq_hz_b = out_file_.SamplingFrequency(); 211 int32_t out_freq_hz_b = out_file_.SamplingFrequency();
212 const int kBufferSizeSamples = 480 * 12 * 2; // Can hold 120 ms stereo audio. 212 const size_t kBufferSizeSamples = 480 * 12 * 2; // 120 ms stereo audio.
213 int16_t audio[kBufferSizeSamples]; 213 int16_t audio[kBufferSizeSamples];
214 int16_t out_audio[kBufferSizeSamples]; 214 int16_t out_audio[kBufferSizeSamples];
215 int16_t audio_type; 215 int16_t audio_type;
216 int written_samples = 0; 216 size_t written_samples = 0;
217 int read_samples = 0; 217 size_t read_samples = 0;
218 int decoded_samples = 0; 218 size_t decoded_samples = 0;
219 bool first_packet = true; 219 bool first_packet = true;
220 uint32_t start_time_stamp = 0; 220 uint32_t start_time_stamp = 0;
221 221
222 channel->reset_payload_size(); 222 channel->reset_payload_size();
223 counter_ = 0; 223 counter_ = 0;
224 224
225 // Set encoder rate. 225 // Set encoder rate.
226 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_mono_encoder_, bitrate)); 226 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_mono_encoder_, bitrate));
227 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_stereo_encoder_, bitrate)); 227 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_stereo_encoder_, bitrate));
228 228
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 resampler_.Resample10Msec(audio_frame.data_, 261 resampler_.Resample10Msec(audio_frame.data_,
262 audio_frame.sample_rate_hz_, 262 audio_frame.sample_rate_hz_,
263 48000, 263 48000,
264 channels, 264 channels,
265 kBufferSizeSamples - written_samples, 265 kBufferSizeSamples - written_samples,
266 &audio[written_samples])); 266 &audio[written_samples]));
267 written_samples += 480 * channels; 267 written_samples += 480 * channels;
268 268
269 // Sometimes we need to loop over the audio vector to produce the right 269 // Sometimes we need to loop over the audio vector to produce the right
270 // number of packets. 270 // number of packets.
271 int loop_encode = (written_samples - read_samples) / 271 size_t loop_encode = (written_samples - read_samples) /
272 (channels * frame_length); 272 (channels * frame_length);
273 273
274 if (loop_encode > 0) { 274 if (loop_encode > 0) {
275 const int kMaxBytes = 1000; // Maximum number of bytes for one packet. 275 const size_t kMaxBytes = 1000; // Maximum number of bytes for one packet.
276 size_t bitstream_len_byte; 276 size_t bitstream_len_byte;
277 uint8_t bitstream[kMaxBytes]; 277 uint8_t bitstream[kMaxBytes];
278 for (int i = 0; i < loop_encode; i++) { 278 for (size_t i = 0; i < loop_encode; i++) {
279 int bitstream_len_byte_int = WebRtcOpus_Encode( 279 int bitstream_len_byte_int = WebRtcOpus_Encode(
280 (channels == 1) ? opus_mono_encoder_ : opus_stereo_encoder_, 280 (channels == 1) ? opus_mono_encoder_ : opus_stereo_encoder_,
281 &audio[read_samples], frame_length, kMaxBytes, bitstream); 281 &audio[read_samples], frame_length, kMaxBytes, bitstream);
282 ASSERT_GE(bitstream_len_byte_int, 0); 282 ASSERT_GE(bitstream_len_byte_int, 0);
283 bitstream_len_byte = static_cast<size_t>(bitstream_len_byte_int); 283 bitstream_len_byte = static_cast<size_t>(bitstream_len_byte_int);
284 284
285 // Simulate packet loss by setting |packet_loss_| to "true" in 285 // Simulate packet loss by setting |packet_loss_| to "true" in
286 // |percent_loss| percent of the loops. 286 // |percent_loss| percent of the loops.
287 // TODO(tlegrand): Move handling of loss simulation to TestPackStereo. 287 // TODO(tlegrand): Move handling of loss simulation to TestPackStereo.
288 if (percent_loss > 0) { 288 if (percent_loss > 0) {
(...skipping 30 matching lines...) Expand all
319 } 319 }
320 } 320 }
321 321
322 // Send data to the channel. "channel" will handle the loss simulation. 322 // Send data to the channel. "channel" will handle the loss simulation.
323 channel->SendData(kAudioFrameSpeech, payload_type_, rtp_timestamp_, 323 channel->SendData(kAudioFrameSpeech, payload_type_, rtp_timestamp_,
324 bitstream, bitstream_len_byte, NULL); 324 bitstream, bitstream_len_byte, NULL);
325 if (first_packet) { 325 if (first_packet) {
326 first_packet = false; 326 first_packet = false;
327 start_time_stamp = rtp_timestamp_; 327 start_time_stamp = rtp_timestamp_;
328 } 328 }
329 rtp_timestamp_ += frame_length; 329 rtp_timestamp_ += static_cast<uint32_t>(frame_length);
330 read_samples += frame_length * channels; 330 read_samples += frame_length * channels;
331 } 331 }
332 if (read_samples == written_samples) { 332 if (read_samples == written_samples) {
333 read_samples = 0; 333 read_samples = 0;
334 written_samples = 0; 334 written_samples = 0;
335 } 335 }
336 } 336 }
337 337
338 // Run received side of ACM. 338 // Run received side of ACM.
339 ASSERT_EQ(0, acm_receiver_->PlayoutData10Ms(out_freq_hz_b, &audio_frame)); 339 ASSERT_EQ(0, acm_receiver_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
340 340
341 // Write output speech to file. 341 // Write output speech to file.
342 out_file_.Write10MsData( 342 out_file_.Write10MsData(
343 audio_frame.data_, 343 audio_frame.data_,
344 audio_frame.samples_per_channel_ * audio_frame.num_channels_); 344 audio_frame.samples_per_channel_ * audio_frame.num_channels_);
345 345
346 // Write stand-alone speech to file. 346 // Write stand-alone speech to file.
347 out_file_standalone_.Write10MsData( 347 out_file_standalone_.Write10MsData(out_audio, decoded_samples * channels);
348 out_audio, static_cast<size_t>(decoded_samples) * channels);
349 348
350 if (audio_frame.timestamp_ > start_time_stamp) { 349 if (audio_frame.timestamp_ > start_time_stamp) {
351 // Number of channels should be the same for both stand-alone and 350 // Number of channels should be the same for both stand-alone and
352 // ACM-decoding. 351 // ACM-decoding.
353 EXPECT_EQ(audio_frame.num_channels_, channels); 352 EXPECT_EQ(audio_frame.num_channels_, channels);
354 } 353 }
355 354
356 decoded_samples = 0; 355 decoded_samples = 0;
357 } 356 }
358 357
(...skipping 16 matching lines...) Expand all
375 out_file_.Open(file_name, 48000, "wb"); 374 out_file_.Open(file_name, 48000, "wb");
376 file_stream.str(""); 375 file_stream.str("");
377 file_name = file_stream.str(); 376 file_name = file_stream.str();
378 file_stream << webrtc::test::OutputPath() << "opusstandalone_out_" 377 file_stream << webrtc::test::OutputPath() << "opusstandalone_out_"
379 << test_number << ".pcm"; 378 << test_number << ".pcm";
380 file_name = file_stream.str(); 379 file_name = file_stream.str();
381 out_file_standalone_.Open(file_name, 48000, "wb"); 380 out_file_standalone_.Open(file_name, 48000, "wb");
382 } 381 }
383 382
384 } // namespace webrtc 383 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/test/opus_test.h ('k') | webrtc/modules/audio_device/dummy/file_audio_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698