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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/host/audio_volume_filter.h"
6
7 namespace remoting {
8
9 AudioVolumeFilter::AudioVolumeFilter(int silence_threshold)
10 : silence_detector_(silence_threshold) {}
11 AudioVolumeFilter::~AudioVolumeFilter() = default;
12
13 bool AudioVolumeFilter::Apply(int16_t* data, size_t frames) {
14 if (frames == 0) {
15 return false;
16 }
17
18 if (silence_detector_.IsSilence(data, frames)) {
19 return false;
20 }
21
22 float level = GetAudioLevel();
23 if (level == 0) {
24 return false;
25 }
26
27 if (level == 1) {
28 return true;
29 }
30
31 const int sample_count = frames * silence_detector_.channels();
32 const int32_t level_int = static_cast<int32_t>(level * 65536);
33 for (int i = 0; i < sample_count; i++) {
34 data[i] = (static_cast<int32_t>(data[i]) * level_int) >> 16;
35 }
36
37 return true;
38 }
39
40 void AudioVolumeFilter::Initialize(int sampling_rate, int channels) {
41 silence_detector_.Reset(sampling_rate, channels);
42 }
43
44 } // namespace remoting
OLDNEW
« 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