Lines Matching refs:st
128 void speex_echo_get_residual(SpeexEchoState *st, spx_word32_t *Yout, int len);
410 SpeexEchoState *st = (SpeexEchoState *)speex_alloc(sizeof(SpeexEchoState)); in speex_echo_state_init_mc() local
412 st->K = nb_speakers; in speex_echo_state_init_mc()
413 st->C = nb_mic; in speex_echo_state_init_mc()
414 C=st->C; in speex_echo_state_init_mc()
415 K=st->K; in speex_echo_state_init_mc()
424 st->frame_size = frame_size; in speex_echo_state_init_mc()
425 st->window_size = 2*frame_size; in speex_echo_state_init_mc()
426 N = st->window_size; in speex_echo_state_init_mc()
427 M = st->M = (filter_length+st->frame_size-1)/frame_size; in speex_echo_state_init_mc()
428 st->cancel_count=0; in speex_echo_state_init_mc()
429 st->sum_adapt = 0; in speex_echo_state_init_mc()
430 st->saturated = 0; in speex_echo_state_init_mc()
431 st->screwed_up = 0; in speex_echo_state_init_mc()
433 st->sampling_rate = 8000; in speex_echo_state_init_mc()
434 st->spec_average = DIV32_16(SHL32(EXTEND32(st->frame_size), 15), st->sampling_rate); in speex_echo_state_init_mc()
436 st->beta0 = DIV32_16(SHL32(EXTEND32(st->frame_size), 16), st->sampling_rate); in speex_echo_state_init_mc()
437 st->beta_max = DIV32_16(SHL32(EXTEND32(st->frame_size), 14), st->sampling_rate); in speex_echo_state_init_mc()
439 st->beta0 = (2.0f*st->frame_size)/st->sampling_rate; in speex_echo_state_init_mc()
440 st->beta_max = (.5f*st->frame_size)/st->sampling_rate; in speex_echo_state_init_mc()
442 st->leak_estimate = 0; in speex_echo_state_init_mc()
444 st->fft_table = spx_fft_init(N); in speex_echo_state_init_mc()
446 st->e = (spx_word16_t*)speex_alloc(C*N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
447 st->x = (spx_word16_t*)speex_alloc(K*N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
448 st->input = (spx_word16_t*)speex_alloc(C*st->frame_size*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
449 st->y = (spx_word16_t*)speex_alloc(C*N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
450 st->last_y = (spx_word16_t*)speex_alloc(C*N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
451 st->Yf = (spx_word32_t*)speex_alloc((st->frame_size+1)*sizeof(spx_word32_t)); in speex_echo_state_init_mc()
452 st->Rf = (spx_word32_t*)speex_alloc((st->frame_size+1)*sizeof(spx_word32_t)); in speex_echo_state_init_mc()
453 st->Xf = (spx_word32_t*)speex_alloc((st->frame_size+1)*sizeof(spx_word32_t)); in speex_echo_state_init_mc()
454 st->Yh = (spx_word32_t*)speex_alloc((st->frame_size+1)*sizeof(spx_word32_t)); in speex_echo_state_init_mc()
455 st->Eh = (spx_word32_t*)speex_alloc((st->frame_size+1)*sizeof(spx_word32_t)); in speex_echo_state_init_mc()
457 st->X = (spx_word16_t*)speex_alloc(K*(M+1)*N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
458 st->Y = (spx_word16_t*)speex_alloc(C*N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
459 st->E = (spx_word16_t*)speex_alloc(C*N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
460 st->W = (spx_word32_t*)speex_alloc(C*K*M*N*sizeof(spx_word32_t)); in speex_echo_state_init_mc()
462 st->foreground = (spx_word16_t*)speex_alloc(M*N*C*K*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
464 st->PHI = (spx_word32_t*)speex_alloc(N*sizeof(spx_word32_t)); in speex_echo_state_init_mc()
465 st->power = (spx_word32_t*)speex_alloc((frame_size+1)*sizeof(spx_word32_t)); in speex_echo_state_init_mc()
466 st->power_1 = (spx_float_t*)speex_alloc((frame_size+1)*sizeof(spx_float_t)); in speex_echo_state_init_mc()
467 st->window = (spx_word16_t*)speex_alloc(N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
468 st->prop = (spx_word16_t*)speex_alloc(M*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
469 st->wtmp = (spx_word16_t*)speex_alloc(N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
471 st->wtmp2 = (spx_word16_t*)speex_alloc(N*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
474 st->window[i] = (16383-SHL16(spx_cos(DIV32_16(MULT16_16(25736,i<<1),N)),1)); in speex_echo_state_init_mc()
475 st->window[N-i-1] = st->window[i]; in speex_echo_state_init_mc()
479 st->window[i] = .5-.5*cos(2*M_PI*i/N); in speex_echo_state_init_mc()
481 for (i=0;i<=st->frame_size;i++) in speex_echo_state_init_mc()
482 st->power_1[i] = FLOAT_ONE; in speex_echo_state_init_mc()
484 st->W[i] = 0; in speex_echo_state_init_mc()
489 st->prop[0] = QCONST16(.7, 15); in speex_echo_state_init_mc()
490 sum = EXTEND32(st->prop[0]); in speex_echo_state_init_mc()
493 st->prop[i] = MULT16_16_Q15(st->prop[i-1], decay); in speex_echo_state_init_mc()
494 sum = ADD32(sum, EXTEND32(st->prop[i])); in speex_echo_state_init_mc()
498 st->prop[i] = DIV32(MULT16_16(QCONST16(.8f,15), st->prop[i]),sum); in speex_echo_state_init_mc()
502 st->memX = (spx_word16_t*)speex_alloc(K*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
503 st->memD = (spx_word16_t*)speex_alloc(C*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
504 st->memE = (spx_word16_t*)speex_alloc(C*sizeof(spx_word16_t)); in speex_echo_state_init_mc()
505 st->preemph = QCONST16(.9,15); in speex_echo_state_init_mc()
506 if (st->sampling_rate<12000) in speex_echo_state_init_mc()
507 st->notch_radius = QCONST16(.9, 15); in speex_echo_state_init_mc()
508 else if (st->sampling_rate<24000) in speex_echo_state_init_mc()
509 st->notch_radius = QCONST16(.982, 15); in speex_echo_state_init_mc()
511 st->notch_radius = QCONST16(.992, 15); in speex_echo_state_init_mc()
513 st->notch_mem = (spx_mem_t*)speex_alloc(2*C*sizeof(spx_mem_t)); in speex_echo_state_init_mc()
514 st->adapted = 0; in speex_echo_state_init_mc()
515 st->Pey = st->Pyy = FLOAT_ONE; in speex_echo_state_init_mc()
518 st->Davg1 = st->Davg2 = 0; in speex_echo_state_init_mc()
519 st->Dvar1 = st->Dvar2 = FLOAT_ZERO; in speex_echo_state_init_mc()
522 … st->play_buf = (spx_int16_t*)speex_alloc(K*(PLAYBACK_DELAY+1)*st->frame_size*sizeof(spx_int16_t)); in speex_echo_state_init_mc()
523 st->play_buf_pos = PLAYBACK_DELAY*st->frame_size; in speex_echo_state_init_mc()
524 st->play_buf_started = 0; in speex_echo_state_init_mc()
526 return st; in speex_echo_state_init_mc()
530 EXPORT void speex_echo_state_reset(SpeexEchoState *st) in speex_echo_state_reset() argument
533 st->cancel_count=0; in speex_echo_state_reset()
534 st->screwed_up = 0; in speex_echo_state_reset()
535 N = st->window_size; in speex_echo_state_reset()
536 M = st->M; in speex_echo_state_reset()
537 C=st->C; in speex_echo_state_reset()
538 K=st->K; in speex_echo_state_reset()
540 st->W[i] = 0; in speex_echo_state_reset()
543 st->foreground[i] = 0; in speex_echo_state_reset()
546 st->X[i] = 0; in speex_echo_state_reset()
547 for (i=0;i<=st->frame_size;i++) in speex_echo_state_reset()
549 st->power[i] = 0; in speex_echo_state_reset()
550 st->power_1[i] = FLOAT_ONE; in speex_echo_state_reset()
551 st->Eh[i] = 0; in speex_echo_state_reset()
552 st->Yh[i] = 0; in speex_echo_state_reset()
554 for (i=0;i<st->frame_size;i++) in speex_echo_state_reset()
556 st->last_y[i] = 0; in speex_echo_state_reset()
560 st->E[i] = 0; in speex_echo_state_reset()
564 st->x[i] = 0; in speex_echo_state_reset()
567 st->notch_mem[i] = 0; in speex_echo_state_reset()
569 st->memD[i]=st->memE[i]=0; in speex_echo_state_reset()
571 st->memX[i]=0; in speex_echo_state_reset()
573 st->saturated = 0; in speex_echo_state_reset()
574 st->adapted = 0; in speex_echo_state_reset()
575 st->sum_adapt = 0; in speex_echo_state_reset()
576 st->Pey = st->Pyy = FLOAT_ONE; in speex_echo_state_reset()
578 st->Davg1 = st->Davg2 = 0; in speex_echo_state_reset()
579 st->Dvar1 = st->Dvar2 = FLOAT_ZERO; in speex_echo_state_reset()
581 for (i=0;i<3*st->frame_size;i++) in speex_echo_state_reset()
582 st->play_buf[i] = 0; in speex_echo_state_reset()
583 st->play_buf_pos = PLAYBACK_DELAY*st->frame_size; in speex_echo_state_reset()
584 st->play_buf_started = 0; in speex_echo_state_reset()
589 EXPORT void speex_echo_state_destroy(SpeexEchoState *st) in speex_echo_state_destroy() argument
591 spx_fft_destroy(st->fft_table); in speex_echo_state_destroy()
593 speex_free(st->e); in speex_echo_state_destroy()
594 speex_free(st->x); in speex_echo_state_destroy()
595 speex_free(st->input); in speex_echo_state_destroy()
596 speex_free(st->y); in speex_echo_state_destroy()
597 speex_free(st->last_y); in speex_echo_state_destroy()
598 speex_free(st->Yf); in speex_echo_state_destroy()
599 speex_free(st->Rf); in speex_echo_state_destroy()
600 speex_free(st->Xf); in speex_echo_state_destroy()
601 speex_free(st->Yh); in speex_echo_state_destroy()
602 speex_free(st->Eh); in speex_echo_state_destroy()
604 speex_free(st->X); in speex_echo_state_destroy()
605 speex_free(st->Y); in speex_echo_state_destroy()
606 speex_free(st->E); in speex_echo_state_destroy()
607 speex_free(st->W); in speex_echo_state_destroy()
609 speex_free(st->foreground); in speex_echo_state_destroy()
611 speex_free(st->PHI); in speex_echo_state_destroy()
612 speex_free(st->power); in speex_echo_state_destroy()
613 speex_free(st->power_1); in speex_echo_state_destroy()
614 speex_free(st->window); in speex_echo_state_destroy()
615 speex_free(st->prop); in speex_echo_state_destroy()
616 speex_free(st->wtmp); in speex_echo_state_destroy()
618 speex_free(st->wtmp2); in speex_echo_state_destroy()
620 speex_free(st->memX); in speex_echo_state_destroy()
621 speex_free(st->memD); in speex_echo_state_destroy()
622 speex_free(st->memE); in speex_echo_state_destroy()
623 speex_free(st->notch_mem); in speex_echo_state_destroy()
625 speex_free(st->play_buf); in speex_echo_state_destroy()
626 speex_free(st); in speex_echo_state_destroy()
636 EXPORT void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out) in speex_echo_capture() argument
640 st->play_buf_started = 1; in speex_echo_capture()
641 if (st->play_buf_pos>=st->frame_size) in speex_echo_capture()
643 speex_echo_cancellation(st, rec, st->play_buf, out); in speex_echo_capture()
644 st->play_buf_pos -= st->frame_size; in speex_echo_capture()
645 for (i=0;i<st->play_buf_pos;i++) in speex_echo_capture()
646 st->play_buf[i] = st->play_buf[i+st->frame_size]; in speex_echo_capture()
649 if (st->play_buf_pos!=0) in speex_echo_capture()
652 st->play_buf_pos = 0; in speex_echo_capture()
654 for (i=0;i<st->frame_size;i++) in speex_echo_capture()
659 EXPORT void speex_echo_playback(SpeexEchoState *st, const spx_int16_t *play) in speex_echo_playback() argument
662 if (!st->play_buf_started) in speex_echo_playback()
667 if (st->play_buf_pos<=PLAYBACK_DELAY*st->frame_size) in speex_echo_playback()
670 for (i=0;i<st->frame_size;i++) in speex_echo_playback()
671 st->play_buf[st->play_buf_pos+i] = play[i]; in speex_echo_playback()
672 st->play_buf_pos += st->frame_size; in speex_echo_playback()
673 if (st->play_buf_pos <= (PLAYBACK_DELAY-1)*st->frame_size) in speex_echo_playback()
676 for (i=0;i<st->frame_size;i++) in speex_echo_playback()
677 st->play_buf[st->play_buf_pos+i] = play[i]; in speex_echo_playback()
678 st->play_buf_pos += st->frame_size; in speex_echo_playback()
686 EXPORT void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *in, const spx_int16_t *far_end… in speex_echo_cancel() argument
688 speex_echo_cancellation(st, in, far_end, out); in speex_echo_cancel()
692 EXPORT void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *in, const spx_int16_t *f… in speex_echo_cancellation() argument
708 N = st->window_size; in speex_echo_cancellation()
709 M = st->M; in speex_echo_cancellation()
710 C = st->C; in speex_echo_cancellation()
711 K = st->K; in speex_echo_cancellation()
713 st->cancel_count++; in speex_echo_cancellation()
725 …filter_dc_notch16(in+chan, st->notch_radius, st->input+chan*st->frame_size, st->frame_size, st->no… in speex_echo_cancellation()
728 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
732 …tmp32 = SUB32(EXTEND32(st->input[chan*st->frame_size+i]), EXTEND32(MULT16_16_P15(st->preemph, st->… in speex_echo_cancellation()
737 if (st->saturated == 0) in speex_echo_cancellation()
738 st->saturated = 1; in speex_echo_cancellation()
743 if (st->saturated == 0) in speex_echo_cancellation()
744 st->saturated = 1; in speex_echo_cancellation()
747 st->memD[chan] = st->input[chan*st->frame_size+i]; in speex_echo_cancellation()
748 st->input[chan*st->frame_size+i] = EXTRACT16(tmp32); in speex_echo_cancellation()
754 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
757 st->x[speak*N+i] = st->x[speak*N+i+st->frame_size]; in speex_echo_cancellation()
758 …tmp32 = SUB32(EXTEND32(far_end[i*K+speak]), EXTEND32(MULT16_16_P15(st->preemph, st->memX[speak]))); in speex_echo_cancellation()
764 st->saturated = M+1; in speex_echo_cancellation()
769 st->saturated = M+1; in speex_echo_cancellation()
772 st->x[speak*N+i+st->frame_size] = EXTRACT16(tmp32); in speex_echo_cancellation()
773 st->memX[speak] = far_end[i*K+speak]; in speex_echo_cancellation()
783 st->X[(j+1)*N*K+speak*N+i] = st->X[j*N*K+speak*N+i]; in speex_echo_cancellation()
786 spx_fft(st->fft_table, st->x+speak*N, &st->X[speak*N]); in speex_echo_cancellation()
792 … Sxx += mdf_inner_prod(st->x+speak*N+st->frame_size, st->x+speak*N+st->frame_size, st->frame_size); in speex_echo_cancellation()
793 power_spectrum_accum(st->X+speak*N, st->Xf, N); in speex_echo_cancellation()
801 spectral_mul_accum16(st->X, st->foreground+chan*N*K*M, st->Y+chan*N, N, M*K); in speex_echo_cancellation()
802 spx_ifft(st->fft_table, st->Y+chan*N, st->e+chan*N); in speex_echo_cancellation()
803 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
804 st->e[chan*N+i] = SUB16(st->input[chan*st->frame_size+i], st->e[chan*N+i+st->frame_size]); in speex_echo_cancellation()
805 Sff += mdf_inner_prod(st->e+chan*N, st->e+chan*N, st->frame_size); in speex_echo_cancellation()
811 if (st->adapted) in speex_echo_cancellation()
812 mdf_adjust_prop (st->W, N, M, C*K, st->prop); in speex_echo_cancellation()
814 if (st->saturated == 0) in speex_echo_cancellation()
822 …weighted_spectral_mul_conj(st->power_1, FLOAT_SHL(PSEUDOFLOAT(st->prop[j]),-15), &st->X[(j+1)*N*K+… in speex_echo_cancellation()
824 st->W[chan*N*K*M + j*N*K + speak*N + i] += st->PHI[i]; in speex_echo_cancellation()
829 st->saturated--; in speex_echo_cancellation()
842 if (j==0 || st->cancel_count%(M-1) == j-1) in speex_echo_cancellation()
846 … st->wtmp2[i] = EXTRACT16(PSHR32(st->W[chan*N*K*M + j*N*K + speak*N + i],NORMALIZE_SCALEDOWN+16)); in speex_echo_cancellation()
847 spx_ifft(st->fft_table, st->wtmp2, st->wtmp); in speex_echo_cancellation()
848 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
850 st->wtmp[i]=0; in speex_echo_cancellation()
852 for (i=st->frame_size;i<N;i++) in speex_echo_cancellation()
854 st->wtmp[i]=SHL16(st->wtmp[i],NORMALIZE_SCALEUP); in speex_echo_cancellation()
856 spx_fft(st->fft_table, st->wtmp, st->wtmp2); in speex_echo_cancellation()
859 …st->W[chan*N*K*M + j*N*K + speak*N + i] -= SHL32(EXTEND32(st->wtmp2[i]),16+NORMALIZE_SCALEDOWN-NOR… in speex_echo_cancellation()
861 spx_ifft(st->fft_table, &st->W[chan*N*K*M + j*N*K + speak*N], st->wtmp); in speex_echo_cancellation()
862 for (i=st->frame_size;i<N;i++) in speex_echo_cancellation()
864 st->wtmp[i]=0; in speex_echo_cancellation()
866 spx_fft(st->fft_table, st->wtmp, &st->W[chan*N*K*M + j*N*K + speak*N]); in speex_echo_cancellation()
874 for (i=0;i<=st->frame_size;i++) in speex_echo_cancellation()
875 st->Rf[i] = st->Yf[i] = st->Xf[i] = 0; in speex_echo_cancellation()
883 spectral_mul_accum(st->X, st->W+chan*N*K*M, st->Y+chan*N, N, M*K); in speex_echo_cancellation()
884 spx_ifft(st->fft_table, st->Y+chan*N, st->y+chan*N); in speex_echo_cancellation()
885 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
886 st->e[chan*N+i] = SUB16(st->e[chan*N+i+st->frame_size], st->y[chan*N+i+st->frame_size]); in speex_echo_cancellation()
887 Dbf += 10+mdf_inner_prod(st->e+chan*N, st->e+chan*N, st->frame_size); in speex_echo_cancellation()
888 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
889 st->e[chan*N+i] = SUB16(st->input[chan*st->frame_size+i], st->y[chan*N+i+st->frame_size]); in speex_echo_cancellation()
890 See += mdf_inner_prod(st->e+chan*N, st->e+chan*N, st->frame_size); in speex_echo_cancellation()
902 …st->Davg1 = ADD32(MULT16_32_Q15(QCONST16(.6f,15),st->Davg1), MULT16_32_Q15(QCONST16(.4f,15),SUB32(… in speex_echo_cancellation()
903 …st->Davg2 = ADD32(MULT16_32_Q15(QCONST16(.85f,15),st->Davg2), MULT16_32_Q15(QCONST16(.15f,15),SUB3… in speex_echo_cancellation()
904 …st->Dvar1 = FLOAT_ADD(FLOAT_MULT(VAR1_SMOOTH, st->Dvar1), FLOAT_MUL32U(MULT16_32_Q15(QCONST16(.4f,… in speex_echo_cancellation()
905 …st->Dvar2 = FLOAT_ADD(FLOAT_MULT(VAR2_SMOOTH, st->Dvar2), FLOAT_MUL32U(MULT16_32_Q15(QCONST16(.15f… in speex_echo_cancellation()
919 … else if (FLOAT_GT(FLOAT_MUL32U(st->Davg1, ABS32(st->Davg1)), FLOAT_MULT(VAR1_UPDATE,(st->Dvar1)))) in speex_echo_cancellation()
921 … else if (FLOAT_GT(FLOAT_MUL32U(st->Davg2, ABS32(st->Davg2)), FLOAT_MULT(VAR2_UPDATE,(st->Dvar2)))) in speex_echo_cancellation()
927 st->Davg1 = st->Davg2 = 0; in speex_echo_cancellation()
928 st->Dvar1 = st->Dvar2 = FLOAT_ZERO; in speex_echo_cancellation()
931 st->foreground[i] = EXTRACT16(PSHR32(st->W[i],16)); in speex_echo_cancellation()
934 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
935 …st->e[chan*N+i+st->frame_size] = MULT16_16_Q15(st->window[i+st->frame_size],st->e[chan*N+i+st->fra… in speex_echo_cancellation()
941 …if (FLOAT_GT(FLOAT_MUL32U(NEG32(st->Davg1), ABS32(st->Davg1)), FLOAT_MULT(VAR_BACKTRACK,st->Dvar1)… in speex_echo_cancellation()
943 …if (FLOAT_GT(FLOAT_MUL32U(NEG32(st->Davg2), ABS32(st->Davg2)), FLOAT_MULT(VAR_BACKTRACK,st->Dvar2)… in speex_echo_cancellation()
949 st->W[i] = SHL32(EXTEND32(st->foreground[i]),16); in speex_echo_cancellation()
953 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
954 st->y[chan*N+i+st->frame_size] = st->e[chan*N+i+st->frame_size]; in speex_echo_cancellation()
955 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
956 … st->e[chan*N+i] = SUB16(st->input[chan*st->frame_size+i], st->y[chan*N+i+st->frame_size]); in speex_echo_cancellation()
959 st->Davg1 = st->Davg2 = 0; in speex_echo_cancellation()
960 st->Dvar1 = st->Dvar2 = FLOAT_ZERO; in speex_echo_cancellation()
969 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
973 …tmp_out = SUB32(EXTEND32(st->input[chan*st->frame_size+i]), EXTEND32(st->e[chan*N+i+st->frame_size… in speex_echo_cancellation()
975 …tmp_out = SUB32(EXTEND32(st->input[chan*st->frame_size+i]), EXTEND32(st->y[chan*N+i+st->frame_size… in speex_echo_cancellation()
977 tmp_out = ADD32(tmp_out, EXTEND32(MULT16_16_P15(st->preemph, st->memE[chan]))); in speex_echo_cancellation()
981 if (st->saturated == 0) in speex_echo_cancellation()
982 st->saturated = 1; in speex_echo_cancellation()
985 st->memE[chan] = tmp_out; in speex_echo_cancellation()
989 dump_audio(in, far_end, out, st->frame_size); in speex_echo_cancellation()
993 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
995 st->e[chan*N+i+st->frame_size] = st->e[chan*N+i]; in speex_echo_cancellation()
996 st->e[chan*N+i] = 0; in speex_echo_cancellation()
1001 … Sey += mdf_inner_prod(st->e+chan*N+st->frame_size, st->y+chan*N+st->frame_size, st->frame_size); in speex_echo_cancellation()
1002 … Syy += mdf_inner_prod(st->y+chan*N+st->frame_size, st->y+chan*N+st->frame_size, st->frame_size); in speex_echo_cancellation()
1003 …Sdd += mdf_inner_prod(st->input+chan*st->frame_size, st->input+chan*st->frame_size, st->frame_size… in speex_echo_cancellation()
1006 spx_fft(st->fft_table, st->e+chan*N, st->E+chan*N); in speex_echo_cancellation()
1007 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
1008 st->y[i+chan*N] = 0; in speex_echo_cancellation()
1009 spx_fft(st->fft_table, st->y+chan*N, st->Y+chan*N); in speex_echo_cancellation()
1012 power_spectrum_accum(st->E+chan*N, st->Rf, N); in speex_echo_cancellation()
1013 power_spectrum_accum(st->Y+chan*N, st->Yf, N); in speex_echo_cancellation()
1027 st->screwed_up += 50; in speex_echo_cancellation()
1028 for (i=0;i<st->frame_size*C;i++) in speex_echo_cancellation()
1033 st->screwed_up++; in speex_echo_cancellation()
1036 st->screwed_up=0; in speex_echo_cancellation()
1038 if (st->screwed_up>=50) in speex_echo_cancellation()
1041 speex_echo_state_reset(st); in speex_echo_cancellation()
1050 … Sxx += mdf_inner_prod(st->x+speak*N+st->frame_size, st->x+speak*N+st->frame_size, st->frame_size); in speex_echo_cancellation()
1051 power_spectrum_accum(st->X+speak*N, st->Xf, N); in speex_echo_cancellation()
1056 for (j=0;j<=st->frame_size;j++) in speex_echo_cancellation()
1057 st->power[j] = MULT16_32_Q15(ss_1,st->power[j]) + 1 + MULT16_32_Q15(ss,st->Xf[j]); in speex_echo_cancellation()
1060 for (j=st->frame_size;j>=0;j--) in speex_echo_cancellation()
1063 Eh = PSEUDOFLOAT(st->Rf[j] - st->Eh[j]); in speex_echo_cancellation()
1064 Yh = PSEUDOFLOAT(st->Yf[j] - st->Yh[j]); in speex_echo_cancellation()
1068 …st->Eh[j] = MAC16_32_Q15(MULT16_32_Q15(SUB16(32767,st->spec_average),st->Eh[j]), st->spec_average,… in speex_echo_cancellation()
1069 …st->Yh[j] = MAC16_32_Q15(MULT16_32_Q15(SUB16(32767,st->spec_average),st->Yh[j]), st->spec_average,… in speex_echo_cancellation()
1071 st->Eh[j] = (1-st->spec_average)*st->Eh[j] + st->spec_average*st->Rf[j]; in speex_echo_cancellation()
1072 st->Yh[j] = (1-st->spec_average)*st->Yh[j] + st->spec_average*st->Yf[j]; in speex_echo_cancellation()
1080 tmp32 = MULT16_32_Q15(st->beta0,Syy); in speex_echo_cancellation()
1081 if (tmp32 > MULT16_32_Q15(st->beta_max,See)) in speex_echo_cancellation()
1082 tmp32 = MULT16_32_Q15(st->beta_max,See); in speex_echo_cancellation()
1086 st->Pey = FLOAT_ADD(FLOAT_MULT(alpha_1,st->Pey) , FLOAT_MULT(alpha,Pey)); in speex_echo_cancellation()
1087 st->Pyy = FLOAT_ADD(FLOAT_MULT(alpha_1,st->Pyy) , FLOAT_MULT(alpha,Pyy)); in speex_echo_cancellation()
1088 if (FLOAT_LT(st->Pyy, FLOAT_ONE)) in speex_echo_cancellation()
1089 st->Pyy = FLOAT_ONE; in speex_echo_cancellation()
1091 if (FLOAT_LT(st->Pey, FLOAT_MULT(MIN_LEAK,st->Pyy))) in speex_echo_cancellation()
1092 st->Pey = FLOAT_MULT(MIN_LEAK,st->Pyy); in speex_echo_cancellation()
1093 if (FLOAT_GT(st->Pey, st->Pyy)) in speex_echo_cancellation()
1094 st->Pey = st->Pyy; in speex_echo_cancellation()
1096 st->leak_estimate = FLOAT_EXTRACT16(FLOAT_SHL(FLOAT_DIVU(st->Pey, st->Pyy),14)); in speex_echo_cancellation()
1098 if (st->leak_estimate > 16383) in speex_echo_cancellation()
1099 st->leak_estimate = 32767; in speex_echo_cancellation()
1101 st->leak_estimate = SHL16(st->leak_estimate,1); in speex_echo_cancellation()
1106 tmp32 = MULT16_32_Q15(st->leak_estimate,Syy); in speex_echo_cancellation()
1121 RER = (.0001*Sxx + 3.*MULT16_32_Q15(st->leak_estimate,Syy)) / See; in speex_echo_cancellation()
1130 …if (!st->adapted && st->sum_adapt > SHL32(EXTEND32(M),15) && MULT16_32_Q15(st->leak_estimate,Syy) … in speex_echo_cancellation()
1132 st->adapted = 1; in speex_echo_cancellation()
1135 if (st->adapted) in speex_echo_cancellation()
1138 for (i=0;i<=st->frame_size;i++) in speex_echo_cancellation()
1142 r = MULT16_32_Q15(st->leak_estimate,SHL32(st->Yf[i],3)); in speex_echo_cancellation()
1143 e = SHL32(st->Rf[i],3)+1; in speex_echo_cancellation()
1153 … st->power_1[i] = FLOAT_SHL(FLOAT_DIV32_FLOAT(r,FLOAT_MUL32U(e,st->power[i]+10)),WEIGHT_SHIFT+16); in speex_echo_cancellation()
1171 for (i=0;i<=st->frame_size;i++) in speex_echo_cancellation()
1172 …st->power_1[i] = FLOAT_SHL(FLOAT_DIV32(EXTEND32(adapt_rate),ADD32(st->power[i],10)),WEIGHT_SHIFT+1… in speex_echo_cancellation()
1176 st->sum_adapt = ADD32(st->sum_adapt,adapt_rate); in speex_echo_cancellation()
1180 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
1181 st->last_y[i] = st->last_y[st->frame_size+i]; in speex_echo_cancellation()
1182 if (st->adapted) in speex_echo_cancellation()
1185 for (i=0;i<st->frame_size;i++) in speex_echo_cancellation()
1186 st->last_y[st->frame_size+i] = in[i]-out[i]; in speex_echo_cancellation()
1196 void speex_echo_get_residual(SpeexEchoState *st, spx_word32_t *residual_echo, int len) in speex_echo_get_residual() argument
1202 N = st->window_size; in speex_echo_get_residual()
1206 st->y[i] = MULT16_16_Q15(st->window[i],st->last_y[i]); in speex_echo_get_residual()
1209 spx_fft(st->fft_table, st->y, st->Y); in speex_echo_get_residual()
1210 power_spectrum(st->Y, residual_echo, N); in speex_echo_get_residual()
1213 if (st->leak_estimate > 16383) in speex_echo_get_residual()
1216 leak2 = SHL16(st->leak_estimate, 1); in speex_echo_get_residual()
1218 if (st->leak_estimate>.5) in speex_echo_get_residual()
1221 leak2 = 2*st->leak_estimate; in speex_echo_get_residual()
1224 for (i=0;i<=st->frame_size;i++) in speex_echo_get_residual()
1229 EXPORT int speex_echo_ctl(SpeexEchoState *st, int request, void *ptr) in speex_echo_ctl() argument
1235 (*(int*)ptr) = st->frame_size; in speex_echo_ctl()
1238 st->sampling_rate = (*(int*)ptr); in speex_echo_ctl()
1239 st->spec_average = DIV32_16(SHL32(EXTEND32(st->frame_size), 15), st->sampling_rate); in speex_echo_ctl()
1241 st->beta0 = DIV32_16(SHL32(EXTEND32(st->frame_size), 16), st->sampling_rate); in speex_echo_ctl()
1242 st->beta_max = DIV32_16(SHL32(EXTEND32(st->frame_size), 14), st->sampling_rate); in speex_echo_ctl()
1244 st->beta0 = (2.0f*st->frame_size)/st->sampling_rate; in speex_echo_ctl()
1245 st->beta_max = (.5f*st->frame_size)/st->sampling_rate; in speex_echo_ctl()
1247 if (st->sampling_rate<12000) in speex_echo_ctl()
1248 st->notch_radius = QCONST16(.9, 15); in speex_echo_ctl()
1249 else if (st->sampling_rate<24000) in speex_echo_ctl()
1250 st->notch_radius = QCONST16(.982, 15); in speex_echo_ctl()
1252 st->notch_radius = QCONST16(.992, 15); in speex_echo_ctl()
1255 (*(int*)ptr) = st->sampling_rate; in speex_echo_ctl()
1259 *((spx_int32_t *)ptr) = st->M * st->frame_size; in speex_echo_ctl()
1263 int M = st->M, N = st->window_size, n = st->frame_size, i, j; in speex_echo_ctl()
1270 st->wtmp2[i] = EXTRACT16(PSHR32(st->W[j*N+i],16+NORMALIZE_SCALEDOWN)); in speex_echo_ctl()
1271 spx_ifft(st->fft_table, st->wtmp2, st->wtmp); in speex_echo_ctl()
1273 spx_ifft(st->fft_table, &st->W[j*N], st->wtmp); in speex_echo_ctl()
1276 filt[j*n+i] = PSHR32(MULT16_16(32767,st->wtmp[i]), WEIGHT_SHIFT-NORMALIZE_SCALEDOWN); in speex_echo_ctl()