blob: af6cf488371f2ba654b57e77601d36325f71d360 [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"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000019
20// the 32 most significant bits of A(19) * B(26) >> 13
minyuecac94aa2016-05-20 08:42:22 -070021#define AGC_MUL32(A, B) (((B) >> 13) * (A) + (((0x00001FFF & (B)) * (A)) >> 13))
niklase@google.com470e71d2011-07-07 08:21:25 +000022// C + the 32 most significant bits of A * B
minyuecac94aa2016-05-20 08:42:22 -070023#define AGC_SCALEDIFF32(A, B, C) \
24 ((C) + ((B) >> 16) * (A) + (((0x0000FFFF & (B)) * (A)) >> 16))
niklase@google.com470e71d2011-07-07 08:21:25 +000025
minyuecac94aa2016-05-20 08:42:22 -070026typedef struct {
27 int32_t downState[8];
28 int16_t HPstate;
29 int16_t counter;
30 int16_t logRatio; // log( P(active) / P(inactive) ) (Q10)
31 int16_t meanLongTerm; // Q10
32 int32_t varianceLongTerm; // Q8
33 int16_t stdLongTerm; // Q10
34 int16_t meanShortTerm; // Q10
35 int32_t varianceShortTerm; // Q8
36 int16_t stdShortTerm; // Q10
37} AgcVad; // total = 54 bytes
niklase@google.com470e71d2011-07-07 08:21:25 +000038
minyuecac94aa2016-05-20 08:42:22 -070039typedef struct {
40 int32_t capacitorSlow;
41 int32_t capacitorFast;
42 int32_t gain;
43 int32_t gainTable[32];
44 int16_t gatePrevious;
45 int16_t agcMode;
46 AgcVad vadNearend;
47 AgcVad vadFarend;
bjornv@webrtc.orgea297872014-09-23 11:21:39 +000048#ifdef WEBRTC_AGC_DEBUG_DUMP
minyuecac94aa2016-05-20 08:42:22 -070049 FILE* logFile;
50 int frameCounter;
niklase@google.com470e71d2011-07-07 08:21:25 +000051#endif
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000052} DigitalAgc;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000054int32_t WebRtcAgc_InitDigital(DigitalAgc* digitalAgcInst, int16_t agcMode);
niklase@google.com470e71d2011-07-07 08:21:25 +000055
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000056int32_t WebRtcAgc_ProcessDigital(DigitalAgc* digitalAgcInst,
aluebs@webrtc.orgcf6d0b62014-12-16 20:56:09 +000057 const int16_t* const* inNear,
Peter Kastingdce40cf2015-08-24 14:52:23 -070058 size_t num_bands,
aluebs@webrtc.orgcf6d0b62014-12-16 20:56:09 +000059 int16_t* const* out,
60 uint32_t FS,
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000061 int16_t lowLevelSignal);
niklase@google.com470e71d2011-07-07 08:21:25 +000062
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000063int32_t WebRtcAgc_AddFarendToDigital(DigitalAgc* digitalAgcInst,
64 const int16_t* inFar,
Peter Kastingdce40cf2015-08-24 14:52:23 -070065 size_t nrSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000066
pbos@webrtc.orge468bc92014-12-18 09:11:33 +000067void WebRtcAgc_InitVad(AgcVad* vadInst);
niklase@google.com470e71d2011-07-07 08:21:25 +000068
minyuecac94aa2016-05-20 08:42:22 -070069int16_t WebRtcAgc_ProcessVad(AgcVad* vadInst, // (i) VAD state
70 const int16_t* in, // (i) Speech signal
Peter Kastingdce40cf2015-08-24 14:52:23 -070071 size_t nrSamples); // (i) number of samples
niklase@google.com470e71d2011-07-07 08:21:25 +000072
minyuecac94aa2016-05-20 08:42:22 -070073int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16
74 int16_t compressionGaindB, // Q0 (in dB)
75 int16_t targetLevelDbfs, // Q0 (in dB)
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000076 uint8_t limiterEnable,
77 int16_t analogTarget);
niklase@google.com470e71d2011-07-07 08:21:25 +000078
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#endif // MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_