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

Unified Diff: webrtc/modules/audio_mixer/frame_combiner_test_tools.cc

Issue 2776113002: Send data from mixer to APM limiter more often. (Closed)
Patch Set: Test 1 not needed. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_mixer/frame_combiner_test_tools.cc
diff --git a/webrtc/modules/audio_mixer/frame_combiner_test_tools.cc b/webrtc/modules/audio_mixer/frame_combiner_test_tools.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3fd5510316239ff7f5d5c091c49ace32d1d9e6ab
--- /dev/null
+++ b/webrtc/modules/audio_mixer/frame_combiner_test_tools.cc
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2017 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 <cmath>
+#include <numeric>
+#include <vector>
+
+#include "webrtc/base/logging.h"
+#include "webrtc/base/safe_conversions.h"
+#include "webrtc/modules/audio_mixer/frame_combiner_test_tools.h"
+
+namespace webrtc {
+
+namespace {
+constexpr float kPi = 3.14159265;
+constexpr int16_t kReliabilityThreshold = 100;
+}
+
+void SineWaveGenerator::GenerateNextFrame(AudioFrame* frame) {
ivoc 2017/03/28 16:11:06 Please add DCHECK(frame)
+ for (size_t i = 0; i < frame->samples_per_channel_; ++i) {
+ for (size_t ch = 0; ch < frame->num_channels_; ++ch) {
+ frame->data_[frame->num_channels_ * i + ch] =
+ rtc::saturated_cast<int16_t>(amplitude_ * sin(phase_));
ivoc 2017/03/28 16:11:06 sinf, sin is for doubles.
aleloi 2017/03/28 17:10:13 Done.
+ }
+ phase_ += wave_frequency_hz_ * 2 * kPi / frame->sample_rate_hz_;
+ }
+}
+
+float GainChangeCalculator::CalculateGainChange(
+ rtc::ArrayView<const int16_t> in,
+ rtc::ArrayView<const int16_t> out) {
+ RTC_DCHECK_EQ(in.size(), out.size());
+
+ std::vector<float> gain(in.size());
+ auto gain_view = rtc::ArrayView<float>(gain.data(), gain.size());
+ CalculateGain(in, out, gain_view);
+ return CalculateDifferences(gain_view);
+}
+
+void GainChangeCalculator::CalculateGain(rtc::ArrayView<const int16_t> in,
+ rtc::ArrayView<const int16_t> out,
+ rtc::ArrayView<float> gain) {
+ RTC_DCHECK_EQ(in.size(), out.size());
+ RTC_DCHECK_EQ(in.size(), gain.size());
+
+ for (size_t i = 0; i < in.size(); ++i) {
+ if (std::abs(in[i]) >= kReliabilityThreshold) {
ivoc 2017/03/28 16:11:06 Won't this cause some discontinuities in the calcu
aleloi 2017/03/28 17:10:13 If the threshold increases, the resulted sum of di
+ last_reliable_gain_ = out[i] / static_cast<float>(in[i]);
+ }
+ gain[i] = last_reliable_gain_;
+ }
+}
+
+float GainChangeCalculator::CalculateDifferences(
+ rtc::ArrayView<const float> values) {
+ float res = 0;
+ for (float f : values) {
+ res += std::abs(f - last_value_);
ivoc 2017/03/28 16:11:06 fabs, abs is for ints.
aleloi 2017/03/28 17:10:13 I checked that this returns floats. fabs seems mor
+ last_value_ = f;
+ }
+ return res;
+}
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698