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

Side by Side Diff: webrtc/modules/audio_mixer/audio_mixer_impl_unittest.cc

Issue 2750783004: Add mute state field to AudioFrame. (Closed)
Patch Set: Update new usages of AudioFrame::data_ Created 3 years, 6 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 const auto mixer = AudioMixerImpl::Create(); 163 const auto mixer = AudioMixerImpl::Create();
164 164
165 MockMixerAudioSource participants[kAudioSources]; 165 MockMixerAudioSource participants[kAudioSources];
166 166
167 for (int i = 0; i < kAudioSources; ++i) { 167 for (int i = 0; i < kAudioSources; ++i) {
168 ResetFrame(participants[i].fake_frame()); 168 ResetFrame(participants[i].fake_frame());
169 169
170 // We set the 80-th sample value since the first 80 samples may be 170 // We set the 80-th sample value since the first 80 samples may be
171 // modified by a ramped-in window. 171 // modified by a ramped-in window.
172 participants[i].fake_frame()->data_[80] = i; 172 participants[i].fake_frame()->mutable_data()[80] = i;
173 173
174 EXPECT_TRUE(mixer->AddSource(&participants[i])); 174 EXPECT_TRUE(mixer->AddSource(&participants[i]));
175 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(_, _)).Times(Exactly(1)); 175 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(_, _)).Times(Exactly(1));
176 } 176 }
177 177
178 // Last participant gives audio frame with passive VAD, although it has the 178 // Last participant gives audio frame with passive VAD, although it has the
179 // largest energy. 179 // largest energy.
180 participants[kAudioSources - 1].fake_frame()->vad_activity_ = 180 participants[kAudioSources - 1].fake_frame()->vad_activity_ =
181 AudioFrame::kVadPassive; 181 AudioFrame::kVadPassive;
182 182
(...skipping 18 matching lines...) Expand all
201 201
202 TEST(AudioMixer, FrameNotModifiedForSingleParticipant) { 202 TEST(AudioMixer, FrameNotModifiedForSingleParticipant) {
203 const auto mixer = AudioMixerImpl::Create(); 203 const auto mixer = AudioMixerImpl::Create();
204 204
205 MockMixerAudioSource participant; 205 MockMixerAudioSource participant;
206 206
207 ResetFrame(participant.fake_frame()); 207 ResetFrame(participant.fake_frame());
208 const size_t n_samples = participant.fake_frame()->samples_per_channel_; 208 const size_t n_samples = participant.fake_frame()->samples_per_channel_;
209 209
210 // Modify the frame so that it's not zero. 210 // Modify the frame so that it's not zero.
211 int16_t* fake_frame_data = participant.fake_frame()->mutable_data();
211 for (size_t j = 0; j < n_samples; ++j) { 212 for (size_t j = 0; j < n_samples; ++j) {
212 participant.fake_frame()->data_[j] = static_cast<int16_t>(j); 213 fake_frame_data[j] = static_cast<int16_t>(j);
213 } 214 }
214 215
215 EXPECT_TRUE(mixer->AddSource(&participant)); 216 EXPECT_TRUE(mixer->AddSource(&participant));
216 EXPECT_CALL(participant, GetAudioFrameWithInfo(_, _)).Times(Exactly(2)); 217 EXPECT_CALL(participant, GetAudioFrameWithInfo(_, _)).Times(Exactly(2));
217 218
218 AudioFrame audio_frame; 219 AudioFrame audio_frame;
219 // Two mix iteration to compare after the ramp-up step. 220 // Two mix iteration to compare after the ramp-up step.
220 for (int i = 0; i < 2; ++i) { 221 for (int i = 0; i < 2; ++i) {
221 mixer->Mix(1, // number of channels 222 mixer->Mix(1, // number of channels
222 &audio_frame); 223 &audio_frame);
223 } 224 }
224 225
225 EXPECT_EQ( 226 EXPECT_EQ(
226 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples)); 227 0,
228 memcmp(participant.fake_frame()->data(), audio_frame.data(), n_samples));
227 } 229 }
228 230
229 TEST(AudioMixer, SourceAtNativeRateShouldNeverResample) { 231 TEST(AudioMixer, SourceAtNativeRateShouldNeverResample) {
230 const auto mixer = AudioMixerImpl::Create(); 232 const auto mixer = AudioMixerImpl::Create();
231 233
232 MockMixerAudioSource audio_source; 234 MockMixerAudioSource audio_source;
233 ResetFrame(audio_source.fake_frame()); 235 ResetFrame(audio_source.fake_frame());
234 236
235 mixer->AddSource(&audio_source); 237 mixer->AddSource(&audio_source);
236 238
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 constexpr int kAudioSources = 323 constexpr int kAudioSources =
322 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1; 324 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1;
323 325
324 const auto mixer = AudioMixerImpl::Create(); 326 const auto mixer = AudioMixerImpl::Create();
325 MockMixerAudioSource participants[kAudioSources]; 327 MockMixerAudioSource participants[kAudioSources];
326 328
327 for (int i = 0; i < kAudioSources; ++i) { 329 for (int i = 0; i < kAudioSources; ++i) {
328 ResetFrame(participants[i].fake_frame()); 330 ResetFrame(participants[i].fake_frame());
329 // Set the participant audio energy to increase with the index 331 // Set the participant audio energy to increase with the index
330 // |i|. 332 // |i|.
331 participants[i].fake_frame()->data_[0] = 100 * i; 333 participants[i].fake_frame()->mutable_data()[0] = 100 * i;
332 } 334 }
333 335
334 // Add all participants but the loudest for mixing. 336 // Add all participants but the loudest for mixing.
335 for (int i = 0; i < kAudioSources - 1; ++i) { 337 for (int i = 0; i < kAudioSources - 1; ++i) {
336 EXPECT_TRUE(mixer->AddSource(&participants[i])); 338 EXPECT_TRUE(mixer->AddSource(&participants[i]));
337 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(kDefaultSampleRateHz, _)) 339 EXPECT_CALL(participants[i], GetAudioFrameWithInfo(kDefaultSampleRateHz, _))
338 .Times(Exactly(1)); 340 .Times(Exactly(1));
339 } 341 }
340 342
341 // First mixer iteration 343 // First mixer iteration
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1; 439 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1;
438 440
439 std::vector<AudioFrame> frames(kAudioSources); 441 std::vector<AudioFrame> frames(kAudioSources);
440 for (auto& frame : frames) { 442 for (auto& frame : frames) {
441 ResetFrame(&frame); 443 ResetFrame(&frame);
442 } 444 }
443 445
444 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( 446 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
445 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 447 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
446 frames[0].vad_activity_ = AudioFrame::kVadPassive; 448 frames[0].vad_activity_ = AudioFrame::kVadPassive;
447 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, 449 int16_t* frame_data = frames[0].mutable_data();
450 std::fill(frame_data, frame_data + kDefaultSampleRateHz / 100,
448 std::numeric_limits<int16_t>::max()); 451 std::numeric_limits<int16_t>::max());
449 std::vector<bool> expected_status(kAudioSources, true); 452 std::vector<bool> expected_status(kAudioSources, true);
450 expected_status[0] = false; 453 expected_status[0] = false;
451 454
452 MixAndCompare(frames, frame_info, expected_status); 455 MixAndCompare(frames, frame_info, expected_status);
453 } 456 }
454 457
455 TEST(AudioMixer, UnmutedShouldMixBeforeLoud) { 458 TEST(AudioMixer, UnmutedShouldMixBeforeLoud) {
456 constexpr int kAudioSources = 459 constexpr int kAudioSources =
457 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1; 460 AudioMixerImpl::kMaximumAmountOfMixedAudioSources + 1;
458 461
459 std::vector<AudioFrame> frames(kAudioSources); 462 std::vector<AudioFrame> frames(kAudioSources);
460 for (auto& frame : frames) { 463 for (auto& frame : frames) {
461 ResetFrame(&frame); 464 ResetFrame(&frame);
462 } 465 }
463 466
464 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info( 467 std::vector<AudioMixer::Source::AudioFrameInfo> frame_info(
465 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal); 468 kAudioSources, AudioMixer::Source::AudioFrameInfo::kNormal);
466 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted; 469 frame_info[0] = AudioMixer::Source::AudioFrameInfo::kMuted;
467 std::fill(frames[0].data_, frames[0].data_ + kDefaultSampleRateHz / 100, 470 int16_t* frame_data = frames[0].mutable_data();
471 std::fill(frame_data, frame_data + kDefaultSampleRateHz / 100,
468 std::numeric_limits<int16_t>::max()); 472 std::numeric_limits<int16_t>::max());
469 std::vector<bool> expected_status(kAudioSources, true); 473 std::vector<bool> expected_status(kAudioSources, true);
470 expected_status[0] = false; 474 expected_status[0] = false;
471 475
472 MixAndCompare(frames, frame_info, expected_status); 476 MixAndCompare(frames, frame_info, expected_status);
473 } 477 }
474 478
475 TEST(AudioMixer, MixingRateShouldBeDecidedByRateCalculator) { 479 TEST(AudioMixer, MixingRateShouldBeDecidedByRateCalculator) {
476 constexpr int kOutputRate = 22000; 480 constexpr int kOutputRate = 22000;
477 const auto mixer = 481 const auto mixer =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 531 }
528 532
529 mixer->Mix(number_of_channels, &frame_for_mixing); 533 mixer->Mix(number_of_channels, &frame_for_mixing);
530 EXPECT_EQ(rate, frame_for_mixing.sample_rate_hz_); 534 EXPECT_EQ(rate, frame_for_mixing.sample_rate_hz_);
531 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_); 535 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_);
532 } 536 }
533 } 537 }
534 } 538 }
535 } 539 }
536 } // namespace webrtc 540 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_mixer/audio_frame_manipulator_unittest.cc ('k') | webrtc/modules/audio_mixer/frame_combiner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698