niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
bjornv@webrtc.org | ea29787 | 2014-09-23 11:21:39 +0000 | [diff] [blame] | 14 | #ifdef WEBRTC_AGC_DEBUG_DUMP |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
| 16 | #endif |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "common_audio/signal_processing/include/signal_processing_library.h" |
| 18 | #include "typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
| 20 | // the 32 most significant bits of A(19) * B(26) >> 13 |
minyue | cac94aa | 2016-05-20 08:42:22 -0700 | [diff] [blame] | 21 | #define AGC_MUL32(A, B) (((B) >> 13) * (A) + (((0x00001FFF & (B)) * (A)) >> 13)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | // C + the 32 most significant bits of A * B |
minyue | cac94aa | 2016-05-20 08:42:22 -0700 | [diff] [blame] | 23 | #define AGC_SCALEDIFF32(A, B, C) \ |
| 24 | ((C) + ((B) >> 16) * (A) + (((0x0000FFFF & (B)) * (A)) >> 16)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
minyue | cac94aa | 2016-05-20 08:42:22 -0700 | [diff] [blame] | 26 | typedef 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
minyue | cac94aa | 2016-05-20 08:42:22 -0700 | [diff] [blame] | 39 | typedef 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.org | ea29787 | 2014-09-23 11:21:39 +0000 | [diff] [blame] | 48 | #ifdef WEBRTC_AGC_DEBUG_DUMP |
minyue | cac94aa | 2016-05-20 08:42:22 -0700 | [diff] [blame] | 49 | FILE* logFile; |
| 50 | int frameCounter; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | #endif |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 52 | } DigitalAgc; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 54 | int32_t WebRtcAgc_InitDigital(DigitalAgc* digitalAgcInst, int16_t agcMode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 56 | int32_t WebRtcAgc_ProcessDigital(DigitalAgc* digitalAgcInst, |
aluebs@webrtc.org | cf6d0b6 | 2014-12-16 20:56:09 +0000 | [diff] [blame] | 57 | const int16_t* const* inNear, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 58 | size_t num_bands, |
aluebs@webrtc.org | cf6d0b6 | 2014-12-16 20:56:09 +0000 | [diff] [blame] | 59 | int16_t* const* out, |
| 60 | uint32_t FS, |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 61 | int16_t lowLevelSignal); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 63 | int32_t WebRtcAgc_AddFarendToDigital(DigitalAgc* digitalAgcInst, |
| 64 | const int16_t* inFar, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 65 | size_t nrSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
pbos@webrtc.org | e468bc9 | 2014-12-18 09:11:33 +0000 | [diff] [blame] | 67 | void WebRtcAgc_InitVad(AgcVad* vadInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
minyue | cac94aa | 2016-05-20 08:42:22 -0700 | [diff] [blame] | 69 | int16_t WebRtcAgc_ProcessVad(AgcVad* vadInst, // (i) VAD state |
| 70 | const int16_t* in, // (i) Speech signal |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 71 | size_t nrSamples); // (i) number of samples |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
minyue | cac94aa | 2016-05-20 08:42:22 -0700 | [diff] [blame] | 73 | int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16 |
| 74 | int16_t compressionGaindB, // Q0 (in dB) |
| 75 | int16_t targetLevelDbfs, // Q0 (in dB) |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 76 | uint8_t limiterEnable, |
| 77 | int16_t analogTarget); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 79 | #endif // MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ |