OLD | NEW |
(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 |
OLD | NEW |