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

Side by Side Diff: webrtc/modules/audio_processing/aecm/echo_control_mobile.c

Issue 1404743003: Removed the indirect error message reporting in aec and aecm. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@process_test_no_output_CL
Patch Set: Merge from latest master Created 5 years, 1 month 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 #ifdef AEC_DEBUG 62 #ifdef AEC_DEBUG
63 FILE *bufFile; 63 FILE *bufFile;
64 FILE *delayFile; 64 FILE *delayFile;
65 FILE *preCompFile; 65 FILE *preCompFile;
66 FILE *postCompFile; 66 FILE *postCompFile;
67 #endif // AEC_DEBUG 67 #endif // AEC_DEBUG
68 // Structures 68 // Structures
69 RingBuffer *farendBuf; 69 RingBuffer *farendBuf;
70 70
71 int lastError;
72
73 AecmCore* aecmCore; 71 AecmCore* aecmCore;
74 } AecMobile; 72 } AecMobile;
75 73
76 // Estimates delay to set the position of the farend buffer read pointer 74 // Estimates delay to set the position of the farend buffer read pointer
77 // (controlled by knownDelay) 75 // (controlled by knownDelay)
78 static int WebRtcAecm_EstBufDelay(AecMobile* aecmInst, short msInSndCardBuf); 76 static int WebRtcAecm_EstBufDelay(AecMobile* aecmInst, short msInSndCardBuf);
79 77
80 // Stuffs the farend buffer if the estimated delay is too large 78 // Stuffs the farend buffer if the estimated delay is too large
81 static int WebRtcAecm_DelayComp(AecMobile* aecmInst); 79 static int WebRtcAecm_DelayComp(AecMobile* aecmInst);
82 80
(...skipping 10 matching lines...) Expand all
93 91
94 aecm->farendBuf = WebRtc_CreateBuffer(kBufSizeSamp, 92 aecm->farendBuf = WebRtc_CreateBuffer(kBufSizeSamp,
95 sizeof(int16_t)); 93 sizeof(int16_t));
96 if (!aecm->farendBuf) 94 if (!aecm->farendBuf)
97 { 95 {
98 WebRtcAecm_Free(aecm); 96 WebRtcAecm_Free(aecm);
99 return NULL; 97 return NULL;
100 } 98 }
101 99
102 aecm->initFlag = 0; 100 aecm->initFlag = 0;
103 aecm->lastError = 0;
104 101
105 #ifdef AEC_DEBUG 102 #ifdef AEC_DEBUG
106 aecm->aecmCore->farFile = fopen("aecFar.pcm","wb"); 103 aecm->aecmCore->farFile = fopen("aecFar.pcm","wb");
107 aecm->aecmCore->nearFile = fopen("aecNear.pcm","wb"); 104 aecm->aecmCore->nearFile = fopen("aecNear.pcm","wb");
108 aecm->aecmCore->outFile = fopen("aecOut.pcm","wb"); 105 aecm->aecmCore->outFile = fopen("aecOut.pcm","wb");
109 //aecm->aecmCore->outLpFile = fopen("aecOutLp.pcm","wb"); 106 //aecm->aecmCore->outLpFile = fopen("aecOutLp.pcm","wb");
110 107
111 aecm->bufFile = fopen("aecBuf.dat", "wb"); 108 aecm->bufFile = fopen("aecBuf.dat", "wb");
112 aecm->delayFile = fopen("aecDelay.dat", "wb"); 109 aecm->delayFile = fopen("aecDelay.dat", "wb");
113 aecm->preCompFile = fopen("preComp.pcm", "wb"); 110 aecm->preCompFile = fopen("preComp.pcm", "wb");
(...skipping 30 matching lines...) Expand all
144 AecMobile* aecm = aecmInst; 141 AecMobile* aecm = aecmInst;
145 AecmConfig aecConfig; 142 AecmConfig aecConfig;
146 143
147 if (aecm == NULL) 144 if (aecm == NULL)
148 { 145 {
149 return -1; 146 return -1;
150 } 147 }
151 148
152 if (sampFreq != 8000 && sampFreq != 16000) 149 if (sampFreq != 8000 && sampFreq != 16000)
153 { 150 {
154 aecm->lastError = AECM_BAD_PARAMETER_ERROR; 151 return AECM_BAD_PARAMETER_ERROR;
155 return -1;
156 } 152 }
157 aecm->sampFreq = sampFreq; 153 aecm->sampFreq = sampFreq;
158 154
159 // Initialize AECM core 155 // Initialize AECM core
160 if (WebRtcAecm_InitCore(aecm->aecmCore, aecm->sampFreq) == -1) 156 if (WebRtcAecm_InitCore(aecm->aecmCore, aecm->sampFreq) == -1)
161 { 157 {
162 aecm->lastError = AECM_UNSPECIFIED_ERROR; 158 return AECM_UNSPECIFIED_ERROR;
163 return -1;
164 } 159 }
165 160
166 // Initialize farend buffer 161 // Initialize farend buffer
167 WebRtc_InitBuffer(aecm->farendBuf); 162 WebRtc_InitBuffer(aecm->farendBuf);
168 163
169 aecm->initFlag = kInitCheck; // indicates that initialization has been done 164 aecm->initFlag = kInitCheck; // indicates that initialization has been done
170 165
171 aecm->delayChange = 1; 166 aecm->delayChange = 1;
172 167
173 aecm->sum = 0; 168 aecm->sum = 0;
(...skipping 10 matching lines...) Expand all
184 aecm->lastDelayDiff = 0; 179 aecm->lastDelayDiff = 0;
185 180
186 memset(&aecm->farendOld[0][0], 0, 160); 181 memset(&aecm->farendOld[0][0], 0, 160);
187 182
188 // Default settings. 183 // Default settings.
189 aecConfig.cngMode = AecmTrue; 184 aecConfig.cngMode = AecmTrue;
190 aecConfig.echoMode = 3; 185 aecConfig.echoMode = 3;
191 186
192 if (WebRtcAecm_set_config(aecm, aecConfig) == -1) 187 if (WebRtcAecm_set_config(aecm, aecConfig) == -1)
193 { 188 {
194 aecm->lastError = AECM_UNSPECIFIED_ERROR; 189 return AECM_UNSPECIFIED_ERROR;
195 return -1;
196 } 190 }
197 191
198 return 0; 192 return 0;
199 } 193 }
200 194
195 // Returns any error that is caused when buffering the
196 // farend signal.
197 int32_t WebRtcAecm_GetBufferFarendError(void *aecmInst, const int16_t *farend,
198 size_t nrOfSamples) {
199 AecMobile* aecm = aecmInst;
200
201 if (aecm == NULL)
202 return -1;
203
204 if (farend == NULL)
205 return AECM_NULL_POINTER_ERROR;
206
207 if (aecm->initFlag != kInitCheck)
208 return AECM_UNINITIALIZED_ERROR;
209
210 if (nrOfSamples != 80 && nrOfSamples != 160)
211 return AECM_BAD_PARAMETER_ERROR;
212
213 return 0;
214 }
215
216
201 int32_t WebRtcAecm_BufferFarend(void *aecmInst, const int16_t *farend, 217 int32_t WebRtcAecm_BufferFarend(void *aecmInst, const int16_t *farend,
202 size_t nrOfSamples) 218 size_t nrOfSamples) {
203 {
204 AecMobile* aecm = aecmInst; 219 AecMobile* aecm = aecmInst;
205 int32_t retVal = 0;
206 220
207 if (aecm == NULL) 221 const int32_t err =
208 { 222 WebRtcAecm_GetBufferFarendError(aecmInst, farend, nrOfSamples);
209 return -1;
210 }
211 223
212 if (farend == NULL) 224 if (err != 0)
213 { 225 return err;
214 aecm->lastError = AECM_NULL_POINTER_ERROR;
215 return -1;
216 }
217 226
218 if (aecm->initFlag != kInitCheck) 227 // TODO(unknown): Is this really a good idea?
219 { 228 if (!aecm->ECstartup)
220 aecm->lastError = AECM_UNINITIALIZED_ERROR; 229 {
221 return -1; 230 WebRtcAecm_DelayComp(aecm);
222 } 231 }
223 232
224 if (nrOfSamples != 80 && nrOfSamples != 160) 233 WebRtc_WriteBuffer(aecm->farendBuf, farend, nrOfSamples);
225 {
226 aecm->lastError = AECM_BAD_PARAMETER_ERROR;
227 return -1;
228 }
229 234
230 // TODO: Is this really a good idea? 235 return 0;
231 if (!aecm->ECstartup)
232 {
233 WebRtcAecm_DelayComp(aecm);
234 }
235
236 WebRtc_WriteBuffer(aecm->farendBuf, farend, nrOfSamples);
237
238 return retVal;
239 } 236 }
240 237
241 int32_t WebRtcAecm_Process(void *aecmInst, const int16_t *nearendNoisy, 238 int32_t WebRtcAecm_Process(void *aecmInst, const int16_t *nearendNoisy,
242 const int16_t *nearendClean, int16_t *out, 239 const int16_t *nearendClean, int16_t *out,
243 size_t nrOfSamples, int16_t msInSndCardBuf) 240 size_t nrOfSamples, int16_t msInSndCardBuf)
244 { 241 {
245 AecMobile* aecm = aecmInst; 242 AecMobile* aecm = aecmInst;
246 int32_t retVal = 0; 243 int32_t retVal = 0;
247 size_t i; 244 size_t i;
248 short nmbrOfFilledBuffers; 245 short nmbrOfFilledBuffers;
249 size_t nBlocks10ms; 246 size_t nBlocks10ms;
250 size_t nFrames; 247 size_t nFrames;
251 #ifdef AEC_DEBUG 248 #ifdef AEC_DEBUG
252 short msInAECBuf; 249 short msInAECBuf;
253 #endif 250 #endif
254 251
255 if (aecm == NULL) 252 if (aecm == NULL)
256 { 253 {
257 return -1; 254 return -1;
258 } 255 }
259 256
260 if (nearendNoisy == NULL) 257 if (nearendNoisy == NULL)
261 { 258 {
262 aecm->lastError = AECM_NULL_POINTER_ERROR; 259 return AECM_NULL_POINTER_ERROR;
263 return -1;
264 } 260 }
265 261
266 if (out == NULL) 262 if (out == NULL)
267 { 263 {
268 aecm->lastError = AECM_NULL_POINTER_ERROR; 264 return AECM_NULL_POINTER_ERROR;
269 return -1;
270 } 265 }
271 266
272 if (aecm->initFlag != kInitCheck) 267 if (aecm->initFlag != kInitCheck)
273 { 268 {
274 aecm->lastError = AECM_UNINITIALIZED_ERROR; 269 return AECM_UNINITIALIZED_ERROR;
275 return -1;
276 } 270 }
277 271
278 if (nrOfSamples != 80 && nrOfSamples != 160) 272 if (nrOfSamples != 80 && nrOfSamples != 160)
279 { 273 {
280 aecm->lastError = AECM_BAD_PARAMETER_ERROR; 274 return AECM_BAD_PARAMETER_ERROR;
281 return -1;
282 } 275 }
283 276
284 if (msInSndCardBuf < 0) 277 if (msInSndCardBuf < 0)
285 { 278 {
286 msInSndCardBuf = 0; 279 msInSndCardBuf = 0;
287 aecm->lastError = AECM_BAD_PARAMETER_WARNING; 280 retVal = AECM_BAD_PARAMETER_WARNING;
288 retVal = -1;
289 } else if (msInSndCardBuf > 500) 281 } else if (msInSndCardBuf > 500)
290 { 282 {
291 msInSndCardBuf = 500; 283 msInSndCardBuf = 500;
292 aecm->lastError = AECM_BAD_PARAMETER_WARNING; 284 retVal = AECM_BAD_PARAMETER_WARNING;
293 retVal = -1;
294 } 285 }
295 msInSndCardBuf += 10; 286 msInSndCardBuf += 10;
296 aecm->msInSndCardBuf = msInSndCardBuf; 287 aecm->msInSndCardBuf = msInSndCardBuf;
297 288
298 nFrames = nrOfSamples / FRAME_LEN; 289 nFrames = nrOfSamples / FRAME_LEN;
299 nBlocks10ms = nFrames / aecm->aecmCore->mult; 290 nBlocks10ms = nFrames / aecm->aecmCore->mult;
300 291
301 if (aecm->ECstartup) 292 if (aecm->ECstartup)
302 { 293 {
303 if (nearendClean == NULL) 294 if (nearendClean == NULL)
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 { 437 {
447 AecMobile* aecm = aecmInst; 438 AecMobile* aecm = aecmInst;
448 439
449 if (aecm == NULL) 440 if (aecm == NULL)
450 { 441 {
451 return -1; 442 return -1;
452 } 443 }
453 444
454 if (aecm->initFlag != kInitCheck) 445 if (aecm->initFlag != kInitCheck)
455 { 446 {
456 aecm->lastError = AECM_UNINITIALIZED_ERROR; 447 return AECM_UNINITIALIZED_ERROR;
457 return -1;
458 } 448 }
459 449
460 if (config.cngMode != AecmFalse && config.cngMode != AecmTrue) 450 if (config.cngMode != AecmFalse && config.cngMode != AecmTrue)
461 { 451 {
462 aecm->lastError = AECM_BAD_PARAMETER_ERROR; 452 return AECM_BAD_PARAMETER_ERROR;
463 return -1;
464 } 453 }
465 aecm->aecmCore->cngMode = config.cngMode; 454 aecm->aecmCore->cngMode = config.cngMode;
466 455
467 if (config.echoMode < 0 || config.echoMode > 4) 456 if (config.echoMode < 0 || config.echoMode > 4)
468 { 457 {
469 aecm->lastError = AECM_BAD_PARAMETER_ERROR; 458 return AECM_BAD_PARAMETER_ERROR;
470 return -1;
471 } 459 }
472 aecm->echoMode = config.echoMode; 460 aecm->echoMode = config.echoMode;
473 461
474 if (aecm->echoMode == 0) 462 if (aecm->echoMode == 0)
475 { 463 {
476 aecm->aecmCore->supGain = SUPGAIN_DEFAULT >> 3; 464 aecm->aecmCore->supGain = SUPGAIN_DEFAULT >> 3;
477 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT >> 3; 465 aecm->aecmCore->supGainOld = SUPGAIN_DEFAULT >> 3;
478 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A >> 3; 466 aecm->aecmCore->supGainErrParamA = SUPGAIN_ERROR_PARAM_A >> 3;
479 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D >> 3; 467 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D >> 3;
480 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A >> 3) 468 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A >> 3)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D << 1; 505 aecm->aecmCore->supGainErrParamD = SUPGAIN_ERROR_PARAM_D << 1;
518 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A << 1) 506 aecm->aecmCore->supGainErrParamDiffAB = (SUPGAIN_ERROR_PARAM_A << 1)
519 - (SUPGAIN_ERROR_PARAM_B << 1); 507 - (SUPGAIN_ERROR_PARAM_B << 1);
520 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B << 1) 508 aecm->aecmCore->supGainErrParamDiffBD = (SUPGAIN_ERROR_PARAM_B << 1)
521 - (SUPGAIN_ERROR_PARAM_D << 1); 509 - (SUPGAIN_ERROR_PARAM_D << 1);
522 } 510 }
523 511
524 return 0; 512 return 0;
525 } 513 }
526 514
527 int32_t WebRtcAecm_get_config(void *aecmInst, AecmConfig *config)
528 {
529 AecMobile* aecm = aecmInst;
530
531 if (aecm == NULL)
532 {
533 return -1;
534 }
535
536 if (config == NULL)
537 {
538 aecm->lastError = AECM_NULL_POINTER_ERROR;
539 return -1;
540 }
541
542 if (aecm->initFlag != kInitCheck)
543 {
544 aecm->lastError = AECM_UNINITIALIZED_ERROR;
545 return -1;
546 }
547
548 config->cngMode = aecm->aecmCore->cngMode;
549 config->echoMode = aecm->echoMode;
550
551 return 0;
552 }
553
554 int32_t WebRtcAecm_InitEchoPath(void* aecmInst, 515 int32_t WebRtcAecm_InitEchoPath(void* aecmInst,
555 const void* echo_path, 516 const void* echo_path,
556 size_t size_bytes) 517 size_t size_bytes)
557 { 518 {
558 AecMobile* aecm = aecmInst; 519 AecMobile* aecm = aecmInst;
559 const int16_t* echo_path_ptr = echo_path; 520 const int16_t* echo_path_ptr = echo_path;
560 521
561 if (aecmInst == NULL) { 522 if (aecmInst == NULL) {
562 return -1; 523 return -1;
563 } 524 }
564 if (echo_path == NULL) { 525 if (echo_path == NULL) {
565 aecm->lastError = AECM_NULL_POINTER_ERROR; 526 return AECM_NULL_POINTER_ERROR;
566 return -1;
567 } 527 }
568 if (size_bytes != WebRtcAecm_echo_path_size_bytes()) 528 if (size_bytes != WebRtcAecm_echo_path_size_bytes())
569 { 529 {
570 // Input channel size does not match the size of AECM 530 // Input channel size does not match the size of AECM
571 aecm->lastError = AECM_BAD_PARAMETER_ERROR; 531 return AECM_BAD_PARAMETER_ERROR;
572 return -1;
573 } 532 }
574 if (aecm->initFlag != kInitCheck) 533 if (aecm->initFlag != kInitCheck)
575 { 534 {
576 aecm->lastError = AECM_UNINITIALIZED_ERROR; 535 return AECM_UNINITIALIZED_ERROR;
577 return -1;
578 } 536 }
579 537
580 WebRtcAecm_InitEchoPathCore(aecm->aecmCore, echo_path_ptr); 538 WebRtcAecm_InitEchoPathCore(aecm->aecmCore, echo_path_ptr);
581 539
582 return 0; 540 return 0;
583 } 541 }
584 542
585 int32_t WebRtcAecm_GetEchoPath(void* aecmInst, 543 int32_t WebRtcAecm_GetEchoPath(void* aecmInst,
586 void* echo_path, 544 void* echo_path,
587 size_t size_bytes) 545 size_t size_bytes)
588 { 546 {
589 AecMobile* aecm = aecmInst; 547 AecMobile* aecm = aecmInst;
590 int16_t* echo_path_ptr = echo_path; 548 int16_t* echo_path_ptr = echo_path;
591 549
592 if (aecmInst == NULL) { 550 if (aecmInst == NULL) {
593 return -1; 551 return -1;
594 } 552 }
595 if (echo_path == NULL) { 553 if (echo_path == NULL) {
596 aecm->lastError = AECM_NULL_POINTER_ERROR; 554 return AECM_NULL_POINTER_ERROR;
597 return -1;
598 } 555 }
599 if (size_bytes != WebRtcAecm_echo_path_size_bytes()) 556 if (size_bytes != WebRtcAecm_echo_path_size_bytes())
600 { 557 {
601 // Input channel size does not match the size of AECM 558 // Input channel size does not match the size of AECM
602 aecm->lastError = AECM_BAD_PARAMETER_ERROR; 559 return AECM_BAD_PARAMETER_ERROR;
603 return -1;
604 } 560 }
605 if (aecm->initFlag != kInitCheck) 561 if (aecm->initFlag != kInitCheck)
606 { 562 {
607 aecm->lastError = AECM_UNINITIALIZED_ERROR; 563 return AECM_UNINITIALIZED_ERROR;
608 return -1;
609 } 564 }
610 565
611 memcpy(echo_path_ptr, aecm->aecmCore->channelStored, size_bytes); 566 memcpy(echo_path_ptr, aecm->aecmCore->channelStored, size_bytes);
612 return 0; 567 return 0;
613 } 568 }
614 569
615 size_t WebRtcAecm_echo_path_size_bytes() 570 size_t WebRtcAecm_echo_path_size_bytes()
616 { 571 {
617 return (PART_LEN1 * sizeof(int16_t)); 572 return (PART_LEN1 * sizeof(int16_t));
618 } 573 }
619 574
620 int32_t WebRtcAecm_get_error_code(void *aecmInst)
621 {
622 AecMobile* aecm = aecmInst;
623
624 if (aecm == NULL)
625 {
626 return -1;
627 }
628
629 return aecm->lastError;
630 }
631 575
632 static int WebRtcAecm_EstBufDelay(AecMobile* aecm, short msInSndCardBuf) { 576 static int WebRtcAecm_EstBufDelay(AecMobile* aecm, short msInSndCardBuf) {
633 short delayNew, nSampSndCard; 577 short delayNew, nSampSndCard;
634 short nSampFar = (short) WebRtc_available_read(aecm->farendBuf); 578 short nSampFar = (short) WebRtc_available_read(aecm->farendBuf);
635 short diff; 579 short diff;
636 580
637 nSampSndCard = msInSndCardBuf * kSampMsNb * aecm->aecmCore->mult; 581 nSampSndCard = msInSndCardBuf * kSampMsNb * aecm->aecmCore->mult;
638 582
639 delayNew = nSampSndCard - nSampFar; 583 delayNew = nSampSndCard - nSampFar;
640 584
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 nSampAdd = (int)(WEBRTC_SPL_MAX(((nSampSndCard >> 1) - nSampFar), 637 nSampAdd = (int)(WEBRTC_SPL_MAX(((nSampSndCard >> 1) - nSampFar),
694 FRAME_LEN)); 638 FRAME_LEN));
695 nSampAdd = WEBRTC_SPL_MIN(nSampAdd, maxStuffSamp); 639 nSampAdd = WEBRTC_SPL_MIN(nSampAdd, maxStuffSamp);
696 640
697 WebRtc_MoveReadPtr(aecm->farendBuf, -nSampAdd); 641 WebRtc_MoveReadPtr(aecm->farendBuf, -nSampAdd);
698 aecm->delayChange = 1; // the delay needs to be updated 642 aecm->delayChange = 1; // the delay needs to be updated
699 } 643 }
700 644
701 return 0; 645 return 0;
702 } 646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698