summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_input_stream_impl.h
diff options
context:
space:
mode:
authorhenrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-28 12:40:02 +0000
committerhenrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-28 12:40:02 +0000
commitdd414bf1a20b69891729b94b3d76ac714d475a81 (patch)
tree1d706835f6628100e23b86b4c9c0677a4bd46b74 /media/audio/audio_input_stream_impl.h
parentfb82b78d9beeee9dfb947ddf86b34ef038bdd013 (diff)
downloadchromium_src-dd414bf1a20b69891729b94b3d76ac714d475a81.zip
chromium_src-dd414bf1a20b69891729b94b3d76ac714d475a81.tar.gz
chromium_src-dd414bf1a20b69891729b94b3d76ac714d475a81.tar.bz2
Adds Analog Gain Control (AGC) to the WebRTC client.
The AGC functionality is as follows. It aims at maintaining the same speech loudness level from the microphone. This is done by both controlling the analog microphone gain and applying a digital gain. The microphone gain on the sound card is slowly increased/decreased during speech only. By observing the microphone control slider you can see it move when you speak. If you scream, the slider moves downwards and then upwards again when you return to normal. It is not uncommon that the slider hits the maximum. This means that the maximum analog gain is not large enough to give the desired loudness. Nevertheless, we can in general still attain the desired loudness. If the microphone control slider is moved manually, the analog adaptation restarts and returns to roughly the same position as before the change if the circumstances are still the same. When the input microphone signal causes saturation, the level is decreased dramatically and has to re-adapt towards the old level. The adaptation is a slowly varying process and at the beginning of a call this is noticed by a slow increase in volume. Smaller changes in microphone input level is leveled out by the built-in digital control. For larger differences we need to rely on the slow adaptation. BUG=115265 TEST=content_unittests Review URL: https://chromiumcodereview.appspot.com/9702019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_input_stream_impl.h')
-rw-r--r--media/audio/audio_input_stream_impl.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/media/audio/audio_input_stream_impl.h b/media/audio/audio_input_stream_impl.h
new file mode 100644
index 0000000..d223985
--- /dev/null
+++ b/media/audio/audio_input_stream_impl.h
@@ -0,0 +1,67 @@
+// 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.
+
+#ifndef MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_
+#define MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_
+
+#include "base/compiler_specific.h"
+#include "base/synchronization/lock.h"
+#include "base/time.h"
+#include "media/audio/audio_io.h"
+
+// AudioInputStreamImpl implements platform-independent parts of the
+// AudioInputStream interface. Each platform dependent implementation
+// should derive from this class.
+// TODO(henrika): we can probably break out more parts from our current
+// AudioInputStream implementation and move out to this class.
+class MEDIA_EXPORT AudioInputStreamImpl : public AudioInputStream {
+ public:
+ AudioInputStreamImpl();
+ virtual ~AudioInputStreamImpl();
+
+ // Sets the automatic gain control (AGC) to on or off. When AGC is enabled,
+ // the microphone volume is queried periodically and the volume level is
+ // provided in each AudioInputCallback::OnData() callback and fed to the
+ // render-side AGC.
+ virtual void SetAutomaticGainControl(bool enabled) OVERRIDE;
+
+ // Gets the current automatic gain control state.
+ virtual bool GetAutomaticGainControl() OVERRIDE;
+
+ protected:
+ // Stores a new volume level by asking the audio hardware.
+ // This method only has an effect if AGC is enabled.
+ void UpdateAgcVolume();
+
+ // Gets the latest stored volume level if AGC is enabled and if
+ // more than one second has passed since the volume was updated the last time.
+ void QueryAgcVolume(double* normalized_volume);
+
+ private:
+ // Takes a volume sample and stores it in |normalized_volume_|.
+ void GetNormalizedVolume();
+
+ // True when automatic gain control is enabled, false otherwise.
+ // Guarded by |lock_|.
+ bool agc_is_enabled_;
+
+ // Stores the maximum volume which is used for normalization to a volume
+ // range of [0.0, 1.0].
+ double max_volume_;
+
+ // Contains last result of internal call to GetVolume(). We save resources
+ // but not querying the capture volume for each callback. Guarded by |lock_|.
+ // The range is normalized to [0.0, 1.0].
+ double normalized_volume_;
+
+ // Protects |agc_is_enabled_| and |volume_| .
+ base::Lock lock_;
+
+ // Keeps track of the last time the microphone volume level was queried.
+ base::Time last_volume_update_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioInputStreamImpl);
+};
+
+#endif // MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_