OLD | NEW |
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 |
11 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | 11 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <functional> | 14 #include <functional> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
| 17 #include "webrtc/audio/utility/audio_frame_operations.h" |
17 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
18 #include "webrtc/modules/audio_mixer/audio_frame_manipulator.h" | 19 #include "webrtc/modules/audio_mixer/audio_frame_manipulator.h" |
19 #include "webrtc/modules/utility/include/audio_frame_operations.h" | |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 namespace { | 22 namespace { |
23 | 23 |
24 struct SourceFrame { | 24 struct SourceFrame { |
25 SourceFrame(AudioMixerImpl::SourceStatus* source_status, | 25 SourceFrame(AudioMixerImpl::SourceStatus* source_status, |
26 AudioFrame* audio_frame, | 26 AudioFrame* audio_frame, |
27 bool muted) | 27 bool muted) |
28 : source_status(source_status), audio_frame(audio_frame), muted(muted) { | 28 : source_status(source_status), audio_frame(audio_frame), muted(muted) { |
29 RTC_DCHECK(source_status); | 29 RTC_DCHECK(source_status); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 RTC_DCHECK_EQ(mixed_audio->sample_rate_hz_, frame->sample_rate_hz_); | 99 RTC_DCHECK_EQ(mixed_audio->sample_rate_hz_, frame->sample_rate_hz_); |
100 RTC_DCHECK_EQ( | 100 RTC_DCHECK_EQ( |
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 // This is to avoid saturation in the mixing. It is only |
110 // This is only meaningful if the limiter will be used. | 110 // meaningful if the limiter will be used. |
111 *frame >>= 1; | 111 AudioFrameOperations::ApplyHalfGain(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::Add(*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( | 122 return std::find_if( |
123 audio_source_list->begin(), audio_source_list->end(), | 123 audio_source_list->begin(), audio_source_list->end(), |
124 [audio_source](const std::unique_ptr<AudioMixerImpl::SourceStatus>& p) { | 124 [audio_source](const std::unique_ptr<AudioMixerImpl::SourceStatus>& p) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 use_limiter_ = mix_list.size() > 1; | 244 use_limiter_ = mix_list.size() > 1; |
245 | 245 |
246 // We only use the limiter if we're actually mixing multiple streams. | 246 // We only use the limiter if we're actually mixing multiple streams. |
247 MixFromList(audio_frame_for_mixing, mix_list, use_limiter_); | 247 MixFromList(audio_frame_for_mixing, mix_list, use_limiter_); |
248 } | 248 } |
249 | 249 |
250 if (audio_frame_for_mixing->samples_per_channel_ == 0) { | 250 if (audio_frame_for_mixing->samples_per_channel_ == 0) { |
251 // Nothing was mixed, set the audio samples to silence. | 251 // Nothing was mixed, set the audio samples to silence. |
252 audio_frame_for_mixing->samples_per_channel_ = sample_size_; | 252 audio_frame_for_mixing->samples_per_channel_ = sample_size_; |
253 audio_frame_for_mixing->Mute(); | 253 AudioFrameOperations::Mute(audio_frame_for_mixing); |
254 } else { | 254 } else { |
255 // Only call the limiter if we have something to mix. | 255 // Only call the limiter if we have something to mix. |
256 LimitMixedAudio(audio_frame_for_mixing); | 256 LimitMixedAudio(audio_frame_for_mixing); |
257 } | 257 } |
258 | 258 |
259 return; | 259 return; |
260 } | 260 } |
261 | 261 |
262 void AudioMixerImpl::SetOutputFrequency(int frequency) { | 262 void AudioMixerImpl::SetOutputFrequency(int frequency) { |
263 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); | 263 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // And now we can safely restore the level. This procedure results in | 350 // And now we can safely restore the level. This procedure results in |
351 // some loss of resolution, deemed acceptable. | 351 // some loss of resolution, deemed acceptable. |
352 // | 352 // |
353 // It's possible to apply the gain in the AGC (with a target level of 0 dbFS | 353 // It's possible to apply the gain in the AGC (with a target level of 0 dbFS |
354 // and compression gain of 6 dB). However, in the transition frame when this | 354 // and compression gain of 6 dB). However, in the transition frame when this |
355 // is enabled (moving from one to two audio sources) it has the potential to | 355 // is enabled (moving from one to two audio sources) it has the potential to |
356 // create discontinuities in the mixed frame. | 356 // create discontinuities in the mixed frame. |
357 // | 357 // |
358 // Instead we double the frame (with addition since left-shifting a | 358 // Instead we double the frame (with addition since left-shifting a |
359 // negative value is undefined). | 359 // negative value is undefined). |
360 *mixed_audio += *mixed_audio; | 360 AudioFrameOperations::Add(*mixed_audio, mixed_audio); |
361 | 361 |
362 if (error != limiter_->kNoError) { | 362 if (error != limiter_->kNoError) { |
363 LOG_F(LS_ERROR) << "Error from AudioProcessing: " << error; | 363 LOG_F(LS_ERROR) << "Error from AudioProcessing: " << error; |
364 RTC_NOTREACHED(); | 364 RTC_NOTREACHED(); |
365 return false; | 365 return false; |
366 } | 366 } |
367 return true; | 367 return true; |
368 } | 368 } |
369 | 369 |
370 bool AudioMixerImpl::GetAudioSourceMixabilityStatusForTest( | 370 bool AudioMixerImpl::GetAudioSourceMixabilityStatusForTest( |
371 AudioMixerImpl::Source* audio_source) const { | 371 AudioMixerImpl::Source* audio_source) const { |
372 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); | 372 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
373 rtc::CritScope lock(&crit_); | 373 rtc::CritScope lock(&crit_); |
374 | 374 |
375 const auto iter = FindSourceInList(audio_source, &audio_source_list_); | 375 const auto iter = FindSourceInList(audio_source, &audio_source_list_); |
376 if (iter != audio_source_list_.end()) { | 376 if (iter != audio_source_list_.end()) { |
377 return (*iter)->is_mixed; | 377 return (*iter)->is_mixed; |
378 } | 378 } |
379 | 379 |
380 LOG(LS_ERROR) << "Audio source unknown"; | 380 LOG(LS_ERROR) << "Audio source unknown"; |
381 return false; | 381 return false; |
382 } | 382 } |
383 } // namespace webrtc | 383 } // namespace webrtc |
OLD | NEW |