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

Unified Diff: remoting/host/audio_volume_filter.cc

Issue 2840773004: [Chromoting] Add AudioVolumeApplier to reduce the complexity and the dependency of kChannels (Closed)
Patch Set: Resolve review comments Created 3 years, 8 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: remoting/host/audio_volume_filter.cc
diff --git a/remoting/host/audio_volume_filter.cc b/remoting/host/audio_volume_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ab433ba1534b437ca10428dabe1352885c9235e6
--- /dev/null
+++ b/remoting/host/audio_volume_filter.cc
@@ -0,0 +1,44 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/audio_volume_filter.h"
+
+namespace remoting {
+
+AudioVolumeFilter::AudioVolumeFilter(int silence_threshold)
+ : silence_detector_(silence_threshold) {}
+AudioVolumeFilter::~AudioVolumeFilter() = default;
+
+bool AudioVolumeFilter::Apply(int16_t* data, size_t frames) {
+ if (frames == 0) {
Sergey Ulanov 2017/05/23 00:02:14 I think this can be replaced with a DCHECK. IAudio
Hzj_jie 2017/05/23 02:54:27 But if it's used on other platforms, assuming it's
+ return false;
+ }
+
+ if (silence_detector_.IsSilence(data, frames)) {
+ return false;
+ }
+
+ float level = GetAudioLevel();
+ if (level == 0) {
+ return false;
+ }
+
+ if (level == 1) {
+ return true;
+ }
+
+ const int sample_count = frames * silence_detector_.channels();
+ const int32_t level_int = static_cast<int32_t>(level * 65536);
+ for (int i = 0; i < sample_count; i++) {
+ data[i] = (static_cast<int32_t>(data[i]) * level_int) >> 16;
+ }
+
+ return true;
+}
+
+void AudioVolumeFilter::Initialize(int sampling_rate, int channels) {
+ silence_detector_.Reset(sampling_rate, channels);
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698