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

Side by Side Diff: webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc

Issue 2424173003: Move functionality out from AudioFrame and into AudioFrameOperations. (Closed)
Patch Set: Include order & DCHECKs. Created 4 years 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
« no previous file with comments | « webrtc/modules/audio_conference_mixer/DEPS ('k') | webrtc/modules/audio_mixer/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "webrtc/audio/utility/audio_frame_operations.h"
11 #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_d efines.h" 12 #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_d efines.h"
12 #include "webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_im pl.h" 13 #include "webrtc/modules/audio_conference_mixer/source/audio_conference_mixer_im pl.h"
13 #include "webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h " 14 #include "webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h "
14 #include "webrtc/modules/audio_processing/include/audio_processing.h" 15 #include "webrtc/modules/audio_processing/include/audio_processing.h"
15 #include "webrtc/modules/utility/include/audio_frame_operations.h"
16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
17 #include "webrtc/system_wrappers/include/trace.h" 17 #include "webrtc/system_wrappers/include/trace.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 namespace { 20 namespace {
21 21
22 struct ParticipantFrameStruct { 22 struct ParticipantFrameStruct {
23 ParticipantFrameStruct(MixerParticipant* p, AudioFrame* a, bool m) 23 ParticipantFrameStruct(MixerParticipant* p, AudioFrame* a, bool m)
24 : participant(p), audioFrame(a), muted(m) {} 24 : participant(p), audioFrame(a), muted(m) {}
25 MixerParticipant* participant; 25 MixerParticipant* participant;
26 AudioFrame* audioFrame; 26 AudioFrame* audioFrame;
27 bool muted; 27 bool muted;
28 }; 28 };
29 29
30 typedef std::list<ParticipantFrameStruct*> ParticipantFrameStructList; 30 typedef std::list<ParticipantFrameStruct*> ParticipantFrameStructList;
31 31
32 // Mix |frame| into |mixed_frame|, with saturation protection and upmixing. 32 // Mix |frame| into |mixed_frame|, with saturation protection and upmixing.
33 // These effects are applied to |frame| itself prior to mixing. Assumes that 33 // These effects are applied to |frame| itself prior to mixing. Assumes that
34 // |mixed_frame| always has at least as many channels as |frame|. Supports 34 // |mixed_frame| always has at least as many channels as |frame|. Supports
35 // stereo at most. 35 // stereo at most.
36 // 36 //
37 // TODO(andrew): consider not modifying |frame| here. 37 // TODO(andrew): consider not modifying |frame| here.
38 void MixFrames(AudioFrame* mixed_frame, AudioFrame* frame, bool use_limiter) { 38 void MixFrames(AudioFrame* mixed_frame, AudioFrame* frame, bool use_limiter) {
39 assert(mixed_frame->num_channels_ >= frame->num_channels_); 39 assert(mixed_frame->num_channels_ >= frame->num_channels_);
40 if (use_limiter) { 40 if (use_limiter) {
41 // Divide by two to avoid saturation in the mixing. 41 // This is to avoid saturation in the mixing. It is only
42 // This is only meaningful if the limiter will be used. 42 // meaningful if the limiter will be used.
43 *frame >>= 1; 43 AudioFrameOperations::ApplyHalfGain(frame);
44 } 44 }
45 if (mixed_frame->num_channels_ > frame->num_channels_) { 45 if (mixed_frame->num_channels_ > frame->num_channels_) {
46 // We only support mono-to-stereo. 46 // We only support mono-to-stereo.
47 assert(mixed_frame->num_channels_ == 2 && 47 assert(mixed_frame->num_channels_ == 2 &&
48 frame->num_channels_ == 1); 48 frame->num_channels_ == 1);
49 AudioFrameOperations::MonoToStereo(frame); 49 AudioFrameOperations::MonoToStereo(frame);
50 } 50 }
51 51
52 *mixed_frame += *frame; 52 AudioFrameOperations::Add(*frame, mixed_frame);
53 } 53 }
54 54
55 // Return the max number of channels from a |list| composed of AudioFrames. 55 // Return the max number of channels from a |list| composed of AudioFrames.
56 size_t MaxNumChannels(const AudioFrameList* list) { 56 size_t MaxNumChannels(const AudioFrameList* list) {
57 size_t max_num_channels = 1; 57 size_t max_num_channels = 1;
58 for (AudioFrameList::const_iterator iter = list->begin(); 58 for (AudioFrameList::const_iterator iter = list->begin();
59 iter != list->end(); 59 iter != list->end();
60 ++iter) { 60 ++iter) {
61 max_num_channels = std::max(max_num_channels, (*iter).frame->num_channels_); 61 max_num_channels = std::max(max_num_channels, (*iter).frame->num_channels_);
62 } 62 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 _numMixedParticipants > 1 && 296 _numMixedParticipants > 1 &&
297 _outputFrequency <= AudioProcessing::kMaxNativeSampleRateHz; 297 _outputFrequency <= AudioProcessing::kMaxNativeSampleRateHz;
298 298
299 MixFromList(mixedAudio, mixList); 299 MixFromList(mixedAudio, mixList);
300 MixAnonomouslyFromList(mixedAudio, additionalFramesList); 300 MixAnonomouslyFromList(mixedAudio, additionalFramesList);
301 MixAnonomouslyFromList(mixedAudio, rampOutList); 301 MixAnonomouslyFromList(mixedAudio, rampOutList);
302 302
303 if(mixedAudio->samples_per_channel_ == 0) { 303 if(mixedAudio->samples_per_channel_ == 0) {
304 // Nothing was mixed, set the audio samples to silence. 304 // Nothing was mixed, set the audio samples to silence.
305 mixedAudio->samples_per_channel_ = _sampleSize; 305 mixedAudio->samples_per_channel_ = _sampleSize;
306 mixedAudio->Mute(); 306 AudioFrameOperations::Mute(mixedAudio);
307 } else { 307 } else {
308 // Only call the limiter if we have something to mix. 308 // Only call the limiter if we have something to mix.
309 LimitMixedAudio(mixedAudio); 309 LimitMixedAudio(mixedAudio);
310 } 310 }
311 } 311 }
312 312
313 { 313 {
314 CriticalSectionScoped cs(_cbCrit.get()); 314 CriticalSectionScoped cs(_cbCrit.get());
315 if(_mixReceiver != NULL) { 315 if(_mixReceiver != NULL) {
316 const AudioFrame** dummy = NULL; 316 const AudioFrame** dummy = NULL;
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 // And now we can safely restore the level. This procedure results in 915 // And now we can safely restore the level. This procedure results in
916 // some loss of resolution, deemed acceptable. 916 // some loss of resolution, deemed acceptable.
917 // 917 //
918 // It's possible to apply the gain in the AGC (with a target level of 0 dbFS 918 // It's possible to apply the gain in the AGC (with a target level of 0 dbFS
919 // and compression gain of 6 dB). However, in the transition frame when this 919 // and compression gain of 6 dB). However, in the transition frame when this
920 // is enabled (moving from one to two participants) it has the potential to 920 // is enabled (moving from one to two participants) it has the potential to
921 // create discontinuities in the mixed frame. 921 // create discontinuities in the mixed frame.
922 // 922 //
923 // Instead we double the frame (with addition since left-shifting a 923 // Instead we double the frame (with addition since left-shifting a
924 // negative value is undefined). 924 // negative value is undefined).
925 *mixedAudio += *mixedAudio; 925 AudioFrameOperations::Add(*mixedAudio, mixedAudio);
926 926
927 if(error != _limiter->kNoError) { 927 if(error != _limiter->kNoError) {
928 WEBRTC_TRACE(kTraceError, kTraceAudioMixerServer, _id, 928 WEBRTC_TRACE(kTraceError, kTraceAudioMixerServer, _id,
929 "Error from AudioProcessing: %d", error); 929 "Error from AudioProcessing: %d", error);
930 assert(false); 930 assert(false);
931 return false; 931 return false;
932 } 932 }
933 return true; 933 return true;
934 } 934 }
935 } // namespace webrtc 935 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_conference_mixer/DEPS ('k') | webrtc/modules/audio_mixer/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698