OLD | NEW |
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // | 180 // |
181 // Inputs: | 181 // Inputs: |
182 // - self : Pointer to the AECM instance. | 182 // - self : Pointer to the AECM instance. |
183 // - delay : Current delay estimate. | 183 // - delay : Current delay estimate. |
184 // | 184 // |
185 // Output: | 185 // Output: |
186 // - far_q : The Q-domain of the aligned far end spectrum | 186 // - far_q : The Q-domain of the aligned far end spectrum |
187 // | 187 // |
188 // Return value: | 188 // Return value: |
189 // - far_spectrum : Pointer to the aligned far end spectrum | 189 // - far_spectrum : Pointer to the aligned far end spectrum |
190 // NULL - Error | 190 // null - Error |
191 // | 191 // |
192 const uint16_t* WebRtcAecm_AlignedFarend(AecmCore* self, | 192 const uint16_t* WebRtcAecm_AlignedFarend(AecmCore* self, |
193 int* far_q, | 193 int* far_q, |
194 int delay) { | 194 int delay) { |
195 int buffer_position = 0; | 195 int buffer_position = 0; |
196 RTC_DCHECK(self); | 196 RTC_DCHECK(self); |
197 buffer_position = self->far_history_pos - delay; | 197 buffer_position = self->far_history_pos - delay; |
198 | 198 |
199 // Check buffer position | 199 // Check buffer position |
200 if (buffer_position < 0) { | 200 if (buffer_position < 0) { |
(...skipping 11 matching lines...) Expand all Loading... |
212 ResetAdaptiveChannel WebRtcAecm_ResetAdaptiveChannel; | 212 ResetAdaptiveChannel WebRtcAecm_ResetAdaptiveChannel; |
213 | 213 |
214 AecmCore* WebRtcAecm_CreateCore() { | 214 AecmCore* WebRtcAecm_CreateCore() { |
215 AecmCore* aecm = static_cast<AecmCore*>(malloc(sizeof(AecmCore))); | 215 AecmCore* aecm = static_cast<AecmCore*>(malloc(sizeof(AecmCore))); |
216 | 216 |
217 aecm->farFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, | 217 aecm->farFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, |
218 sizeof(int16_t)); | 218 sizeof(int16_t)); |
219 if (!aecm->farFrameBuf) | 219 if (!aecm->farFrameBuf) |
220 { | 220 { |
221 WebRtcAecm_FreeCore(aecm); | 221 WebRtcAecm_FreeCore(aecm); |
222 return NULL; | 222 return nullptr; |
223 } | 223 } |
224 | 224 |
225 aecm->nearNoisyFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, | 225 aecm->nearNoisyFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, |
226 sizeof(int16_t)); | 226 sizeof(int16_t)); |
227 if (!aecm->nearNoisyFrameBuf) | 227 if (!aecm->nearNoisyFrameBuf) |
228 { | 228 { |
229 WebRtcAecm_FreeCore(aecm); | 229 WebRtcAecm_FreeCore(aecm); |
230 return NULL; | 230 return nullptr; |
231 } | 231 } |
232 | 232 |
233 aecm->nearCleanFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, | 233 aecm->nearCleanFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, |
234 sizeof(int16_t)); | 234 sizeof(int16_t)); |
235 if (!aecm->nearCleanFrameBuf) | 235 if (!aecm->nearCleanFrameBuf) |
236 { | 236 { |
237 WebRtcAecm_FreeCore(aecm); | 237 WebRtcAecm_FreeCore(aecm); |
238 return NULL; | 238 return nullptr; |
239 } | 239 } |
240 | 240 |
241 aecm->outFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, | 241 aecm->outFrameBuf = WebRtc_CreateBuffer(FRAME_LEN + PART_LEN, |
242 sizeof(int16_t)); | 242 sizeof(int16_t)); |
243 if (!aecm->outFrameBuf) | 243 if (!aecm->outFrameBuf) |
244 { | 244 { |
245 WebRtcAecm_FreeCore(aecm); | 245 WebRtcAecm_FreeCore(aecm); |
246 return NULL; | 246 return nullptr; |
247 } | 247 } |
248 | 248 |
249 aecm->delay_estimator_farend = WebRtc_CreateDelayEstimatorFarend(PART_LEN1, | 249 aecm->delay_estimator_farend = WebRtc_CreateDelayEstimatorFarend(PART_LEN1, |
250 MAX_DELAY); | 250 MAX_DELAY); |
251 if (aecm->delay_estimator_farend == NULL) { | 251 if (aecm->delay_estimator_farend == nullptr) { |
252 WebRtcAecm_FreeCore(aecm); | 252 WebRtcAecm_FreeCore(aecm); |
253 return NULL; | 253 return nullptr; |
254 } | 254 } |
255 aecm->delay_estimator = | 255 aecm->delay_estimator = |
256 WebRtc_CreateDelayEstimator(aecm->delay_estimator_farend, 0); | 256 WebRtc_CreateDelayEstimator(aecm->delay_estimator_farend, 0); |
257 if (aecm->delay_estimator == NULL) { | 257 if (aecm->delay_estimator == nullptr) { |
258 WebRtcAecm_FreeCore(aecm); | 258 WebRtcAecm_FreeCore(aecm); |
259 return NULL; | 259 return nullptr; |
260 } | 260 } |
261 // TODO(bjornv): Explicitly disable robust delay validation until no | 261 // TODO(bjornv): Explicitly disable robust delay validation until no |
262 // performance regression has been established. Then remove the line. | 262 // performance regression has been established. Then remove the line. |
263 WebRtc_enable_robust_validation(aecm->delay_estimator, 0); | 263 WebRtc_enable_robust_validation(aecm->delay_estimator, 0); |
264 | 264 |
265 aecm->real_fft = WebRtcSpl_CreateRealFFT(PART_LEN_SHIFT); | 265 aecm->real_fft = WebRtcSpl_CreateRealFFT(PART_LEN_SHIFT); |
266 if (aecm->real_fft == NULL) { | 266 if (aecm->real_fft == nullptr) { |
267 WebRtcAecm_FreeCore(aecm); | 267 WebRtcAecm_FreeCore(aecm); |
268 return NULL; | 268 return nullptr; |
269 } | 269 } |
270 | 270 |
271 // Init some aecm pointers. 16 and 32 byte alignment is only necessary | 271 // Init some aecm pointers. 16 and 32 byte alignment is only necessary |
272 // for Neon code currently. | 272 // for Neon code currently. |
273 aecm->xBuf = (int16_t*) (((uintptr_t)aecm->xBuf_buf + 31) & ~ 31); | 273 aecm->xBuf = (int16_t*) (((uintptr_t)aecm->xBuf_buf + 31) & ~ 31); |
274 aecm->dBufClean = (int16_t*) (((uintptr_t)aecm->dBufClean_buf + 31) & ~ 31); | 274 aecm->dBufClean = (int16_t*) (((uintptr_t)aecm->dBufClean_buf + 31) & ~ 31); |
275 aecm->dBufNoisy = (int16_t*) (((uintptr_t)aecm->dBufNoisy_buf + 31) & ~ 31); | 275 aecm->dBufNoisy = (int16_t*) (((uintptr_t)aecm->dBufNoisy_buf + 31) & ~ 31); |
276 aecm->outBuf = (int16_t*) (((uintptr_t)aecm->outBuf_buf + 15) & ~ 15); | 276 aecm->outBuf = (int16_t*) (((uintptr_t)aecm->outBuf_buf + 15) & ~ 15); |
277 aecm->channelStored = (int16_t*) (((uintptr_t) | 277 aecm->channelStored = (int16_t*) (((uintptr_t) |
278 aecm->channelStored_buf + 15) & ~ 1
5); | 278 aecm->channelStored_buf + 15) & ~ 1
5); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 // TODO(bjornv): This function is currently not used. Add support for these | 525 // TODO(bjornv): This function is currently not used. Add support for these |
526 // parameters from a higher level | 526 // parameters from a higher level |
527 int WebRtcAecm_Control(AecmCore* aecm, int delay, int nlpFlag) { | 527 int WebRtcAecm_Control(AecmCore* aecm, int delay, int nlpFlag) { |
528 aecm->nlpFlag = nlpFlag; | 528 aecm->nlpFlag = nlpFlag; |
529 aecm->fixedDelay = delay; | 529 aecm->fixedDelay = delay; |
530 | 530 |
531 return 0; | 531 return 0; |
532 } | 532 } |
533 | 533 |
534 void WebRtcAecm_FreeCore(AecmCore* aecm) { | 534 void WebRtcAecm_FreeCore(AecmCore* aecm) { |
535 if (aecm == NULL) { | 535 if (aecm == nullptr) { |
536 return; | 536 return; |
537 } | 537 } |
538 | 538 |
539 WebRtc_FreeBuffer(aecm->farFrameBuf); | 539 WebRtc_FreeBuffer(aecm->farFrameBuf); |
540 WebRtc_FreeBuffer(aecm->nearNoisyFrameBuf); | 540 WebRtc_FreeBuffer(aecm->nearNoisyFrameBuf); |
541 WebRtc_FreeBuffer(aecm->nearCleanFrameBuf); | 541 WebRtc_FreeBuffer(aecm->nearCleanFrameBuf); |
542 WebRtc_FreeBuffer(aecm->outFrameBuf); | 542 WebRtc_FreeBuffer(aecm->outFrameBuf); |
543 | 543 |
544 WebRtc_FreeDelayEstimator(aecm->delay_estimator); | 544 WebRtc_FreeDelayEstimator(aecm->delay_estimator); |
545 WebRtc_FreeDelayEstimatorFarend(aecm->delay_estimator_farend); | 545 WebRtc_FreeDelayEstimatorFarend(aecm->delay_estimator_farend); |
546 WebRtcSpl_FreeRealFFT(aecm->real_fft); | 546 WebRtcSpl_FreeRealFFT(aecm->real_fft); |
547 | 547 |
548 free(aecm); | 548 free(aecm); |
549 } | 549 } |
550 | 550 |
551 int WebRtcAecm_ProcessFrame(AecmCore* aecm, | 551 int WebRtcAecm_ProcessFrame(AecmCore* aecm, |
552 const int16_t* farend, | 552 const int16_t* farend, |
553 const int16_t* nearendNoisy, | 553 const int16_t* nearendNoisy, |
554 const int16_t* nearendClean, | 554 const int16_t* nearendClean, |
555 int16_t* out) { | 555 int16_t* out) { |
556 int16_t outBlock_buf[PART_LEN + 8]; // Align buffer to 8-byte boundary. | 556 int16_t outBlock_buf[PART_LEN + 8]; // Align buffer to 8-byte boundary. |
557 int16_t* outBlock = (int16_t*) (((uintptr_t) outBlock_buf + 15) & ~ 15); | 557 int16_t* outBlock = (int16_t*) (((uintptr_t) outBlock_buf + 15) & ~ 15); |
558 | 558 |
559 int16_t farFrame[FRAME_LEN]; | 559 int16_t farFrame[FRAME_LEN]; |
560 const int16_t* out_ptr = NULL; | 560 const int16_t* out_ptr = nullptr; |
561 int size = 0; | 561 int size = 0; |
562 | 562 |
563 // Buffer the current frame. | 563 // Buffer the current frame. |
564 // Fetch an older one corresponding to the delay. | 564 // Fetch an older one corresponding to the delay. |
565 WebRtcAecm_BufferFarFrame(aecm, farend, FRAME_LEN); | 565 WebRtcAecm_BufferFarFrame(aecm, farend, FRAME_LEN); |
566 WebRtcAecm_FetchFarFrame(aecm, farFrame, FRAME_LEN, aecm->knownDelay); | 566 WebRtcAecm_FetchFarFrame(aecm, farFrame, FRAME_LEN, aecm->knownDelay); |
567 | 567 |
568 // Buffer the synchronized far and near frames, | 568 // Buffer the synchronized far and near frames, |
569 // to pass the smaller blocks individually. | 569 // to pass the smaller blocks individually. |
570 WebRtc_WriteBuffer(aecm->farFrameBuf, farFrame, FRAME_LEN); | 570 WebRtc_WriteBuffer(aecm->farFrameBuf, farFrame, FRAME_LEN); |
571 WebRtc_WriteBuffer(aecm->nearNoisyFrameBuf, nearendNoisy, FRAME_LEN); | 571 WebRtc_WriteBuffer(aecm->nearNoisyFrameBuf, nearendNoisy, FRAME_LEN); |
572 if (nearendClean != NULL) | 572 if (nearendClean != nullptr) { |
573 { | 573 WebRtc_WriteBuffer(aecm->nearCleanFrameBuf, nearendClean, FRAME_LEN); |
574 WebRtc_WriteBuffer(aecm->nearCleanFrameBuf, nearendClean, FRAME_LEN); | |
575 } | 574 } |
576 | 575 |
577 // Process as many blocks as possible. | 576 // Process as many blocks as possible. |
578 while (WebRtc_available_read(aecm->farFrameBuf) >= PART_LEN) | 577 while (WebRtc_available_read(aecm->farFrameBuf) >= PART_LEN) |
579 { | 578 { |
580 int16_t far_block[PART_LEN]; | 579 int16_t far_block[PART_LEN]; |
581 const int16_t* far_block_ptr = NULL; | 580 const int16_t* far_block_ptr = nullptr; |
582 int16_t near_noisy_block[PART_LEN]; | 581 int16_t near_noisy_block[PART_LEN]; |
583 const int16_t* near_noisy_block_ptr = NULL; | 582 const int16_t* near_noisy_block_ptr = nullptr; |
584 | 583 |
585 WebRtc_ReadBuffer(aecm->farFrameBuf, (void**) &far_block_ptr, far_block, | 584 WebRtc_ReadBuffer(aecm->farFrameBuf, (void**) &far_block_ptr, far_block, |
586 PART_LEN); | 585 PART_LEN); |
587 WebRtc_ReadBuffer(aecm->nearNoisyFrameBuf, | 586 WebRtc_ReadBuffer(aecm->nearNoisyFrameBuf, |
588 (void**) &near_noisy_block_ptr, | 587 (void**) &near_noisy_block_ptr, |
589 near_noisy_block, | 588 near_noisy_block, |
590 PART_LEN); | 589 PART_LEN); |
591 if (nearendClean != NULL) | 590 if (nearendClean != nullptr) { |
592 { | 591 int16_t near_clean_block[PART_LEN]; |
593 int16_t near_clean_block[PART_LEN]; | 592 const int16_t* near_clean_block_ptr = nullptr; |
594 const int16_t* near_clean_block_ptr = NULL; | |
595 | 593 |
596 WebRtc_ReadBuffer(aecm->nearCleanFrameBuf, | 594 WebRtc_ReadBuffer(aecm->nearCleanFrameBuf, |
597 (void**) &near_clean_block_ptr, | 595 (void**)&near_clean_block_ptr, near_clean_block, |
598 near_clean_block, | 596 PART_LEN); |
599 PART_LEN); | 597 if (WebRtcAecm_ProcessBlock(aecm, far_block_ptr, near_noisy_block_ptr, |
600 if (WebRtcAecm_ProcessBlock(aecm, | 598 near_clean_block_ptr, outBlock) == -1) { |
601 far_block_ptr, | 599 return -1; |
602 near_noisy_block_ptr, | 600 } |
603 near_clean_block_ptr, | |
604 outBlock) == -1) | |
605 { | |
606 return -1; | |
607 } | |
608 } else | 601 } else |
609 { | 602 { |
610 if (WebRtcAecm_ProcessBlock(aecm, | 603 if (WebRtcAecm_ProcessBlock(aecm, far_block_ptr, near_noisy_block_ptr, |
611 far_block_ptr, | 604 nullptr, outBlock) == -1) { |
612 near_noisy_block_ptr, | 605 return -1; |
613 NULL, | |
614 outBlock) == -1) | |
615 { | |
616 return -1; | |
617 } | 606 } |
618 } | 607 } |
619 | 608 |
620 WebRtc_WriteBuffer(aecm->outFrameBuf, outBlock, PART_LEN); | 609 WebRtc_WriteBuffer(aecm->outFrameBuf, outBlock, PART_LEN); |
621 } | 610 } |
622 | 611 |
623 // Stuff the out buffer if we have less than a frame to output. | 612 // Stuff the out buffer if we have less than a frame to output. |
624 // This should only happen for the first frame. | 613 // This should only happen for the first frame. |
625 size = (int) WebRtc_available_read(aecm->outFrameBuf); | 614 size = (int) WebRtc_available_read(aecm->outFrameBuf); |
626 if (size < FRAME_LEN) | 615 if (size < FRAME_LEN) |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 memcpy(farend + readPos, aecm->farBuf + aecm->farBufReadPos, | 1211 memcpy(farend + readPos, aecm->farBuf + aecm->farBufReadPos, |
1223 sizeof(int16_t) * readLen); | 1212 sizeof(int16_t) * readLen); |
1224 aecm->farBufReadPos = 0; | 1213 aecm->farBufReadPos = 0; |
1225 readPos = readLen; | 1214 readPos = readLen; |
1226 readLen = farLen - readLen; | 1215 readLen = farLen - readLen; |
1227 } | 1216 } |
1228 memcpy(farend + readPos, aecm->farBuf + aecm->farBufReadPos, | 1217 memcpy(farend + readPos, aecm->farBuf + aecm->farBufReadPos, |
1229 sizeof(int16_t) * readLen); | 1218 sizeof(int16_t) * readLen); |
1230 aecm->farBufReadPos += readLen; | 1219 aecm->farBufReadPos += readLen; |
1231 } | 1220 } |
OLD | NEW |