blob: 223c74b9bd4c87430cde772407e497191bceb159 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_
12#define MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "common_audio/signal_processing/include/signal_processing_library.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
Per Åhgren5b139d62020-03-20 15:50:14 +010016namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000017
minyuecac94aa2016-05-20 08:42:22 -070018typedef struct {
19 int32_t downState[8];
20 int16_t HPstate;
21 int16_t counter;
22 int16_t logRatio; // log( P(active) / P(inactive) ) (Q10)
23 int16_t meanLongTerm; // Q10
24 int32_t varianceLongTerm; // Q8
25 int16_t stdLongTerm; // Q10
26 int16_t meanShortTerm; // Q10
27 int32_t varianceShortTerm; // Q8
28 int16_t stdShortTerm; // Q10
29} AgcVad; // total = 54 bytes
niklase@google.com470e71d2011-07-07 08:21:25 +000030
minyuecac94aa2016-05-20 08:42:22 -070031typedef struct {
32 int32_t capacitorSlow;
33 int32_t capacitorFast;
34 int32_t gain;
35 int32_t gainTable[32];
36 int16_t gatePrevious;
37 int16_t agcMode;
38 AgcVad vadNearend;
39 AgcVad vadFarend;
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000040} DigitalAgc;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000042int32_t WebRtcAgc_InitDigital(DigitalAgc* digitalAgcInst, int16_t agcMode);
niklase@google.com470e71d2011-07-07 08:21:25 +000043
Per Åhgren77dc1992019-11-23 00:14:31 +010044int32_t WebRtcAgc_ComputeDigitalGains(DigitalAgc* digitalAgcInst,
45 const int16_t* const* inNear,
46 size_t num_bands,
47 uint32_t FS,
48 int16_t lowLevelSignal,
49 int32_t gains[11]);
50
51int32_t WebRtcAgc_ApplyDigitalGains(const int32_t gains[11],
52 size_t num_bands,
53 uint32_t FS,
54 const int16_t* const* in_near,
55 int16_t* const* out);
niklase@google.com470e71d2011-07-07 08:21:25 +000056
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000057int32_t WebRtcAgc_AddFarendToDigital(DigitalAgc* digitalAgcInst,
58 const int16_t* inFar,
Peter Kastingdce40cf2015-08-24 14:52:23 -070059 size_t nrSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000060
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000061void WebRtcAgc_InitVad(AgcVad* vadInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000062
minyuecac94aa2016-05-20 08:42:22 -070063int16_t WebRtcAgc_ProcessVad(AgcVad* vadInst, // (i) VAD state
64 const int16_t* in, // (i) Speech signal
Peter Kastingdce40cf2015-08-24 14:52:23 -070065 size_t nrSamples); // (i) number of samples
niklase@google.com470e71d2011-07-07 08:21:25 +000066
minyuecac94aa2016-05-20 08:42:22 -070067int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16
68 int16_t compressionGaindB, // Q0 (in dB)
69 int16_t targetLevelDbfs, // Q0 (in dB)
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000070 uint8_t limiterEnable,
71 int16_t analogTarget);
niklase@google.com470e71d2011-07-07 08:21:25 +000072
Per Åhgren5b139d62020-03-20 15:50:14 +010073} // namespace webrtc
74
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020075#endif // MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_