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

Unified Diff: media/audio/audio_input_stream_impl.cc

Issue 15563004: Improved AGC update scheme for the audio backend in Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added Start/Stop APIs for the AGC part Created 7 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 | « media/audio/audio_input_stream_impl.h ('k') | media/audio/cras/cras_input.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_input_stream_impl.cc
diff --git a/media/audio/audio_input_stream_impl.cc b/media/audio/audio_input_stream_impl.cc
deleted file mode 100644
index f68317ce417b28c2770503e9b719d6962078cba1..0000000000000000000000000000000000000000
--- a/media/audio/audio_input_stream_impl.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2012 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 "base/logging.h"
-#include "media/audio/audio_input_stream_impl.h"
-
-namespace media {
-
-static const int kMinIntervalBetweenVolumeUpdatesMs = 1000;
-
-AudioInputStreamImpl::AudioInputStreamImpl()
- : agc_is_enabled_(false),
- max_volume_(0.0),
- normalized_volume_(0.0) {
-}
-
-AudioInputStreamImpl::~AudioInputStreamImpl() {}
-
-void AudioInputStreamImpl::SetAutomaticGainControl(bool enabled) {
- agc_is_enabled_ = enabled;
-}
-
-bool AudioInputStreamImpl::GetAutomaticGainControl() {
- return agc_is_enabled_;
-}
-
-void AudioInputStreamImpl::UpdateAgcVolume() {
- base::AutoLock lock(lock_);
-
- // We take new volume samples once every second when the AGC is enabled.
- // To ensure that a new setting has an immediate effect, the new volume
- // setting is cached here. It will ensure that the next OnData() callback
- // will contain a new valid volume level. If this approach was not taken,
- // we could report invalid volume levels to the client for a time period
- // of up to one second.
- if (agc_is_enabled_) {
- GetNormalizedVolume();
- }
-}
-
-void AudioInputStreamImpl::QueryAgcVolume(double* normalized_volume) {
- base::AutoLock lock(lock_);
-
- // Only modify the |volume| output reference if AGC is enabled and if
- // more than one second has passed since the volume was updated the last time.
- if (agc_is_enabled_) {
- base::Time now = base::Time::Now();
- if ((now - last_volume_update_time_).InMilliseconds() >
- kMinIntervalBetweenVolumeUpdatesMs) {
- GetNormalizedVolume();
- last_volume_update_time_ = now;
- }
- *normalized_volume = normalized_volume_;
- }
-}
-
-void AudioInputStreamImpl::GetNormalizedVolume() {
- if (max_volume_ == 0.0) {
- // Cach the maximum volume if this is the first time we ask for it.
- max_volume_ = GetMaxVolume();
- }
-
- if (max_volume_ != 0.0) {
- // Retrieve the current volume level by asking the audio hardware.
- // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux.
- normalized_volume_ = GetVolume() / max_volume_;
- }
-}
-
-} // namespace media
« no previous file with comments | « media/audio/audio_input_stream_impl.h ('k') | media/audio/cras/cras_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698