blob: f086294cf253dbc400237aee6ab4b5ec2d6e9a6d [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
bjornv@webrtc.orgea297872014-09-23 11:21:39 +000014#ifdef WEBRTC_AGC_DEBUG_DUMP
niklase@google.com470e71d2011-07-07 08:21:25 +000015#include <stdio.h>
16#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "common_audio/signal_processing/include/signal_processing_library.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19// the 32 most significant bits of A(19) * B(26) >> 13
minyuecac94aa2016-05-20 08:42:22 -070020#define AGC_MUL32(A, B) (((B) >> 13) * (A) + (((0x00001FFF & (B)) * (A)) >> 13))
niklase@google.com470e71d2011-07-07 08:21:25 +000021// C + the 32 most significant bits of A * B
minyuecac94aa2016-05-20 08:42:22 -070022#define AGC_SCALEDIFF32(A, B, C) \
23 ((C) + ((B) >> 16) * (A) + (((0x0000FFFF & (B)) * (A)) >> 16))
niklase@google.com470e71d2011-07-07 08:21:25 +000024
minyuecac94aa2016-05-20 08:42:22 -070025typedef struct {
26 int32_t downState[8];
27 int16_t HPstate;
28 int16_t counter;
29 int16_t logRatio; // log( P(active) / P(inactive) ) (Q10)
30 int16_t meanLongTerm; // Q10
31 int32_t varianceLongTerm; // Q8
32 int16_t stdLongTerm; // Q10
33 int16_t meanShortTerm; // Q10
34 int32_t varianceShortTerm; // Q8
35 int16_t stdShortTerm; // Q10
36} AgcVad; // total = 54 bytes
niklase@google.com470e71d2011-07-07 08:21:25 +000037
minyuecac94aa2016-05-20 08:42:22 -070038typedef struct {
39 int32_t capacitorSlow;
40 int32_t capacitorFast;
41 int32_t gain;
42 int32_t gainTable[32];
43 int16_t gatePrevious;
44 int16_t agcMode;
45 AgcVad vadNearend;
46 AgcVad vadFarend;
bjornv@webrtc.orgea297872014-09-23 11:21:39 +000047#ifdef WEBRTC_AGC_DEBUG_DUMP
minyuecac94aa2016-05-20 08:42:22 -070048 FILE* logFile;
49 int frameCounter;
niklase@google.com470e71d2011-07-07 08:21:25 +000050#endif
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000051} DigitalAgc;
niklase@google.com470e71d2011-07-07 08:21:25 +000052
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000053int32_t WebRtcAgc_InitDigital(DigitalAgc* digitalAgcInst, int16_t agcMode);
niklase@google.com470e71d2011-07-07 08:21:25 +000054
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000055int32_t WebRtcAgc_ProcessDigital(DigitalAgc* digitalAgcInst,
aluebs@webrtc.orgcf6d0b62014-12-16 20:56:09 +000056 const int16_t* const* inNear,
Peter Kastingdce40cf2015-08-24 14:52:23 -070057 size_t num_bands,
aluebs@webrtc.orgcf6d0b62014-12-16 20:56:09 +000058 int16_t* const* out,
59 uint32_t FS,
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000060 int16_t lowLevelSignal);
niklase@google.com470e71d2011-07-07 08:21:25 +000061
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000062int32_t WebRtcAgc_AddFarendToDigital(DigitalAgc* digitalAgcInst,
63 const int16_t* inFar,
Peter Kastingdce40cf2015-08-24 14:52:23 -070064 size_t nrSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000065
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000066void WebRtcAgc_InitVad(AgcVad* vadInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000067
minyuecac94aa2016-05-20 08:42:22 -070068int16_t WebRtcAgc_ProcessVad(AgcVad* vadInst, // (i) VAD state
69 const int16_t* in, // (i) Speech signal
Peter Kastingdce40cf2015-08-24 14:52:23 -070070 size_t nrSamples); // (i) number of samples
niklase@google.com470e71d2011-07-07 08:21:25 +000071
minyuecac94aa2016-05-20 08:42:22 -070072int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16
73 int16_t compressionGaindB, // Q0 (in dB)
74 int16_t targetLevelDbfs, // Q0 (in dB)
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000075 uint8_t limiterEnable,
76 int16_t analogTarget);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020078#endif // MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_