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 |
(...skipping 14 matching lines...) Expand all Loading... |
25 * In the beginning the range is narrower to widen as soon as the measure | 25 * In the beginning the range is narrower to widen as soon as the measure |
26 * 'Rxx160_LP' is inside it. Currently the starting limits are -22.2+/-1dBm0 | 26 * 'Rxx160_LP' is inside it. Currently the starting limits are -22.2+/-1dBm0 |
27 * and the final limits -22.2+/-2.5dBm0. These levels makes the speech signal | 27 * and the final limits -22.2+/-2.5dBm0. These levels makes the speech signal |
28 * go towards -25.4dBm0 (-31.4dBov). Tuned with wbfile-31.4dBov.pcm | 28 * go towards -25.4dBm0 (-31.4dBov). Tuned with wbfile-31.4dBov.pcm |
29 * The limits are created by running the AGC with a file having the desired | 29 * The limits are created by running the AGC with a file having the desired |
30 * signal level and thereafter plotting Rxx160_LP in the dBm0-domain defined | 30 * signal level and thereafter plotting Rxx160_LP in the dBm0-domain defined |
31 * by out=10*log10(in/260537279.7); Set the target level to the average level | 31 * by out=10*log10(in/260537279.7); Set the target level to the average level |
32 * of our measure Rxx160_LP. Remember that the levels are in blocks of 16 in | 32 * of our measure Rxx160_LP. Remember that the levels are in blocks of 16 in |
33 * Q(-7). (Example matlab code: round(db2pow(-21.2)*16/2^7) ) | 33 * Q(-7). (Example matlab code: round(db2pow(-21.2)*16/2^7) ) |
34 */ | 34 */ |
35 #define RXX_BUFFER_LEN 10 | 35 #define RXX_BUFFER_LEN 10 |
36 | 36 |
37 static const int16_t kMsecSpeechInner = 520; | 37 static const int16_t kMsecSpeechInner = 520; |
38 static const int16_t kMsecSpeechOuter = 340; | 38 static const int16_t kMsecSpeechOuter = 340; |
39 | 39 |
40 static const int16_t kNormalVadThreshold = 400; | 40 static const int16_t kNormalVadThreshold = 400; |
41 | 41 |
42 static const int16_t kAlphaShortTerm = 6; // 1 >> 6 = 0.0156 | 42 static const int16_t kAlphaShortTerm = 6; // 1 >> 6 = 0.0156 |
43 static const int16_t kAlphaLongTerm = 10; // 1 >> 10 = 0.000977 | 43 static const int16_t kAlphaLongTerm = 10; // 1 >> 10 = 0.000977 |
44 | 44 |
45 typedef struct | 45 typedef struct { |
46 { | 46 // Configurable parameters/variables |
47 // Configurable parameters/variables | 47 uint32_t fs; // Sampling frequency |
48 uint32_t fs; // Sampling frequency | 48 int16_t compressionGaindB; // Fixed gain level in dB |
49 int16_t compressionGaindB; // Fixed gain level in dB | 49 int16_t targetLevelDbfs; // Target level in -dBfs of envelope (default -3) |
50 int16_t targetLevelDbfs; // Target level in -dBfs of envelope
(default -3) | 50 int16_t agcMode; // Hard coded mode (adaptAna/adaptDig/fixedDig) |
51 int16_t agcMode; // Hard coded mode (adaptAna/adaptDi
g/fixedDig) | 51 uint8_t limiterEnable; // Enabling limiter (on/off (default off)) |
52 uint8_t limiterEnable; // Enabling limiter (on/off (default
off)) | 52 WebRtcAgcConfig defaultConfig; |
53 WebRtcAgcConfig defaultConfig; | 53 WebRtcAgcConfig usedConfig; |
54 WebRtcAgcConfig usedConfig; | |
55 | 54 |
56 // General variables | 55 // General variables |
57 int16_t initFlag; | 56 int16_t initFlag; |
58 int16_t lastError; | 57 int16_t lastError; |
59 | 58 |
60 // Target level parameters | 59 // Target level parameters |
61 // Based on the above: analogTargetLevel = round((32767*10^(-22/20))^2*16/2^
7) | 60 // Based on the above: analogTargetLevel = round((32767*10^(-22/20))^2*16/2^7) |
62 int32_t analogTargetLevel; // = RXX_BUFFER_LEN * 846805;
-22 dBfs | 61 int32_t analogTargetLevel; // = RXX_BUFFER_LEN * 846805; -22 dBfs |
63 int32_t startUpperLimit; // = RXX_BUFFER_LEN * 1066064;
-21 dBfs | 62 int32_t startUpperLimit; // = RXX_BUFFER_LEN * 1066064; -21 dBfs |
64 int32_t startLowerLimit; // = RXX_BUFFER_LEN * 672641;
-23 dBfs | 63 int32_t startLowerLimit; // = RXX_BUFFER_LEN * 672641; -23 dBfs |
65 int32_t upperPrimaryLimit; // = RXX_BUFFER_LEN * 1342095;
-20 dBfs | 64 int32_t upperPrimaryLimit; // = RXX_BUFFER_LEN * 1342095; -20 dBfs |
66 int32_t lowerPrimaryLimit; // = RXX_BUFFER_LEN * 534298;
-24 dBfs | 65 int32_t lowerPrimaryLimit; // = RXX_BUFFER_LEN * 534298; -24 dBfs |
67 int32_t upperSecondaryLimit;// = RXX_BUFFER_LEN * 2677832;
-17 dBfs | 66 int32_t upperSecondaryLimit; // = RXX_BUFFER_LEN * 2677832; -17 dBfs |
68 int32_t lowerSecondaryLimit;// = RXX_BUFFER_LEN * 267783;
-27 dBfs | 67 int32_t lowerSecondaryLimit; // = RXX_BUFFER_LEN * 267783; -27 dBfs |
69 uint16_t targetIdx; // Table index for corresponding tar
get level | 68 uint16_t targetIdx; // Table index for corresponding target level |
70 #ifdef MIC_LEVEL_FEEDBACK | 69 #ifdef MIC_LEVEL_FEEDBACK |
71 uint16_t targetIdxOffset; // Table index offset for level comp
ensation | 70 uint16_t targetIdxOffset; // Table index offset for level compensation |
72 #endif | 71 #endif |
73 int16_t analogTarget; // Digital reference level in ENV sc
ale | 72 int16_t analogTarget; // Digital reference level in ENV scale |
74 | 73 |
75 // Analog AGC specific variables | 74 // Analog AGC specific variables |
76 int32_t filterState[8]; // For downsampling wb to nb | 75 int32_t filterState[8]; // For downsampling wb to nb |
77 int32_t upperLimit; // Upper limit for mic energy | 76 int32_t upperLimit; // Upper limit for mic energy |
78 int32_t lowerLimit; // Lower limit for mic energy | 77 int32_t lowerLimit; // Lower limit for mic energy |
79 int32_t Rxx160w32; // Average energy for one frame | 78 int32_t Rxx160w32; // Average energy for one frame |
80 int32_t Rxx16_LPw32; // Low pass filtered subframe energi
es | 79 int32_t Rxx16_LPw32; // Low pass filtered subframe energies |
81 int32_t Rxx160_LPw32; // Low pass filtered frame energies | 80 int32_t Rxx160_LPw32; // Low pass filtered frame energies |
82 int32_t Rxx16_LPw32Max; // Keeps track of largest energy sub
frame | 81 int32_t Rxx16_LPw32Max; // Keeps track of largest energy subframe |
83 int32_t Rxx16_vectorw32[RXX_BUFFER_LEN];// Array with subframe e
nergies | 82 int32_t Rxx16_vectorw32[RXX_BUFFER_LEN]; // Array with subframe energies |
84 int32_t Rxx16w32_array[2][5];// Energy values of microphone sign
al | 83 int32_t Rxx16w32_array[2][5]; // Energy values of microphone signal |
85 int32_t env[2][10]; // Envelope values of subframes | 84 int32_t env[2][10]; // Envelope values of subframes |
86 | 85 |
87 int16_t Rxx16pos; // Current position in the Rxx16_vec
torw32 | 86 int16_t Rxx16pos; // Current position in the Rxx16_vectorw32 |
88 int16_t envSum; // Filtered scaled envelope in subfr
ames | 87 int16_t envSum; // Filtered scaled envelope in subframes |
89 int16_t vadThreshold; // Threshold for VAD decision | 88 int16_t vadThreshold; // Threshold for VAD decision |
90 int16_t inActive; // Inactive time in milliseconds | 89 int16_t inActive; // Inactive time in milliseconds |
91 int16_t msTooLow; // Milliseconds of speech at a too l
ow level | 90 int16_t msTooLow; // Milliseconds of speech at a too low level |
92 int16_t msTooHigh; // Milliseconds of speech at a too h
igh level | 91 int16_t msTooHigh; // Milliseconds of speech at a too high level |
93 int16_t changeToSlowMode; // Change to slow mode after some ti
me at target | 92 int16_t changeToSlowMode; // Change to slow mode after some time at target |
94 int16_t firstCall; // First call to the process-functio
n | 93 int16_t firstCall; // First call to the process-function |
95 int16_t msZero; // Milliseconds of zero input | 94 int16_t msZero; // Milliseconds of zero input |
96 int16_t msecSpeechOuterChange;// Min ms of speech between volume
changes | 95 int16_t msecSpeechOuterChange; // Min ms of speech between volume changes |
97 int16_t msecSpeechInnerChange;// Min ms of speech between volume
changes | 96 int16_t msecSpeechInnerChange; // Min ms of speech between volume changes |
98 int16_t activeSpeech; // Milliseconds of active speech | 97 int16_t activeSpeech; // Milliseconds of active speech |
99 int16_t muteGuardMs; // Counter to prevent mute action | 98 int16_t muteGuardMs; // Counter to prevent mute action |
100 int16_t inQueue; // 10 ms batch indicator | 99 int16_t inQueue; // 10 ms batch indicator |
101 | 100 |
102 // Microphone level variables | 101 // Microphone level variables |
103 int32_t micRef; // Remember ref. mic level for virtu
al mic | 102 int32_t micRef; // Remember ref. mic level for virtual mic |
104 uint16_t gainTableIdx; // Current position in virtual gain
table | 103 uint16_t gainTableIdx; // Current position in virtual gain table |
105 int32_t micGainIdx; // Gain index of mic level to increa
se slowly | 104 int32_t micGainIdx; // Gain index of mic level to increase slowly |
106 int32_t micVol; // Remember volume between frames | 105 int32_t micVol; // Remember volume between frames |
107 int32_t maxLevel; // Max possible vol level, incl dig
gain | 106 int32_t maxLevel; // Max possible vol level, incl dig gain |
108 int32_t maxAnalog; // Maximum possible analog volume le
vel | 107 int32_t maxAnalog; // Maximum possible analog volume level |
109 int32_t maxInit; // Initial value of "max" | 108 int32_t maxInit; // Initial value of "max" |
110 int32_t minLevel; // Minimum possible volume level | 109 int32_t minLevel; // Minimum possible volume level |
111 int32_t minOutput; // Minimum output volume level | 110 int32_t minOutput; // Minimum output volume level |
112 int32_t zeroCtrlMax; // Remember max gain => don't amp lo
w input | 111 int32_t zeroCtrlMax; // Remember max gain => don't amp low input |
113 int32_t lastInMicLevel; | 112 int32_t lastInMicLevel; |
114 | 113 |
115 int16_t scale; // Scale factor for internal volume
levels | 114 int16_t scale; // Scale factor for internal volume levels |
116 #ifdef MIC_LEVEL_FEEDBACK | 115 #ifdef MIC_LEVEL_FEEDBACK |
117 int16_t numBlocksMicLvlSat; | 116 int16_t numBlocksMicLvlSat; |
118 uint8_t micLvlSat; | 117 uint8_t micLvlSat; |
119 #endif | 118 #endif |
120 // Structs for VAD and digital_agc | 119 // Structs for VAD and digital_agc |
121 AgcVad vadMic; | 120 AgcVad vadMic; |
122 DigitalAgc digitalAgc; | 121 DigitalAgc digitalAgc; |
123 | 122 |
124 #ifdef WEBRTC_AGC_DEBUG_DUMP | 123 #ifdef WEBRTC_AGC_DEBUG_DUMP |
125 FILE* fpt; | 124 FILE* fpt; |
126 FILE* agcLog; | 125 FILE* agcLog; |
127 int32_t fcount; | 126 int32_t fcount; |
128 #endif | 127 #endif |
129 | 128 |
130 int16_t lowLevelSignal; | 129 int16_t lowLevelSignal; |
131 } LegacyAgc; | 130 } LegacyAgc; |
132 | 131 |
133 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_LEGACY_ANALOG_AGC_H_ | 132 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AGC_LEGACY_ANALOG_AGC_H_ |
OLD | NEW |