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

Side by Side Diff: media/audio/audio_input_stream_impl.cc

Issue 9702019: Adds Analog Gain Control (AGC) to the WebRTC client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved AGC comments Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "base/logging.h"
6 #include "media/audio/audio_input_stream_impl.h"
7
8 static const int kMinIntervalBetweenVolumeUpdatesMs = 1000;
9
10 AudioInputStreamImpl::AudioInputStreamImpl()
11 : agc_is_enabled_(false),
12 max_volume_(0.0),
13 normalized_volume_(0.0) {
14 }
15
16 AudioInputStreamImpl::~AudioInputStreamImpl() {
scherkus (not reviewing) 2012/03/26 22:41:04 nit: {}
henrika (OOO until Aug 14) 2012/03/27 09:20:38 Done.
17 }
18
19 void AudioInputStreamImpl::SetAutomaticGainControl(bool enabled) {
20 agc_is_enabled_ = enabled;
21 }
22
23 bool AudioInputStreamImpl::GetAutomaticGainControl() {
24 return agc_is_enabled_;
25 }
26
27 void AudioInputStreamImpl::UpdateAgcVolume() {
28 base::AutoLock lock(lock_);
29
30 // We take new volume samples once every second when the AGC is enabled.
31 // To ensure that a new setting has an immediate effect, the new volume
32 // setting is cached here. It will ensure that the next OnData() callback
33 // will contain a new valid volume level. If this approach was not taken,
34 // we could report invalid volume levels to the client for a time period
35 // of up to one second.
36 if (agc_is_enabled_) {
37 GetNormalizedVolume();
38 }
39 }
40
41 void AudioInputStreamImpl::QueryAgcVolume(double* normalized_volume) {
42 base::AutoLock lock(lock_);
43
44 // Only modify the |volume| output reference if AGC is enabled and if
45 // more than one second has passed since the volume was updated the last time.
46 if (agc_is_enabled_) {
47 base::Time now = base::Time::Now();
48 if ((now - last_volume_update_time_).InMilliseconds() >
49 kMinIntervalBetweenVolumeUpdatesMs) {
50 GetNormalizedVolume();
51 last_volume_update_time_ = now;
52 }
53 *normalized_volume = normalized_volume_;
54 }
55 }
56
57 void AudioInputStreamImpl::GetNormalizedVolume() {
58 if (max_volume_ == 0.0) {
59 // Cach the maximum volume if this is the first time we ask for it.
60 max_volume_ = GetMaxVolume();
61 }
62
63 if (max_volume_ != 0.0) {
64 // Retrieve the current volume level by asking the audio hardware.
65 // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux.
66 normalized_volume_ = GetVolume() / max_volume_;
67 }
68 }
69
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698