blob: 573f3eca05bdc71b4588f4c200817429a1116532 [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
11#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AGC_MAIN_SOURCE_DIGITAL_AGC_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_AGC_MAIN_SOURCE_DIGITAL_AGC_H_
13
14#ifdef AGC_DEBUG
15#include <stdio.h>
16#endif
17#include "typedefs.h"
18#include "signal_processing_library.h"
19
20// the 32 most significant bits of A(19) * B(26) >> 13
21#define AGC_MUL32(A, B) (((B)>>13)*(A) + ( ((0x00001FFF & (B))*(A)) >> 13 ))
22// C + the 32 most significant bits of A * B
23#define AGC_SCALEDIFF32(A, B, C) ((C) + ((B)>>16)*(A) + ( ((0x0000FFFF & (B))*(A)) >> 16 ))
24
25typedef struct
26{
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000027 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
niklase@google.com470e71d2011-07-07 08:21:25 +000037} AgcVad_t; // total = 54 bytes
38
39typedef struct
40{
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000041 int32_t capacitorSlow;
42 int32_t capacitorFast;
43 int32_t gain;
44 int32_t gainTable[32];
45 int16_t gatePrevious;
46 int16_t agcMode;
niklase@google.com470e71d2011-07-07 08:21:25 +000047 AgcVad_t vadNearend;
48 AgcVad_t vadFarend;
49#ifdef AGC_DEBUG
50 FILE* logFile;
51 int frameCounter;
52#endif
53} DigitalAgc_t;
54
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000055int32_t WebRtcAgc_InitDigital(DigitalAgc_t *digitalAgcInst, int16_t agcMode);
niklase@google.com470e71d2011-07-07 08:21:25 +000056
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000057int32_t WebRtcAgc_ProcessDigital(DigitalAgc_t *digitalAgcInst,
58 const int16_t *inNear, const int16_t *inNear_H,
59 int16_t *out, int16_t *out_H, uint32_t FS,
60 int16_t lowLevelSignal);
niklase@google.com470e71d2011-07-07 08:21:25 +000061
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000062int32_t WebRtcAgc_AddFarendToDigital(DigitalAgc_t *digitalAgcInst,
63 const int16_t *inFar,
64 int16_t nrSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000065
66void WebRtcAgc_InitVad(AgcVad_t *vadInst);
67
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000068int16_t WebRtcAgc_ProcessVad(AgcVad_t *vadInst, // (i) VAD state
69 const int16_t *in, // (i) Speech signal
70 int16_t nrSamples); // (i) number of samples
niklase@google.com470e71d2011-07-07 08:21:25 +000071
pbos@webrtc.orgb7192b82013-04-10 07:50:54 +000072int32_t WebRtcAgc_CalculateGainTable(int32_t *gainTable, // Q16
73 int16_t compressionGaindB, // Q0 (in dB)
74 int16_t targetLevelDbfs,// Q0 (in dB)
75 uint8_t limiterEnable,
76 int16_t analogTarget);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
78#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_MAIN_SOURCE_ANALOG_AGC_H_