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

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

Issue 2424173003: Move functionality out from AudioFrame and into AudioFrameOperations. (Closed)
Patch Set: Created 4 years, 2 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 frame->samples_per_channel_, 101 frame->samples_per_channel_,
102 static_cast<size_t>((mixed_audio->sample_rate_hz_ * 102 static_cast<size_t>((mixed_audio->sample_rate_hz_ *
103 webrtc::AudioMixerImpl::kFrameDurationInMs) / 103 webrtc::AudioMixerImpl::kFrameDurationInMs) /
104 1000)); 104 1000));
105 105
106 // Mix |f.frame| into |mixed_audio|, with saturation protection. 106 // Mix |f.frame| into |mixed_audio|, with saturation protection.
107 // These effect is applied to |f.frame| itself prior to mixing. 107 // These effect is applied to |f.frame| itself prior to mixing.
108 if (use_limiter) { 108 if (use_limiter) {
109 // Divide by two to avoid saturation in the mixing. 109 // Divide by two to avoid saturation in the mixing.
110 // This is only meaningful if the limiter will be used. 110 // This is only meaningful if the limiter will be used.
111 *frame >>= 1; 111 AudioFrameOperations::ShiftDown(frame);
112 } 112 }
113 RTC_DCHECK_EQ(frame->num_channels_, mixed_audio->num_channels_); 113 RTC_DCHECK_EQ(frame->num_channels_, mixed_audio->num_channels_);
114 *mixed_audio += *frame; 114 AudioFrameOperations::AddFrames(*frame, mixed_audio);
115 } 115 }
116 return 0; 116 return 0;
117 } 117 }
118 118
119 AudioMixerImpl::SourceStatusList::const_iterator FindSourceInList( 119 AudioMixerImpl::SourceStatusList::const_iterator FindSourceInList(
120 AudioMixerImpl::Source const* audio_source, 120 AudioMixerImpl::Source const* audio_source,
121 AudioMixerImpl::SourceStatusList const* audio_source_list) { 121 AudioMixerImpl::SourceStatusList const* audio_source_list) {
122 return std::find_if(audio_source_list->begin(), audio_source_list->end(), 122 return std::find_if(audio_source_list->begin(), audio_source_list->end(),
123 [audio_source](const AudioMixerImpl::SourceStatus& p) { 123 [audio_source](const AudioMixerImpl::SourceStatus& p) {
124 return p.audio_source == audio_source; 124 return p.audio_source == audio_source;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 AudioFrameList mix_list; 198 AudioFrameList mix_list;
199 { 199 {
200 rtc::CritScope lock(&crit_); 200 rtc::CritScope lock(&crit_);
201 mix_list = GetAudioFromSources(); 201 mix_list = GetAudioFromSources();
202 } 202 }
203 203
204 for (const auto& frame : mix_list) { 204 for (const auto& frame : mix_list) {
205 RemixFrame(number_of_channels, frame); 205 RemixFrame(number_of_channels, frame);
206 } 206 }
207 207
208 audio_frame_for_mixing->UpdateFrame( 208 AudioFrameOperations::UpdateFrame(
209 -1, time_stamp_, NULL, 0, OutputFrequency(), AudioFrame::kNormalSpeech, 209 -1, time_stamp_, NULL, 0, OutputFrequency(), AudioFrame::kNormalSpeech,
210 AudioFrame::kVadPassive, number_of_channels); 210 AudioFrame::kVadPassive, number_of_channels, audio_frame_for_mixing);
211 211
212 time_stamp_ += static_cast<uint32_t>(sample_size_); 212 time_stamp_ += static_cast<uint32_t>(sample_size_);
213 213
214 use_limiter_ = mix_list.size() > 1; 214 use_limiter_ = mix_list.size() > 1;
215 215
216 // We only use the limiter if we're actually mixing multiple streams. 216 // We only use the limiter if we're actually mixing multiple streams.
217 MixFromList(audio_frame_for_mixing, mix_list, use_limiter_); 217 MixFromList(audio_frame_for_mixing, mix_list, use_limiter_);
218 218
219 if (audio_frame_for_mixing->samples_per_channel_ == 0) { 219 if (audio_frame_for_mixing->samples_per_channel_ == 0) {
220 // Nothing was mixed, set the audio samples to silence. 220 // Nothing was mixed, set the audio samples to silence.
221 audio_frame_for_mixing->samples_per_channel_ = sample_size_; 221 audio_frame_for_mixing->samples_per_channel_ = sample_size_;
222 audio_frame_for_mixing->Mute(); 222 AudioFrameOperations::Mute(audio_frame_for_mixing);
223 } else { 223 } else {
224 // Only call the limiter if we have something to mix. 224 // Only call the limiter if we have something to mix.
225 LimitMixedAudio(audio_frame_for_mixing); 225 LimitMixedAudio(audio_frame_for_mixing);
226 } 226 }
227 227
228 return; 228 return;
229 } 229 }
230 230
231 void AudioMixerImpl::SetOutputFrequency(int frequency) { 231 void AudioMixerImpl::SetOutputFrequency(int frequency) {
232 RTC_DCHECK_RUN_ON(&thread_checker_); 232 RTC_DCHECK_RUN_ON(&thread_checker_);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // And now we can safely restore the level. This procedure results in 323 // And now we can safely restore the level. This procedure results in
324 // some loss of resolution, deemed acceptable. 324 // some loss of resolution, deemed acceptable.
325 // 325 //
326 // It's possible to apply the gain in the AGC (with a target level of 0 dbFS 326 // It's possible to apply the gain in the AGC (with a target level of 0 dbFS
327 // and compression gain of 6 dB). However, in the transition frame when this 327 // and compression gain of 6 dB). However, in the transition frame when this
328 // is enabled (moving from one to two audio sources) it has the potential to 328 // is enabled (moving from one to two audio sources) it has the potential to
329 // create discontinuities in the mixed frame. 329 // create discontinuities in the mixed frame.
330 // 330 //
331 // Instead we double the frame (with addition since left-shifting a 331 // Instead we double the frame (with addition since left-shifting a
332 // negative value is undefined). 332 // negative value is undefined).
333 *mixed_audio += *mixed_audio; 333 AudioFrameOperations::AddFrames(*mixed_audio, mixed_audio);
334 334
335 if (error != limiter_->kNoError) { 335 if (error != limiter_->kNoError) {
336 LOG_F(LS_ERROR) << "Error from AudioProcessing: " << error; 336 LOG_F(LS_ERROR) << "Error from AudioProcessing: " << error;
337 RTC_NOTREACHED(); 337 RTC_NOTREACHED();
338 return false; 338 return false;
339 } 339 }
340 return true; 340 return true;
341 } 341 }
342 342
343 bool AudioMixerImpl::GetAudioSourceMixabilityStatusForTest( 343 bool AudioMixerImpl::GetAudioSourceMixabilityStatusForTest(
344 AudioMixerImpl::Source* audio_source) const { 344 AudioMixerImpl::Source* audio_source) const {
345 RTC_DCHECK_RUN_ON(&thread_checker_); 345 RTC_DCHECK_RUN_ON(&thread_checker_);
346 rtc::CritScope lock(&crit_); 346 rtc::CritScope lock(&crit_);
347 347
348 const auto non_anonymous_iter = 348 const auto non_anonymous_iter =
349 FindSourceInList(audio_source, &audio_source_list_); 349 FindSourceInList(audio_source, &audio_source_list_);
350 if (non_anonymous_iter != audio_source_list_.end()) { 350 if (non_anonymous_iter != audio_source_list_.end()) {
351 return non_anonymous_iter->is_mixed; 351 return non_anonymous_iter->is_mixed;
352 } 352 }
353 353
354 LOG(LS_ERROR) << "Audio source unknown"; 354 LOG(LS_ERROR) << "Audio source unknown";
355 return false; 355 return false;
356 } 356 }
357 } // namespace webrtc 357 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698