Files
platform-external-webrtc/webrtc/modules/audio_processing/agc/agc_manager_direct.h
Bjorn Volcker adc46c4cf7 audio_processing/agc: Adds config to set minimum microphone volume at startup
The AGC is currently bumping up the mic volume to 33% at startup if it is below that level. This is to avoid getting stuck in a poor state from which the AGC can not move, simply a too low input audio level. For some users, 33% is instead too loud.

This CL gives the user the possibility to set that level at create time.
- Extends the Config ExperimentalAgc with a startup_mic_volume for the user to set if desired. Note that the bump up does not apply to the legacy AGC and the "regular" AGC is controlled by ExperimentalAgc.
- Without any actions, the same default value as previously is used.
- In addition I removed a return value from InitializeExperimentalAgc() and InitializeTransient()

This has been tested by building Chromium on Mac and verify through apprtc that
1) startup_mic_volume = 128 bumps up to 50%.
2) startup_mic_volume = 500 (out of range) bumps up to 100%.
3) startup_mic_volume = 0 bumps up to 4%, the AGC min level.

BUG=4529
TESTED=locally
R=andrew@webrtc.org, kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/43109004

Cr-Commit-Position: refs/heads/master@{#9004}
2015-04-15 09:42:35 +00:00

105 lines
3.4 KiB
C++

/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_MANAGER_DIRECT_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_MANAGER_DIRECT_H_
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_processing/agc/agc.h"
namespace webrtc {
class AudioFrame;
class DebugFile;
class GainControl;
// Callbacks that need to be injected into AgcManagerDirect to read and control
// the volume values. They have different behavior if they are called from
// AgcManager or AudioProcessing. This is done to remove the VoiceEngine
// dependency in AgcManagerDirect.
class VolumeCallbacks {
public:
virtual ~VolumeCallbacks() {}
virtual void SetMicVolume(int volume) = 0;
virtual int GetMicVolume() = 0;
};
// Direct interface to use AGC to set volume and compression values.
// AudioProcessing uses this interface directly to integrate the callback-less
// AGC. AgcManager delegates most of its calls here. See agc_manager.h for
// undocumented methods.
//
// This class is not thread-safe.
class AgcManagerDirect {
public:
// AgcManagerDirect will configure GainControl internally. The user is
// responsible for processing the audio using it after the call to Process.
// The operating range of startup_min_level is [12, 255] and any input value
// outside that range will be clamped.
AgcManagerDirect(GainControl* gctrl,
VolumeCallbacks* volume_callbacks,
int startup_min_level);
// Dependency injection for testing. Don't delete |agc| as the memory is owned
// by the manager.
AgcManagerDirect(Agc* agc,
GainControl* gctrl,
VolumeCallbacks* volume_callbacks,
int startup_min_level);
~AgcManagerDirect();
int Initialize();
void AnalyzePreProcess(int16_t* audio,
int num_channels,
int samples_per_channel);
void Process(const int16_t* audio, int length, int sample_rate_hz);
// Sets a new microphone level, after first checking that it hasn't been
// updated by the user, in which case no action is taken.
void SetLevel(int new_level);
// Set the maximum level the AGC is allowed to apply. Also updates the
// maximum compression gain to compensate. The level must be at least
// |kClippedLevelMin|.
void SetMaxLevel(int level);
void SetCaptureMuted(bool muted);
bool capture_muted() { return capture_muted_; }
float voice_probability();
private:
int CheckVolumeAndReset();
void UpdateGain();
void UpdateCompressor();
rtc::scoped_ptr<Agc> agc_;
GainControl* gctrl_;
VolumeCallbacks* volume_callbacks_;
int frames_since_clipped_;
int level_;
int max_level_;
int max_compression_gain_;
int target_compression_;
int compression_;
float compression_accumulator_;
bool capture_muted_;
bool check_volume_on_next_process_;
bool startup_;
int startup_min_level_;
rtc::scoped_ptr<DebugFile> file_preproc_;
rtc::scoped_ptr<DebugFile> file_postproc_;
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_MANAGER_DIRECT_H_