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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 #ifdef WEBRTC_AEC_DEBUG_DUMP | 98 #ifdef WEBRTC_AEC_DEBUG_DUMP |
99 int webrtc_aec_instance_count = 0; | 99 int webrtc_aec_instance_count = 0; |
100 #endif | 100 #endif |
101 | 101 |
102 // Estimates delay to set the position of the far-end buffer read pointer | 102 // Estimates delay to set the position of the far-end buffer read pointer |
103 // (controlled by knownDelay) | 103 // (controlled by knownDelay) |
104 static void EstBufDelayNormal(Aec* aecInst); | 104 static void EstBufDelayNormal(Aec* aecInst); |
105 static void EstBufDelayExtended(Aec* aecInst); | 105 static void EstBufDelayExtended(Aec* aecInst); |
106 static int ProcessNormal(Aec* self, | 106 static int ProcessNormal(Aec* self, |
107 const float* const* near, | 107 const float* const* near, |
108 int num_bands, | 108 size_t num_bands, |
109 float* const* out, | 109 float* const* out, |
110 int16_t num_samples, | 110 size_t num_samples, |
111 int16_t reported_delay_ms, | 111 int16_t reported_delay_ms, |
112 int32_t skew); | 112 int32_t skew); |
113 static void ProcessExtended(Aec* self, | 113 static void ProcessExtended(Aec* self, |
114 const float* const* near, | 114 const float* const* near, |
115 int num_bands, | 115 size_t num_bands, |
116 float* const* out, | 116 float* const* out, |
117 int16_t num_samples, | 117 size_t num_samples, |
118 int16_t reported_delay_ms, | 118 int16_t reported_delay_ms, |
119 int32_t skew); | 119 int32_t skew); |
120 | 120 |
121 void* WebRtcAec_Create() { | 121 void* WebRtcAec_Create() { |
122 Aec* aecpc = malloc(sizeof(Aec)); | 122 Aec* aecpc = malloc(sizeof(Aec)); |
123 | 123 |
124 if (!aecpc) { | 124 if (!aecpc) { |
125 return NULL; | 125 return NULL; |
126 } | 126 } |
127 | 127 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 aecpc->lastError = AEC_UNSPECIFIED_ERROR; | 264 aecpc->lastError = AEC_UNSPECIFIED_ERROR; |
265 return -1; | 265 return -1; |
266 } | 266 } |
267 | 267 |
268 return 0; | 268 return 0; |
269 } | 269 } |
270 | 270 |
271 // only buffer L band for farend | 271 // only buffer L band for farend |
272 int32_t WebRtcAec_BufferFarend(void* aecInst, | 272 int32_t WebRtcAec_BufferFarend(void* aecInst, |
273 const float* farend, | 273 const float* farend, |
274 int16_t nrOfSamples) { | 274 size_t nrOfSamples) { |
275 Aec* aecpc = aecInst; | 275 Aec* aecpc = aecInst; |
276 int newNrOfSamples = nrOfSamples; | 276 size_t newNrOfSamples = nrOfSamples; |
277 float new_farend[MAX_RESAMP_LEN]; | 277 float new_farend[MAX_RESAMP_LEN]; |
278 const float* farend_ptr = farend; | 278 const float* farend_ptr = farend; |
279 | 279 |
280 if (farend == NULL) { | 280 if (farend == NULL) { |
281 aecpc->lastError = AEC_NULL_POINTER_ERROR; | 281 aecpc->lastError = AEC_NULL_POINTER_ERROR; |
282 return -1; | 282 return -1; |
283 } | 283 } |
284 | 284 |
285 if (aecpc->initFlag != initCheck) { | 285 if (aecpc->initFlag != initCheck) { |
286 aecpc->lastError = AEC_UNINITIALIZED_ERROR; | 286 aecpc->lastError = AEC_UNINITIALIZED_ERROR; |
(...skipping 11 matching lines...) Expand all Loading... |
298 WebRtcAec_ResampleLinear(aecpc->resampler, | 298 WebRtcAec_ResampleLinear(aecpc->resampler, |
299 farend, | 299 farend, |
300 nrOfSamples, | 300 nrOfSamples, |
301 aecpc->skew, | 301 aecpc->skew, |
302 new_farend, | 302 new_farend, |
303 &newNrOfSamples); | 303 &newNrOfSamples); |
304 farend_ptr = new_farend; | 304 farend_ptr = new_farend; |
305 } | 305 } |
306 | 306 |
307 aecpc->farend_started = 1; | 307 aecpc->farend_started = 1; |
308 WebRtcAec_SetSystemDelay(aecpc->aec, | 308 WebRtcAec_SetSystemDelay( |
309 WebRtcAec_system_delay(aecpc->aec) + newNrOfSamples); | 309 aecpc->aec, WebRtcAec_system_delay(aecpc->aec) + (int)newNrOfSamples); |
310 | 310 |
311 // Write the time-domain data to |far_pre_buf|. | 311 // Write the time-domain data to |far_pre_buf|. |
312 WebRtc_WriteBuffer(aecpc->far_pre_buf, farend_ptr, (size_t)newNrOfSamples); | 312 WebRtc_WriteBuffer(aecpc->far_pre_buf, farend_ptr, newNrOfSamples); |
313 | 313 |
314 // Transform to frequency domain if we have enough data. | 314 // Transform to frequency domain if we have enough data. |
315 while (WebRtc_available_read(aecpc->far_pre_buf) >= PART_LEN2) { | 315 while (WebRtc_available_read(aecpc->far_pre_buf) >= PART_LEN2) { |
316 // We have enough data to pass to the FFT, hence read PART_LEN2 samples. | 316 // We have enough data to pass to the FFT, hence read PART_LEN2 samples. |
317 { | 317 { |
318 float* ptmp = NULL; | 318 float* ptmp = NULL; |
319 float tmp[PART_LEN2]; | 319 float tmp[PART_LEN2]; |
320 WebRtc_ReadBuffer(aecpc->far_pre_buf, (void**)&ptmp, tmp, PART_LEN2); | 320 WebRtc_ReadBuffer(aecpc->far_pre_buf, (void**)&ptmp, tmp, PART_LEN2); |
321 WebRtcAec_BufferFarendPartition(aecpc->aec, ptmp); | 321 WebRtcAec_BufferFarendPartition(aecpc->aec, ptmp); |
322 #ifdef WEBRTC_AEC_DEBUG_DUMP | 322 #ifdef WEBRTC_AEC_DEBUG_DUMP |
323 WebRtc_WriteBuffer( | 323 WebRtc_WriteBuffer( |
324 WebRtcAec_far_time_buf(aecpc->aec), &ptmp[PART_LEN], 1); | 324 WebRtcAec_far_time_buf(aecpc->aec), &ptmp[PART_LEN], 1); |
325 #endif | 325 #endif |
326 } | 326 } |
327 | 327 |
328 // Rewind |far_pre_buf| PART_LEN samples for overlap before continuing. | 328 // Rewind |far_pre_buf| PART_LEN samples for overlap before continuing. |
329 WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN); | 329 WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN); |
330 } | 330 } |
331 | 331 |
332 return 0; | 332 return 0; |
333 } | 333 } |
334 | 334 |
335 int32_t WebRtcAec_Process(void* aecInst, | 335 int32_t WebRtcAec_Process(void* aecInst, |
336 const float* const* nearend, | 336 const float* const* nearend, |
337 int num_bands, | 337 size_t num_bands, |
338 float* const* out, | 338 float* const* out, |
339 int16_t nrOfSamples, | 339 size_t nrOfSamples, |
340 int16_t msInSndCardBuf, | 340 int16_t msInSndCardBuf, |
341 int32_t skew) { | 341 int32_t skew) { |
342 Aec* aecpc = aecInst; | 342 Aec* aecpc = aecInst; |
343 int32_t retVal = 0; | 343 int32_t retVal = 0; |
344 | 344 |
345 if (out == NULL) { | 345 if (out == NULL) { |
346 aecpc->lastError = AEC_NULL_POINTER_ERROR; | 346 aecpc->lastError = AEC_NULL_POINTER_ERROR; |
347 return -1; | 347 return -1; |
348 } | 348 } |
349 | 349 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 | 585 |
586 AecCore* WebRtcAec_aec_core(void* handle) { | 586 AecCore* WebRtcAec_aec_core(void* handle) { |
587 if (!handle) { | 587 if (!handle) { |
588 return NULL; | 588 return NULL; |
589 } | 589 } |
590 return ((Aec*)handle)->aec; | 590 return ((Aec*)handle)->aec; |
591 } | 591 } |
592 | 592 |
593 static int ProcessNormal(Aec* aecpc, | 593 static int ProcessNormal(Aec* aecpc, |
594 const float* const* nearend, | 594 const float* const* nearend, |
595 int num_bands, | 595 size_t num_bands, |
596 float* const* out, | 596 float* const* out, |
597 int16_t nrOfSamples, | 597 size_t nrOfSamples, |
598 int16_t msInSndCardBuf, | 598 int16_t msInSndCardBuf, |
599 int32_t skew) { | 599 int32_t skew) { |
600 int retVal = 0; | 600 int retVal = 0; |
601 short i; | 601 size_t i; |
602 short nBlocks10ms; | 602 size_t nBlocks10ms; |
603 // Limit resampling to doubling/halving of signal | 603 // Limit resampling to doubling/halving of signal |
604 const float minSkewEst = -0.5f; | 604 const float minSkewEst = -0.5f; |
605 const float maxSkewEst = 1.0f; | 605 const float maxSkewEst = 1.0f; |
606 | 606 |
607 msInSndCardBuf = | 607 msInSndCardBuf = |
608 msInSndCardBuf > kMaxTrustedDelayMs ? kMaxTrustedDelayMs : msInSndCardBuf; | 608 msInSndCardBuf > kMaxTrustedDelayMs ? kMaxTrustedDelayMs : msInSndCardBuf; |
609 // TODO(andrew): we need to investigate if this +10 is really wanted. | 609 // TODO(andrew): we need to investigate if this +10 is really wanted. |
610 msInSndCardBuf += 10; | 610 msInSndCardBuf += 10; |
611 aecpc->msInSndCardBuf = msInSndCardBuf; | 611 aecpc->msInSndCardBuf = msInSndCardBuf; |
612 | 612 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 nrOfSamples, | 733 nrOfSamples, |
734 aecpc->knownDelay, | 734 aecpc->knownDelay, |
735 out); | 735 out); |
736 } | 736 } |
737 | 737 |
738 return retVal; | 738 return retVal; |
739 } | 739 } |
740 | 740 |
741 static void ProcessExtended(Aec* self, | 741 static void ProcessExtended(Aec* self, |
742 const float* const* near, | 742 const float* const* near, |
743 int num_bands, | 743 size_t num_bands, |
744 float* const* out, | 744 float* const* out, |
745 int16_t num_samples, | 745 size_t num_samples, |
746 int16_t reported_delay_ms, | 746 int16_t reported_delay_ms, |
747 int32_t skew) { | 747 int32_t skew) { |
748 int i; | 748 size_t i; |
749 const int delay_diff_offset = kDelayDiffOffsetSamples; | 749 const int delay_diff_offset = kDelayDiffOffsetSamples; |
750 #if defined(WEBRTC_UNTRUSTED_DELAY) | 750 #if defined(WEBRTC_UNTRUSTED_DELAY) |
751 reported_delay_ms = kFixedDelayMs; | 751 reported_delay_ms = kFixedDelayMs; |
752 #else | 752 #else |
753 // This is the usual mode where we trust the reported system delay values. | 753 // This is the usual mode where we trust the reported system delay values. |
754 // Due to the longer filter, we no longer add 10 ms to the reported delay | 754 // Due to the longer filter, we no longer add 10 ms to the reported delay |
755 // to reduce chance of non-causality. Instead we apply a minimum here to avoid | 755 // to reduce chance of non-causality. Instead we apply a minimum here to avoid |
756 // issues with the read pointer jumping around needlessly. | 756 // issues with the read pointer jumping around needlessly. |
757 reported_delay_ms = reported_delay_ms < kMinTrustedDelayMs | 757 reported_delay_ms = reported_delay_ms < kMinTrustedDelayMs |
758 ? kMinTrustedDelayMs | 758 ? kMinTrustedDelayMs |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 } | 914 } |
915 } else { | 915 } else { |
916 self->timeForDelayChange = 0; | 916 self->timeForDelayChange = 0; |
917 } | 917 } |
918 self->lastDelayDiff = delay_difference; | 918 self->lastDelayDiff = delay_difference; |
919 | 919 |
920 if (self->timeForDelayChange > 25) { | 920 if (self->timeForDelayChange > 25) { |
921 self->knownDelay = WEBRTC_SPL_MAX((int)self->filtDelay - 256, 0); | 921 self->knownDelay = WEBRTC_SPL_MAX((int)self->filtDelay - 256, 0); |
922 } | 922 } |
923 } | 923 } |
OLD | NEW |