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

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: Sync latest changes Created 3 years, 7 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
« no previous file with comments | « remoting/host/audio_volume_filter.h ('k') | remoting/host/audio_volume_filter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
+ 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
« no previous file with comments | « remoting/host/audio_volume_filter.h ('k') | remoting/host/audio_volume_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698