diff options
author | henrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-28 12:40:02 +0000 |
---|---|---|
committer | henrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-28 12:40:02 +0000 |
commit | dd414bf1a20b69891729b94b3d76ac714d475a81 (patch) | |
tree | 1d706835f6628100e23b86b4c9c0677a4bd46b74 /content/browser/renderer_host/media/audio_input_renderer_host.cc | |
parent | fb82b78d9beeee9dfb947ddf86b34ef038bdd013 (diff) | |
download | chromium_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 'content/browser/renderer_host/media/audio_input_renderer_host.cc')
-rw-r--r-- | content/browser/renderer_host/media/audio_input_renderer_host.cc | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/content/browser/renderer_host/media/audio_input_renderer_host.cc b/content/browser/renderer_host/media/audio_input_renderer_host.cc index 85d269f..121a5ac 100644 --- a/content/browser/renderer_host/media/audio_input_renderer_host.cc +++ b/content/browser/renderer_host/media/audio_input_renderer_host.cc @@ -174,7 +174,6 @@ bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER(AudioInputHostMsg_CreateStream, OnCreateStream) IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream) IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream) - IPC_MESSAGE_HANDLER(AudioInputHostMsg_GetVolume, OnGetVolume) IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() @@ -200,7 +199,8 @@ void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) { void AudioInputRendererHost::OnCreateStream(int stream_id, const AudioParameters& params, - const std::string& device_id) { + const std::string& device_id, + bool automatic_gain_control) { VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id=" << stream_id << ")"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); @@ -214,9 +214,11 @@ void AudioInputRendererHost::OnCreateStream(int stream_id, // Create a new AudioEntry structure. scoped_ptr<AudioEntry> entry(new AudioEntry()); + uint32 mem_size = sizeof(AudioInputBufferParameters) + buffer_size; + // Create the shared memory and share it with the renderer process // using a new SyncWriter object. - if (!entry->shared_memory.CreateAndMapAnonymous(buffer_size)) { + if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { // If creation of shared memory failed then send an error message. SendErrorMessage(stream_id); return; @@ -248,6 +250,9 @@ void AudioInputRendererHost::OnCreateStream(int stream_id, return; } + // Set the initial AGC state for the audio input stream. + entry->controller->SetAutomaticGainControl(automatic_gain_control); + // If we have created the controller successfully create a entry and add it // to the map. entry->stream_id = stream_id; @@ -290,21 +295,7 @@ void AudioInputRendererHost::OnSetVolume(int stream_id, double volume) { return; } - // TODO(henrika): TBI. - NOTIMPLEMENTED(); -} - -void AudioInputRendererHost::OnGetVolume(int stream_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - AudioEntry* entry = LookupById(stream_id); - if (!entry) { - SendErrorMessage(stream_id); - return; - } - - // TODO(henrika): TBI. - NOTIMPLEMENTED(); + entry->controller->SetVolume(volume); } void AudioInputRendererHost::SendErrorMessage(int stream_id) { |