Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: webrtc/modules/audio_coding/neteq/normal.cc

Issue 2763273003: Changed OLA window for neteq. Old code didnt work well with 48khz (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // Shift 14 with proper rounding. 123 // Shift 14 with proper rounding.
124 (*output)[channel_ix][i] = 124 (*output)[channel_ix][i] =
125 static_cast<int16_t>((scaled_signal + 8192) >> 14); 125 static_cast<int16_t>((scaled_signal + 8192) >> 14);
126 // Increase mute_factor towards 16384. 126 // Increase mute_factor towards 16384.
127 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min( 127 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min(
128 external_mute_factor_array[channel_ix] + increment, 16384)); 128 external_mute_factor_array[channel_ix] + increment, 16384));
129 } 129 }
130 130
131 // Interpolate the expanded data into the new vector. 131 // Interpolate the expanded data into the new vector.
132 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.) 132 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.)
133 RTC_DCHECK_LT(fs_shift, 3); // Will always be 0, 1, or, 2. 133 int win_length = ola_win_length_ ;
hlundin-webrtc 2017/03/23 11:41:50 int -> size_t
squashingskak 2017/03/27 10:24:59 Acknowledged.
134 increment = 4 >> fs_shift; 134 int16_t win_slope_Q14 = ola_win_slope_Q14_;
135 int fraction = increment; 135 int16_t win_up_Q14 = win_slope_Q14;
hlundin-webrtc 2017/03/23 11:41:51 Move declaration of win_up_Q14 to after the if sta
squashingskak 2017/03/27 10:24:59 Acknowledged.
136 // Don't interpolate over more samples than what is in output. When this 136 assert(channel_ix < output->Channels());
hlundin-webrtc 2017/03/23 11:41:50 RTC_DCHECK_LT(channel_ix, output->Channels());
squashingskak 2017/03/27 10:24:59 Acknowledged.
137 // cap strikes, the interpolation will likely sound worse, but this is an 137 if(win_length > (int)output->Size()){
hlundin-webrtc 2017/03/23 11:41:51 Don't cast; both sides should be size_t. Also, whe
squashingskak 2017/03/27 10:24:59 Acknowledged.
138 // emergency operation in response to unexpected input. 138 win_length = length;
139 const size_t interp_len_samples = 139 win_slope_Q14 = (1 << 14)/length;
hlundin-webrtc 2017/03/23 11:41:51 Add spaces on both sides of /
squashingskak 2017/03/27 10:24:59 Acknowledged.
140 std::min(static_cast<size_t>(8 * fs_mult), output->Size()); 140 win_up_Q14 = win_slope_Q14;
141 for (size_t i = 0; i < interp_len_samples; ++i) { 141 }
142 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 142 for (int i = 0; i < win_length; i++) {
hlundin-webrtc 2017/03/23 11:41:51 size_t i
squashingskak 2017/03/27 10:24:59 Acknowledged.
143 // now for legacy bit-exactness.
144 RTC_DCHECK_LT(channel_ix, output->Channels());
145 RTC_DCHECK_LT(i, output->Size());
146 (*output)[channel_ix][i] = 143 (*output)[channel_ix][i] =
147 static_cast<int16_t>((fraction * (*output)[channel_ix][i] + 144 (win_up_Q14 * (*output)[channel_ix][i] +
148 (32 - fraction) * expanded[channel_ix][i] + 8) >> 5); 145 ((1 << 14) - win_up_Q14) * expanded[channel_ix][i] + (1 << 13)) >> 14;
149 fraction += increment; 146 win_up_Q14 += win_slope_Q14;
150 } 147 }
hlundin-webrtc 2017/03/23 11:41:51 After this for loop, we expect the value of win_up
squashingskak 2017/03/27 10:24:59 1 << 14 / 48 = 341. 341 * 48 = 16384 = 1<< 14 - 16
hlundin-webrtc 2017/03/27 10:44:27 OK. Please, add a DCHECK. if (fs_hz_ == 48000) {
151 } 148 }
152 } else if (last_mode == kModeRfc3389Cng) { 149 } else if (last_mode == kModeRfc3389Cng) {
153 RTC_DCHECK_EQ(output->Channels(), 1); // Not adapted for multi-channel yet. 150 RTC_DCHECK_EQ(output->Channels(), 1); // Not adapted for multi-channel yet.
154 static const size_t kCngLength = 48; 151 static const size_t kCngLength = 48;
155 RTC_DCHECK_LE(8 * fs_mult, kCngLength); 152 RTC_DCHECK_LE(8 * fs_mult, kCngLength);
156 int16_t cng_output[kCngLength]; 153 int16_t cng_output[kCngLength];
157 // Reset mute factor and start up fresh. 154 // Reset mute factor and start up fresh.
158 external_mute_factor_array[0] = 16384; 155 external_mute_factor_array[0] = 16384;
159 ComfortNoiseDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); 156 ComfortNoiseDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder();
160 157
161 if (cng_decoder) { 158 if (cng_decoder) {
162 // Generate long enough for 48kHz. 159 // Generate long enough for 48kHz.
163 if (!cng_decoder->Generate(cng_output, 0)) { 160 if (!cng_decoder->Generate(cng_output, 0)) {
164 // Error returned; set return vector to all zeros. 161 // Error returned; set return vector to all zeros.
165 memset(cng_output, 0, sizeof(cng_output)); 162 memset(cng_output, 0, sizeof(cng_output));
166 } 163 }
167 } else { 164 } else {
168 // If no CNG instance is defined, just copy from the decoded data. 165 // If no CNG instance is defined, just copy from the decoded data.
169 // (This will result in interpolating the decoded with itself.) 166 // (This will result in interpolating the decoded with itself.)
170 (*output)[0].CopyTo(fs_mult * 8, 0, cng_output); 167 (*output)[0].CopyTo(fs_mult * 8, 0, cng_output);
171 } 168 }
172 // Interpolate the CNG into the new vector. 169 // Interpolate the CNG into the new vector.
173 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.) 170 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.)
174 RTC_DCHECK_LT(fs_shift, 3); // Will always be 0, 1, or, 2. 171 int win_length = ola_win_length_;
hlundin-webrtc 2017/03/23 11:41:50 All the above comments that apply here.
squashingskak 2017/03/27 10:24:59 Acknowledged.
175 int16_t increment = 4 >> fs_shift; 172 int16_t win_slope_Q14 = ola_win_slope_Q14_;
176 int16_t fraction = increment; 173 int16_t win_up_Q14 = win_slope_Q14;
177 for (size_t i = 0; i < static_cast<size_t>(8 * fs_mult); i++) { 174 if(win_length > (int)kCngLength){
178 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 now 175 win_length = (int)kCngLength;
179 // for legacy bit-exactness. 176 win_slope_Q14 = (1 << 14)/kCngLength;
180 (*output)[0][i] = (fraction * (*output)[0][i] + 177 win_up_Q14 = win_slope_Q14;
181 (32 - fraction) * cng_output[i] + 8) >> 5; 178 }
182 fraction += increment; 179 for (int i = 0; i < win_length; i++) {
180 (*output)[0][i] = (win_up_Q14 * (*output)[0][i] +
181 ((1 << 14) - win_up_Q14) * cng_output[i] + (1 << 13)) >> 14;
182 win_up_Q14 += win_slope_Q14;
183 } 183 }
184 } else if (external_mute_factor_array[0] < 16384) { 184 } else if (external_mute_factor_array[0] < 16384) {
185 // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are 185 // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are
186 // still ramping up from previous muting. 186 // still ramping up from previous muting.
187 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). 187 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14).
188 int increment = 64 / fs_mult; 188 int increment = 64 / fs_mult;
189 size_t length_per_channel = length / output->Channels(); 189 size_t length_per_channel = length / output->Channels();
190 for (size_t i = 0; i < length_per_channel; i++) { 190 for (size_t i = 0; i < length_per_channel; i++) {
191 for (size_t channel_ix = 0; channel_ix < output->Channels(); 191 for (size_t channel_ix = 0; channel_ix < output->Channels();
192 ++channel_ix) { 192 ++channel_ix) {
193 // Scale with mute factor. 193 // Scale with mute factor.
194 RTC_DCHECK_LT(channel_ix, output->Channels()); 194 RTC_DCHECK_LT(channel_ix, output->Channels());
195 RTC_DCHECK_LT(i, output->Size()); 195 RTC_DCHECK_LT(i, output->Size());
196 int32_t scaled_signal = (*output)[channel_ix][i] * 196 int32_t scaled_signal = (*output)[channel_ix][i] *
197 external_mute_factor_array[channel_ix]; 197 external_mute_factor_array[channel_ix];
198 // Shift 14 with proper rounding. 198 // Shift 14 with proper rounding.
199 (*output)[channel_ix][i] = 199 (*output)[channel_ix][i] =
200 static_cast<int16_t>((scaled_signal + 8192) >> 14); 200 static_cast<int16_t>((scaled_signal + 8192) >> 14);
201 // Increase mute_factor towards 16384. 201 // Increase mute_factor towards 16384.
202 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min( 202 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min(
203 16384, external_mute_factor_array[channel_ix] + increment)); 203 16384, external_mute_factor_array[channel_ix] + increment));
204 } 204 }
205 } 205 }
206 } 206 }
207 207
208 return static_cast<int>(length); 208 return static_cast<int>(length);
209 } 209 }
210 210
211 } // namespace webrtc 211 } // namespace webrtc
OLDNEW
« webrtc/modules/audio_coding/neteq/normal.h ('K') | « webrtc/modules/audio_coding/neteq/normal.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698