OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ |
13 | 13 |
14 #ifdef WEBRTC_AGC_DEBUG_DUMP | 14 #ifdef WEBRTC_AGC_DEBUG_DUMP |
15 #include <stdio.h> | 15 #include <stdio.h> |
16 #endif | 16 #endif |
17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
18 #include "webrtc/typedefs.h" | 18 #include "webrtc/typedefs.h" |
19 | 19 |
20 // the 32 most significant bits of A(19) * B(26) >> 13 | 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 )) | 21 #define AGC_MUL32(A, B) (((B) >> 13) * (A) + (((0x00001FFF & (B)) * (A)) >> 13)) |
22 // C + the 32 most significant bits of A * B | 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 )) | 23 #define AGC_SCALEDIFF32(A, B, C) \ |
| 24 ((C) + ((B) >> 16) * (A) + (((0x0000FFFF & (B)) * (A)) >> 16)) |
24 | 25 |
25 typedef struct | 26 typedef struct { |
26 { | 27 int32_t downState[8]; |
27 int32_t downState[8]; | 28 int16_t HPstate; |
28 int16_t HPstate; | 29 int16_t counter; |
29 int16_t counter; | 30 int16_t logRatio; // log( P(active) / P(inactive) ) (Q10) |
30 int16_t logRatio; // log( P(active) / P(inactive) ) (Q10) | 31 int16_t meanLongTerm; // Q10 |
31 int16_t meanLongTerm; // Q10 | 32 int32_t varianceLongTerm; // Q8 |
32 int32_t varianceLongTerm; // Q8 | 33 int16_t stdLongTerm; // Q10 |
33 int16_t stdLongTerm; // Q10 | 34 int16_t meanShortTerm; // Q10 |
34 int16_t meanShortTerm; // Q10 | 35 int32_t varianceShortTerm; // Q8 |
35 int32_t varianceShortTerm; // Q8 | 36 int16_t stdShortTerm; // Q10 |
36 int16_t stdShortTerm; // Q10 | 37 } AgcVad; // total = 54 bytes |
37 } AgcVad; // total = 54 bytes | |
38 | 38 |
39 typedef struct | 39 typedef struct { |
40 { | 40 int32_t capacitorSlow; |
41 int32_t capacitorSlow; | 41 int32_t capacitorFast; |
42 int32_t capacitorFast; | 42 int32_t gain; |
43 int32_t gain; | 43 int32_t gainTable[32]; |
44 int32_t gainTable[32]; | 44 int16_t gatePrevious; |
45 int16_t gatePrevious; | 45 int16_t agcMode; |
46 int16_t agcMode; | 46 AgcVad vadNearend; |
47 AgcVad vadNearend; | 47 AgcVad vadFarend; |
48 AgcVad vadFarend; | |
49 #ifdef WEBRTC_AGC_DEBUG_DUMP | 48 #ifdef WEBRTC_AGC_DEBUG_DUMP |
50 FILE* logFile; | 49 FILE* logFile; |
51 int frameCounter; | 50 int frameCounter; |
52 #endif | 51 #endif |
53 } DigitalAgc; | 52 } DigitalAgc; |
54 | 53 |
55 int32_t WebRtcAgc_InitDigital(DigitalAgc* digitalAgcInst, int16_t agcMode); | 54 int32_t WebRtcAgc_InitDigital(DigitalAgc* digitalAgcInst, int16_t agcMode); |
56 | 55 |
57 int32_t WebRtcAgc_ProcessDigital(DigitalAgc* digitalAgcInst, | 56 int32_t WebRtcAgc_ProcessDigital(DigitalAgc* digitalAgcInst, |
58 const int16_t* const* inNear, | 57 const int16_t* const* inNear, |
59 size_t num_bands, | 58 size_t num_bands, |
60 int16_t* const* out, | 59 int16_t* const* out, |
61 uint32_t FS, | 60 uint32_t FS, |
62 int16_t lowLevelSignal); | 61 int16_t lowLevelSignal); |
63 | 62 |
64 int32_t WebRtcAgc_AddFarendToDigital(DigitalAgc* digitalAgcInst, | 63 int32_t WebRtcAgc_AddFarendToDigital(DigitalAgc* digitalAgcInst, |
65 const int16_t* inFar, | 64 const int16_t* inFar, |
66 size_t nrSamples); | 65 size_t nrSamples); |
67 | 66 |
68 void WebRtcAgc_InitVad(AgcVad* vadInst); | 67 void WebRtcAgc_InitVad(AgcVad* vadInst); |
69 | 68 |
70 int16_t WebRtcAgc_ProcessVad(AgcVad* vadInst, // (i) VAD state | 69 int16_t WebRtcAgc_ProcessVad(AgcVad* vadInst, // (i) VAD state |
71 const int16_t* in, // (i) Speech signal | 70 const int16_t* in, // (i) Speech signal |
72 size_t nrSamples); // (i) number of samples | 71 size_t nrSamples); // (i) number of samples |
73 | 72 |
74 int32_t WebRtcAgc_CalculateGainTable(int32_t *gainTable, // Q16 | 73 int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16 |
75 int16_t compressionGaindB, // Q0 (in dB) | 74 int16_t compressionGaindB, // Q0 (in dB) |
76 int16_t targetLevelDbfs,// Q0 (in dB) | 75 int16_t targetLevelDbfs, // Q0 (in dB) |
77 uint8_t limiterEnable, | 76 uint8_t limiterEnable, |
78 int16_t analogTarget); | 77 int16_t analogTarget); |
79 | 78 |
80 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ | 79 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_LEGACY_DIGITAL_AGC_H_ |
OLD | NEW |