2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-25 19:21:13 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_AUDIO_PROCESSING_AGC_LEGACY_GAIN_CONTROL_H_
|
|
|
|
|
#define MODULES_AUDIO_PROCESSING_AGC_LEGACY_GAIN_CONTROL_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2020-03-20 15:50:14 +01:00
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-05-20 08:42:22 -07:00
|
|
|
enum {
|
|
|
|
|
kAgcModeUnchanged,
|
|
|
|
|
kAgcModeAdaptiveAnalog,
|
|
|
|
|
kAgcModeAdaptiveDigital,
|
|
|
|
|
kAgcModeFixedDigital
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2016-05-20 08:42:22 -07:00
|
|
|
enum { kAgcFalse = 0, kAgcTrue };
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-05-20 08:42:22 -07:00
|
|
|
typedef struct {
|
|
|
|
|
int16_t targetLevelDbfs; // default 3 (-3 dBOv)
|
|
|
|
|
int16_t compressionGaindB; // default 9 dB
|
|
|
|
|
uint8_t limiterEnable; // default kAgcTrue (on)
|
2014-12-18 09:11:33 +00:00
|
|
|
} WebRtcAgcConfig;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-16 23:52:25 -08:00
|
|
|
/*
|
|
|
|
|
* This function analyses the number of samples passed to
|
|
|
|
|
* farend and produces any error code that could arise.
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance.
|
|
|
|
|
* - samples : Number of samples in input vector.
|
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* : 0 - Normal operation.
|
|
|
|
|
* : -1 - Error.
|
|
|
|
|
*/
|
|
|
|
|
int WebRtcAgc_GetAddFarendError(void* state, size_t samples);
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2014-12-15 21:54:50 +00:00
|
|
|
* This function processes a 10 ms frame of far-end speech to determine
|
|
|
|
|
* if there is active speech. The length of the input speech vector must be
|
2014-12-16 20:56:09 +00:00
|
|
|
* given in samples (80 when FS=8000, and 160 when FS=16000, FS=32000 or
|
|
|
|
|
* FS=48000).
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance.
|
2014-12-15 21:54:50 +00:00
|
|
|
* - inFar : Far-end input speech vector
|
2011-07-07 08:21:25 +00:00
|
|
|
* - samples : Number of samples in input vector
|
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* : 0 - Normal operation.
|
|
|
|
|
* : -1 - Error
|
|
|
|
|
*/
|
2016-05-20 08:42:22 -07:00
|
|
|
int WebRtcAgc_AddFarend(void* agcInst, const int16_t* inFar, size_t samples);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
2014-12-15 21:54:50 +00:00
|
|
|
* This function processes a 10 ms frame of microphone speech to determine
|
|
|
|
|
* if there is active speech. The length of the input speech vector must be
|
2014-12-16 20:56:09 +00:00
|
|
|
* given in samples (80 when FS=8000, and 160 when FS=16000, FS=32000 or
|
|
|
|
|
* FS=48000). For very low input levels, the input signal is increased in level
|
|
|
|
|
* by multiplying and overwriting the samples in inMic[].
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* This function should be called before any further processing of the
|
|
|
|
|
* near-end microphone signal.
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance.
|
2014-12-16 20:56:09 +00:00
|
|
|
* - inMic : Microphone input speech vector for each band
|
|
|
|
|
* - num_bands : Number of bands in input vector
|
2011-07-07 08:21:25 +00:00
|
|
|
* - samples : Number of samples in input vector
|
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* : 0 - Normal operation.
|
|
|
|
|
* : -1 - Error
|
|
|
|
|
*/
|
|
|
|
|
int WebRtcAgc_AddMic(void* agcInst,
|
2014-12-16 20:56:09 +00:00
|
|
|
int16_t* const* inMic,
|
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 num_bands,
|
|
|
|
|
size_t samples);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function replaces the analog microphone with a virtual one.
|
|
|
|
|
* It is a digital gain applied to the input signal and is used in the
|
2014-12-15 21:54:50 +00:00
|
|
|
* agcAdaptiveDigital mode where no microphone level is adjustable. The length
|
|
|
|
|
* of the input speech vector must be given in samples (80 when FS=8000, and 160
|
2014-12-16 20:56:09 +00:00
|
|
|
* when FS=16000, FS=32000 or FS=48000).
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance.
|
2014-12-16 20:56:09 +00:00
|
|
|
* - inMic : Microphone input speech vector for each band
|
|
|
|
|
* - num_bands : Number of bands in input vector
|
2011-07-07 08:21:25 +00:00
|
|
|
* - samples : Number of samples in input vector
|
|
|
|
|
* - micLevelIn : Input level of microphone (static)
|
|
|
|
|
*
|
|
|
|
|
* Output:
|
|
|
|
|
* - inMic : Microphone output after processing (L band)
|
|
|
|
|
* - inMic_H : Microphone output after processing (H band)
|
|
|
|
|
* - micLevelOut : Adjusted microphone level after processing
|
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* : 0 - Normal operation.
|
|
|
|
|
* : -1 - Error
|
|
|
|
|
*/
|
|
|
|
|
int WebRtcAgc_VirtualMic(void* agcInst,
|
2014-12-16 20:56:09 +00:00
|
|
|
int16_t* const* inMic,
|
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 num_bands,
|
|
|
|
|
size_t samples,
|
2013-04-10 07:50:54 +00:00
|
|
|
int32_t micLevelIn,
|
|
|
|
|
int32_t* micLevelOut);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
2019-11-23 00:14:31 +01:00
|
|
|
* This function analyses a 10 ms frame and produces the analog and digital
|
|
|
|
|
* gains required to normalize the signal. The gain adjustments are done only
|
|
|
|
|
* during active periods of speech. The length of the speech vectors must be
|
|
|
|
|
* given in samples (80 when FS=8000, and 160 when FS=16000, FS=32000 or
|
|
|
|
|
* FS=48000). The echo parameter can be used to ensure the AGC will not adjust
|
|
|
|
|
* upward in the presence of echo.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* This function should be called after processing the near-end microphone
|
|
|
|
|
* signal, in any case after any echo cancellation.
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance
|
2014-12-16 20:56:09 +00:00
|
|
|
* - inNear : Near-end input speech vector for each band
|
|
|
|
|
* - num_bands : Number of bands in input/output vector
|
2011-07-07 08:21:25 +00:00
|
|
|
* - samples : Number of samples in input/output vector
|
|
|
|
|
* - inMicLevel : Current microphone volume level
|
|
|
|
|
* - echo : Set to 0 if the signal passed to add_mic is
|
|
|
|
|
* almost certainly free of echo; otherwise set
|
|
|
|
|
* to 1. If you have no information regarding echo
|
|
|
|
|
* set to 0.
|
|
|
|
|
*
|
|
|
|
|
* Output:
|
|
|
|
|
* - outMicLevel : Adjusted microphone volume level
|
|
|
|
|
* - saturationWarning : A returned value of 1 indicates a saturation event
|
|
|
|
|
* has occurred and the volume cannot be further
|
|
|
|
|
* reduced. Otherwise will be set to 0.
|
2019-11-23 00:14:31 +01:00
|
|
|
* - gains : Vector of gains to apply for digital normalization
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* : 0 - Normal operation.
|
|
|
|
|
* : -1 - Error
|
|
|
|
|
*/
|
2019-11-23 00:14:31 +01:00
|
|
|
int WebRtcAgc_Analyze(void* agcInst,
|
2014-12-16 20:56:09 +00:00
|
|
|
const int16_t* const* inNear,
|
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 num_bands,
|
|
|
|
|
size_t samples,
|
2013-04-10 07:50:54 +00:00
|
|
|
int32_t inMicLevel,
|
|
|
|
|
int32_t* outMicLevel,
|
|
|
|
|
int16_t echo,
|
2019-11-23 00:14:31 +01:00
|
|
|
uint8_t* saturationWarning,
|
|
|
|
|
int32_t gains[11]);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function processes a 10 ms frame by applying precomputed digital gains.
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance
|
|
|
|
|
* - gains : Vector of gains to apply for digital normalization
|
|
|
|
|
* - in_near : Near-end input speech vector for each band
|
|
|
|
|
* - num_bands : Number of bands in input/output vector
|
|
|
|
|
*
|
|
|
|
|
* Output:
|
|
|
|
|
* - out : Gain-adjusted near-end speech vector
|
|
|
|
|
* : May be the same vector as the input.
|
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* : 0 - Normal operation.
|
|
|
|
|
* : -1 - Error
|
|
|
|
|
*/
|
|
|
|
|
int WebRtcAgc_Process(const void* agcInst,
|
|
|
|
|
const int32_t gains[11],
|
|
|
|
|
const int16_t* const* in_near,
|
|
|
|
|
size_t num_bands,
|
|
|
|
|
int16_t* const* out);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function sets the config parameters (targetLevelDbfs,
|
|
|
|
|
* compressionGaindB and limiterEnable).
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance
|
|
|
|
|
* - config : config struct
|
|
|
|
|
*
|
|
|
|
|
* Output:
|
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* : 0 - Normal operation.
|
|
|
|
|
* : -1 - Error
|
|
|
|
|
*/
|
2014-12-18 09:11:33 +00:00
|
|
|
int WebRtcAgc_set_config(void* agcInst, WebRtcAgcConfig config);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function returns the config parameters (targetLevelDbfs,
|
|
|
|
|
* compressionGaindB and limiterEnable).
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance
|
|
|
|
|
*
|
|
|
|
|
* Output:
|
|
|
|
|
* - config : config struct
|
|
|
|
|
*
|
|
|
|
|
* Return value:
|
|
|
|
|
* : 0 - Normal operation.
|
|
|
|
|
* : -1 - Error
|
|
|
|
|
*/
|
2014-12-18 09:11:33 +00:00
|
|
|
int WebRtcAgc_get_config(void* agcInst, WebRtcAgcConfig* config);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
2015-06-10 21:43:36 +02:00
|
|
|
* This function creates and returns an AGC instance, which will contain the
|
|
|
|
|
* state information for one (duplex) channel.
|
2011-07-07 08:21:25 +00:00
|
|
|
*/
|
2018-03-19 16:23:48 +01:00
|
|
|
void* WebRtcAgc_Create(void);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function frees the AGC instance created at the beginning.
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance.
|
|
|
|
|
*/
|
2015-04-10 07:56:57 +02:00
|
|
|
void WebRtcAgc_Free(void* agcInst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function initializes an AGC instance.
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - agcInst : AGC instance.
|
|
|
|
|
* - minLevel : Minimum possible mic level
|
|
|
|
|
* - maxLevel : Maximum possible mic level
|
|
|
|
|
* - agcMode : 0 - Unchanged
|
|
|
|
|
* : 1 - Adaptive Analog Automatic Gain Control -3dBOv
|
|
|
|
|
* : 2 - Adaptive Digital Automatic Gain Control -3dBOv
|
|
|
|
|
* : 3 - Fixed Digital Gain 0dB
|
|
|
|
|
* - fs : Sampling frequency
|
|
|
|
|
*
|
|
|
|
|
* Return value : 0 - Ok
|
|
|
|
|
* -1 - Error
|
|
|
|
|
*/
|
2016-05-20 08:42:22 -07:00
|
|
|
int WebRtcAgc_Init(void* agcInst,
|
2013-04-10 07:50:54 +00:00
|
|
|
int32_t minLevel,
|
|
|
|
|
int32_t maxLevel,
|
|
|
|
|
int16_t agcMode,
|
|
|
|
|
uint32_t fs);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2020-03-20 15:50:14 +01:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_PROCESSING_AGC_LEGACY_GAIN_CONTROL_H_
|