From 5bcc00e538203bb6714e6a6537b87ca1dfd7e8f3 Mon Sep 17 00:00:00 2001 From: aleloi Date: Mon, 15 Aug 2016 03:01:31 -0700 Subject: [PATCH] Changed folder structure in new mixer and fixed simple lint errors. The folder structure is now as was agreed on in the 'Slim and Modular WebRTC' effort. Also added some dependencies that were previously in another part of the tree. NOTRY=True Review-Url: https://codereview.webrtc.org/2238803002 Cr-Commit-Position: refs/heads/master@{#13742} --- webrtc/modules/audio_mixer/BUILD.gn | 14 +++-- .../audio_mixer/audio_frame_manipulator.cc | 62 +++++++++++++++++++ .../audio_mixer/audio_frame_manipulator.h | 28 +++++++++ webrtc/modules/audio_mixer/audio_mixer.gypi | 10 +-- webrtc/modules/audio_mixer/audio_mixer.h | 4 +- .../{include => }/audio_mixer_defines.h | 6 +- .../new_audio_conference_mixer.h | 8 +-- .../new_audio_conference_mixer_impl.cc | 12 ++-- .../new_audio_conference_mixer_impl.h | 8 +-- webrtc/modules/audio_mixer/source/OWNERS | 5 -- .../audio_mixer/test/audio_mixer_unittest.cc | 14 ++--- 11 files changed, 130 insertions(+), 41 deletions(-) create mode 100644 webrtc/modules/audio_mixer/audio_frame_manipulator.cc create mode 100644 webrtc/modules/audio_mixer/audio_frame_manipulator.h rename webrtc/modules/audio_mixer/{include => }/audio_mixer_defines.h (90%) rename webrtc/modules/audio_mixer/{include => }/new_audio_conference_mixer.h (89%) rename webrtc/modules/audio_mixer/{source => }/new_audio_conference_mixer_impl.cc (98%) rename webrtc/modules/audio_mixer/{source => }/new_audio_conference_mixer_impl.h (94%) delete mode 100644 webrtc/modules/audio_mixer/source/OWNERS diff --git a/webrtc/modules/audio_mixer/BUILD.gn b/webrtc/modules/audio_mixer/BUILD.gn index 471156ff36..7ef27908be 100644 --- a/webrtc/modules/audio_mixer/BUILD.gn +++ b/webrtc/modules/audio_mixer/BUILD.gn @@ -45,15 +45,17 @@ source_set("audio_mixer") { source_set("audio_conference_mixer") { sources = [ - "include/audio_mixer_defines.h", - "include/new_audio_conference_mixer.h", - "source/new_audio_conference_mixer_impl.cc", - "source/new_audio_conference_mixer_impl.h", + "audio_frame_manipulator.cc", + "audio_frame_manipulator.h", + "audio_mixer_defines.h", + "new_audio_conference_mixer.h", + "new_audio_conference_mixer_impl.cc", + "new_audio_conference_mixer_impl.h", ] public = [ - "include/audio_mixer_defines.h", - "include/new_audio_conference_mixer.h", + "audio_mixer_defines.h", + "new_audio_conference_mixer.h", ] configs += [ "../..:common_config" ] diff --git a/webrtc/modules/audio_mixer/audio_frame_manipulator.cc b/webrtc/modules/audio_mixer/audio_frame_manipulator.cc new file mode 100644 index 0000000000..aafeedaeda --- /dev/null +++ b/webrtc/modules/audio_mixer/audio_frame_manipulator.cc @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/modules/audio_mixer/audio_frame_manipulator.h" +#include "webrtc/modules/include/module_common_types.h" +#include "webrtc/typedefs.h" + +namespace webrtc { +namespace { +// Linear ramping over 80 samples. +// TODO(hellner): ramp using fix point? +const float kRampArray[] = { + 0.0000f, 0.0127f, 0.0253f, 0.0380f, 0.0506f, 0.0633f, 0.0759f, 0.0886f, + 0.1013f, 0.1139f, 0.1266f, 0.1392f, 0.1519f, 0.1646f, 0.1772f, 0.1899f, + 0.2025f, 0.2152f, 0.2278f, 0.2405f, 0.2532f, 0.2658f, 0.2785f, 0.2911f, + 0.3038f, 0.3165f, 0.3291f, 0.3418f, 0.3544f, 0.3671f, 0.3797f, 0.3924f, + 0.4051f, 0.4177f, 0.4304f, 0.4430f, 0.4557f, 0.4684f, 0.4810f, 0.4937f, + 0.5063f, 0.5190f, 0.5316f, 0.5443f, 0.5570f, 0.5696f, 0.5823f, 0.5949f, + 0.6076f, 0.6203f, 0.6329f, 0.6456f, 0.6582f, 0.6709f, 0.6835f, 0.6962f, + 0.7089f, 0.7215f, 0.7342f, 0.7468f, 0.7595f, 0.7722f, 0.7848f, 0.7975f, + 0.8101f, 0.8228f, 0.8354f, 0.8481f, 0.8608f, 0.8734f, 0.8861f, 0.8987f, + 0.9114f, 0.9241f, 0.9367f, 0.9494f, 0.9620f, 0.9747f, 0.9873f, 1.0000f}; +const size_t kRampSize = sizeof(kRampArray) / sizeof(kRampArray[0]); +} // namespace + +uint32_t NewMixerCalculateEnergy(const AudioFrame& audio_frame) { + uint32_t energy = 0; + for (size_t position = 0; position < audio_frame.samples_per_channel_; + position++) { + // TODO(andrew): this can easily overflow. + energy += audio_frame.data_[position] * audio_frame.data_[position]; + } + return energy; +} + +void NewMixerRampIn(AudioFrame* audio_frame) { + assert(kRampSize <= audio_frame->samples_per_channel_); + for (size_t i = 0; i < kRampSize; i++) { + audio_frame->data_[i] = + static_cast(kRampArray[i] * audio_frame->data_[i]); + } +} + +void NewMixerRampOut(AudioFrame* audio_frame) { + assert(kRampSize <= audio_frame->samples_per_channel_); + for (size_t i = 0; i < kRampSize; i++) { + const size_t kRampPos = kRampSize - 1 - i; + audio_frame->data_[i] = + static_cast(kRampArray[kRampPos] * audio_frame->data_[i]); + } + memset(&audio_frame->data_[kRampSize], 0, + (audio_frame->samples_per_channel_ - kRampSize) * + sizeof(audio_frame->data_[0])); +} +} // namespace webrtc diff --git a/webrtc/modules/audio_mixer/audio_frame_manipulator.h b/webrtc/modules/audio_mixer/audio_frame_manipulator.h new file mode 100644 index 0000000000..58103addeb --- /dev/null +++ b/webrtc/modules/audio_mixer/audio_frame_manipulator.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_MODULES_AUDIO_MIXER_AUDIO_FRAME_MANIPULATOR_H_ +#define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_FRAME_MANIPULATOR_H_ + +#include "webrtc/typedefs.h" + +namespace webrtc { +class AudioFrame; + +// Updates the audioFrame's energy (based on its samples). +uint32_t NewMixerCalculateEnergy(const AudioFrame& audio_frame); + +// Apply linear step function that ramps in/out the audio samples in audio_frame +void NewMixerRampIn(AudioFrame* audio_frame); +void NewMixerRampOut(AudioFrame* audio_frame); + +} // namespace webrtc + +#endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_FRAME_MANIPULATOR_H_ diff --git a/webrtc/modules/audio_mixer/audio_mixer.gypi b/webrtc/modules/audio_mixer/audio_mixer.gypi index 4253c20c39..5b2ebe639b 100644 --- a/webrtc/modules/audio_mixer/audio_mixer.gypi +++ b/webrtc/modules/audio_mixer/audio_mixer.gypi @@ -18,10 +18,12 @@ '<(webrtc_root)/base/base.gyp:rtc_base_approved', ], 'sources': [ - 'include/new_audio_conference_mixer.h', - 'include/audio_mixer_defines.h', - 'source/new_audio_conference_mixer_impl.cc', - 'source/new_audio_conference_mixer_impl.h', + 'audio_frame_manipulator.cc', + 'audio_frame_manipulator.h', + 'new_audio_conference_mixer.h', + 'audio_mixer_defines.h', + 'new_audio_conference_mixer_impl.cc', + 'new_audio_conference_mixer_impl.h', ], }, { diff --git a/webrtc/modules/audio_mixer/audio_mixer.h b/webrtc/modules/audio_mixer/audio_mixer.h index 9aabfcca5b..78cd4e5c79 100644 --- a/webrtc/modules/audio_mixer/audio_mixer.h +++ b/webrtc/modules/audio_mixer/audio_mixer.h @@ -14,8 +14,8 @@ #include "webrtc/base/criticalsection.h" #include "webrtc/common_audio/resampler/include/push_resampler.h" #include "webrtc/common_types.h" -#include "webrtc/modules/audio_mixer/include/new_audio_conference_mixer.h" -#include "webrtc/modules/audio_mixer/include/audio_mixer_defines.h" +#include "webrtc/modules/audio_mixer/new_audio_conference_mixer.h" +#include "webrtc/modules/audio_mixer/audio_mixer_defines.h" #include "webrtc/modules/utility/include/file_recorder.h" #include "webrtc/voice_engine/level_indicator.h" #include "webrtc/voice_engine/voice_engine_defines.h" diff --git a/webrtc/modules/audio_mixer/include/audio_mixer_defines.h b/webrtc/modules/audio_mixer/audio_mixer_defines.h similarity index 90% rename from webrtc/modules/audio_mixer/include/audio_mixer_defines.h rename to webrtc/modules/audio_mixer/audio_mixer_defines.h index 008f4d60f1..7f69a4347a 100644 --- a/webrtc/modules/audio_mixer/include/audio_mixer_defines.h +++ b/webrtc/modules/audio_mixer/audio_mixer_defines.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_MODULES_AUDIO_MIXER_INCLUDE_AUDIO_MIXER_DEFINES_H_ -#define WEBRTC_MODULES_AUDIO_MIXER_INCLUDE_AUDIO_MIXER_DEFINES_H_ +#ifndef WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_DEFINES_H_ +#define WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_DEFINES_H_ #include "webrtc/base/checks.h" #include "webrtc/modules/include/module_common_types.h" @@ -54,4 +54,4 @@ class MixerAudioSource { }; } // namespace webrtc -#endif // WEBRTC_MODULES_AUDIO_MIXER_INCLUDE_AUDIO_MIXER_DEFINES_H_ +#endif // WEBRTC_MODULES_AUDIO_MIXER_AUDIO_MIXER_DEFINES_H_ diff --git a/webrtc/modules/audio_mixer/include/new_audio_conference_mixer.h b/webrtc/modules/audio_mixer/new_audio_conference_mixer.h similarity index 89% rename from webrtc/modules/audio_mixer/include/new_audio_conference_mixer.h rename to webrtc/modules/audio_mixer/new_audio_conference_mixer.h index cbb44901e0..561cf88604 100644 --- a/webrtc/modules/audio_mixer/include/new_audio_conference_mixer.h +++ b/webrtc/modules/audio_mixer/new_audio_conference_mixer.h @@ -8,10 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_MODULES_AUDIO_MIXER_INCLUDE_NEW_AUDIO_CONFERENCE_MIXER_H_ -#define WEBRTC_MODULES_AUDIO_MIXER_INCLUDE_NEW_AUDIO_CONFERENCE_MIXER_H_ +#ifndef WEBRTC_MODULES_AUDIO_MIXER_NEW_AUDIO_CONFERENCE_MIXER_H_ +#define WEBRTC_MODULES_AUDIO_MIXER_NEW_AUDIO_CONFERENCE_MIXER_H_ -#include "webrtc/modules/audio_mixer/include/audio_mixer_defines.h" +#include "webrtc/modules/audio_mixer/audio_mixer_defines.h" #include "webrtc/modules/include/module.h" #include "webrtc/modules/include/module_common_types.h" @@ -64,4 +64,4 @@ class NewAudioConferenceMixer { }; } // namespace webrtc -#endif // WEBRTC_MODULES_AUDIO_MIXER_INCLUDE_NEW_AUDIO_CONFERENCE_MIXER_H_ +#endif // WEBRTC_MODULES_AUDIO_MIXER_NEW_AUDIO_CONFERENCE_MIXER_H_ diff --git a/webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.cc b/webrtc/modules/audio_mixer/new_audio_conference_mixer_impl.cc similarity index 98% rename from webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.cc rename to webrtc/modules/audio_mixer/new_audio_conference_mixer_impl.cc index dbb46ff0b1..5be76ec4d0 100644 --- a/webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.cc +++ b/webrtc/modules/audio_mixer/new_audio_conference_mixer_impl.cc @@ -8,13 +8,13 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.h" +#include "webrtc/modules/audio_mixer/new_audio_conference_mixer_impl.h" #include #include -#include "webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h" -#include "webrtc/modules/audio_mixer/include/audio_mixer_defines.h" +#include "webrtc/modules/audio_mixer/audio_frame_manipulator.h" +#include "webrtc/modules/audio_mixer/audio_mixer_defines.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/utility/include/audio_frame_operations.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" @@ -32,7 +32,7 @@ class SourceFrame { muted_(m), was_mixed_before_(was_mixed_before) { if (!muted_) { - energy_ = CalculateEnergy(*a); + energy_ = NewMixerCalculateEnergy(*a); } } @@ -410,7 +410,7 @@ AudioFrameList NewAudioConferenceMixerImpl::UpdateToMix( if (maxAudioFrameCounter > 0) { --maxAudioFrameCounter; if (!p.was_mixed_before_) { - RampIn(*p.audio_frame_); + NewMixerRampIn(p.audio_frame_); } result.emplace_back(p.audio_frame_, false); is_mixed = true; @@ -418,7 +418,7 @@ AudioFrameList NewAudioConferenceMixerImpl::UpdateToMix( // Ramp out unmuted. if (p.was_mixed_before_ && !is_mixed) { - RampOut(*p.audio_frame_); + NewMixerRampOut(p.audio_frame_); result.emplace_back(p.audio_frame_, false); } diff --git a/webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.h b/webrtc/modules/audio_mixer/new_audio_conference_mixer_impl.h similarity index 94% rename from webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.h rename to webrtc/modules/audio_mixer/new_audio_conference_mixer_impl.h index 3d41373b43..ef93e6ff91 100644 --- a/webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.h +++ b/webrtc/modules/audio_mixer/new_audio_conference_mixer_impl.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_MODULES_AUDIO_MIXER_SOURCE_NEW_AUDIO_CONFERENCE_MIXER_IMPL_H_ -#define WEBRTC_MODULES_AUDIO_MIXER_SOURCE_NEW_AUDIO_CONFERENCE_MIXER_IMPL_H_ +#ifndef WEBRTC_MODULES_AUDIO_MIXER_NEW_AUDIO_CONFERENCE_MIXER_IMPL_H_ +#define WEBRTC_MODULES_AUDIO_MIXER_NEW_AUDIO_CONFERENCE_MIXER_IMPL_H_ #include #include @@ -18,7 +18,7 @@ #include "webrtc/base/thread_checker.h" #include "webrtc/engine_configurations.h" -#include "webrtc/modules/audio_mixer/include/new_audio_conference_mixer.h" +#include "webrtc/modules/audio_mixer/new_audio_conference_mixer.h" #include "webrtc/modules/audio_conference_mixer/source/memory_pool.h" #include "webrtc/modules/include/module_common_types.h" @@ -154,4 +154,4 @@ class NewAudioConferenceMixerImpl : public NewAudioConferenceMixer { }; } // namespace webrtc -#endif // WEBRTC_MODULES_AUDIO_MIXER_SOURCE_NEW_AUDIO_CONFERENCE_MIXER_IMPL_H_ +#endif // WEBRTC_MODULES_AUDIO_MIXER_NEW_AUDIO_CONFERENCE_MIXER_IMPL_H_ diff --git a/webrtc/modules/audio_mixer/source/OWNERS b/webrtc/modules/audio_mixer/source/OWNERS deleted file mode 100644 index 3ee6b4bf5f..0000000000 --- a/webrtc/modules/audio_mixer/source/OWNERS +++ /dev/null @@ -1,5 +0,0 @@ - -# These are for the common case of adding or renaming files. If you're doing -# structural changes, please get a review from a reviewer in this file. -per-file *.gyp=* -per-file *.gypi=* diff --git a/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc b/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc index c228ec532e..38f2b2ebff 100644 --- a/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc +++ b/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc @@ -17,9 +17,9 @@ #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h" #include "webrtc/modules/audio_conference_mixer/source/audio_frame_manipulator.h" #include "webrtc/modules/audio_mixer/audio_mixer.h" -#include "webrtc/modules/audio_mixer/include/audio_mixer_defines.h" -#include "webrtc/modules/audio_mixer/include/new_audio_conference_mixer.h" -#include "webrtc/modules/audio_mixer/source/new_audio_conference_mixer_impl.h" +#include "webrtc/modules/audio_mixer/audio_mixer_defines.h" +#include "webrtc/modules/audio_mixer/new_audio_conference_mixer.h" +#include "webrtc/modules/audio_mixer/new_audio_conference_mixer_impl.h" using testing::_; using testing::Exactly; @@ -455,10 +455,10 @@ TEST_F(CompareWithOldMixerTest, ThreeParticipantsDifferentFrames) { TEST_F(CompareWithOldMixerTest, ManyParticipantsDifferentFrames) { Reset(); - constexpr int num_participants = 20; - AudioFrame audio_frames[num_participants]; + constexpr int kNumParticipants = 20; + AudioFrame audio_frames[kNumParticipants]; - for (int i = 0; i < num_participants; ++i) { + for (int i = 0; i < kNumParticipants; ++i) { ResetFrame(&audio_frames[i]); audio_frames[i].id_ = 1; audio_frames[i].data_[10] = 100 * (i % 5); @@ -468,7 +468,7 @@ TEST_F(CompareWithOldMixerTest, ManyParticipantsDifferentFrames) { } } - for (int i = 0; i < num_participants; ++i) { + for (int i = 0; i < kNumParticipants; ++i) { if (i % 2 == 0) { AddParticipant(&audio_frames[i], MixerParticipant::AudioFrameInfo::kMuted);