Chromium Code Reviews| 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_applier.h" | |
| 6 | |
| 7 namespace remoting { | |
| 8 | |
| 9 AudioVolumeApplier::AudioVolumeApplier(int silence_threshold) | |
| 10 : silence_detector_before_(silence_threshold), | |
| 11 silence_detector_after_(silence_threshold) {} | |
|
Sergey Ulanov
2017/04/26 19:57:35
I don't think we need the post-processing silence
Hzj_jie
2017/04/28 03:53:34
Done.
| |
| 12 AudioVolumeApplier::~AudioVolumeApplier() = default; | |
| 13 | |
| 14 bool AudioVolumeApplier::Apply(int16_t* data, size_t frames) { | |
| 15 if (frames == 0) { | |
| 16 return false; | |
| 17 } | |
| 18 | |
| 19 bool result = ApplyVolumeLevel(data, frames); | |
| 20 return !silence_detector_after_.IsSilence(data, frames) && result; | |
| 21 } | |
| 22 | |
| 23 void AudioVolumeApplier::Initialize(int sampling_rate, int channels) { | |
| 24 silence_detector_before_.Reset(sampling_rate, channels); | |
| 25 silence_detector_after_.Reset(sampling_rate, channels); | |
| 26 } | |
| 27 | |
| 28 bool AudioVolumeApplier::ApplyVolumeLevel(int16_t* data, size_t frames) { | |
| 29 if (silence_detector_before_.IsSilence(data, frames)) { | |
| 30 return false; | |
| 31 } | |
| 32 | |
| 33 float level = GetAudioLevel(); | |
| 34 if (level == 0) { | |
| 35 return false; | |
| 36 } | |
| 37 | |
| 38 if (level == 1) { | |
| 39 return true; | |
| 40 } | |
| 41 | |
| 42 const int sample_count = frames * silence_detector_before_.channels(); | |
| 43 const int32_t level_int = static_cast<int32_t>(level * 65536); | |
| 44 for (int i = 0; i < sample_count; i++) { | |
| 45 data[i] = (static_cast<int32_t>(data[i]) * level_int) >> 16; | |
| 46 } | |
| 47 | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 } // namespace remoting | |
| OLD | NEW |