2014-12-15 09:41:24 +00:00
|
|
|
/*
|
|
|
|
|
* 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_
|
|
|
|
|
|
2016-02-19 07:04:49 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
#include "webrtc/base/constructormagic.h"
|
2014-12-15 09:41:24 +00:00
|
|
|
#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
|
2015-09-29 15:43:42 -07:00
|
|
|
// the volume values. This is done to remove the VoiceEngine dependency in
|
|
|
|
|
// AgcManagerDirect.
|
|
|
|
|
// TODO(aluebs): Remove VolumeCallbacks.
|
2014-12-15 09:41:24 +00:00
|
|
|
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
|
2015-09-29 15:43:42 -07:00
|
|
|
// AGC.
|
2014-12-15 09:41:24 +00:00
|
|
|
//
|
|
|
|
|
// This class is not thread-safe.
|
2015-09-29 15:43:42 -07:00
|
|
|
class AgcManagerDirect final {
|
2014-12-15 09:41:24 +00:00
|
|
|
public:
|
|
|
|
|
// AgcManagerDirect will configure GainControl internally. The user is
|
|
|
|
|
// responsible for processing the audio using it after the call to Process.
|
2015-04-15 11:42:40 +02:00
|
|
|
// 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);
|
2014-12-15 09:41:24 +00:00
|
|
|
// Dependency injection for testing. Don't delete |agc| as the memory is owned
|
|
|
|
|
// by the manager.
|
|
|
|
|
AgcManagerDirect(Agc* agc,
|
|
|
|
|
GainControl* gctrl,
|
2015-04-15 11:42:40 +02:00
|
|
|
VolumeCallbacks* volume_callbacks,
|
|
|
|
|
int startup_min_level);
|
2014-12-15 09:41:24 +00:00
|
|
|
~AgcManagerDirect();
|
|
|
|
|
|
|
|
|
|
int Initialize();
|
|
|
|
|
void AnalyzePreProcess(int16_t* audio,
|
|
|
|
|
int num_channels,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t samples_per_channel);
|
|
|
|
|
void Process(const int16_t* audio, size_t length, int sample_rate_hz);
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2015-09-29 15:43:42 -07:00
|
|
|
// Call when the capture stream has been muted/unmuted. This causes the
|
|
|
|
|
// manager to disregard all incoming audio; chances are good it's background
|
|
|
|
|
// noise to which we'd like to avoid adapting.
|
|
|
|
|
void SetCaptureMuted(bool muted);
|
|
|
|
|
bool capture_muted() { return capture_muted_; }
|
|
|
|
|
|
|
|
|
|
float voice_probability();
|
|
|
|
|
|
|
|
|
|
private:
|
2014-12-15 09:41:24 +00:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
int CheckVolumeAndReset();
|
|
|
|
|
void UpdateGain();
|
|
|
|
|
void UpdateCompressor();
|
|
|
|
|
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<Agc> agc_;
|
2014-12-15 09:41:24 +00:00
|
|
|
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_;
|
2015-04-15 11:42:40 +02:00
|
|
|
int startup_min_level_;
|
2014-12-15 09:41:24 +00:00
|
|
|
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<DebugFile> file_preproc_;
|
|
|
|
|
std::unique_ptr<DebugFile> file_postproc_;
|
2015-09-29 15:43:42 -07:00
|
|
|
|
|
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(AgcManagerDirect);
|
2014-12-15 09:41:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_AGC_MANAGER_DIRECT_H_
|