/* This routine will be called by the PortAudio engine when audio is needed. ** It may called at interrupt level on some machines so don't do anything ** that could mess up the system like calling malloc() or free(). */ static int patestCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData) { PaCtx *ctx; int16_t *in, *out; int avail, amt; ctx = (PaCtx *)userData; out = (int16_t *)outputBuffer; in = (int16_t *)inputBuffer; pthread_mutex_lock(&ctx->mtx); amt = framesPerBuffer * sizeof(out[0]); /* Copy out samples to be played */ if ((avail = fifo_get(ctx->incrate, (uint8_t *)out, amt)) < amt) { /* Zero out samples there are no data for */ bzero(out + (avail / sizeof(out[0])), amt - avail); ctx->underrun += (amt - avail) / sizeof(out[0]); } /* Copy in samples to be recorded */ if ((avail = fifo_put(ctx->outgoing, (uint8_t *)in, amt)) < amt) { /* Zero out samples there are no data for */ bzero(in + (avail / sizeof(out[0])), amt - avail); ctx->overrun += (amt - avail) / sizeof(out[0]); } #if 1 /* Run the echo canceller */ for (int ofs = 0; ofs < framesPerBuffer; ofs++) out[ofs] = echo_can_update(ctx->echocan, in[ofs], out[ofs]); #endif pthread_mutex_unlock(&ctx->mtx); return paContinue; }
void do_echo_update2(phmstream_t *s, char *data, int length) { int i, lg, len; short *p1, *p2; len = length; if (s->pcm_need_resync) return ; if(s->bytes_to_throw){ if(s->bytes_to_throw >= len){ s->bytes_to_throw -= len; printf("EC1:%d bytes thrown\n", len); return; }else{ printf("EC2:%d bytes thrown\n", s->bytes_to_throw); len = length - s->bytes_to_throw; s->bytes_to_throw = 0; } } s->recv_cnt += len; if(s->recv_cnt > s->sent_cnt) { printf( "\nUNDERRUN: %d %d\n", s->sent_cnt, s->recv_cnt); echo_resync(s); return; } p1 = (short *)(s->pcm_sent + s->pcm_rd); p2 = (short *)data; if((PCM_TRACE_LEN - s->pcm_rd) >= len) { for (i=0; i<len/2; i++) { #if !AEC_BIS *p2 = echo_can_update(s->ec, *p1++, *p2); #else /* AEC_BIS */ *p2 = do_AEC(*p1++, *p2); #endif /* AEC_BIS */ p2++; } s->pcm_rd += len; if(s->pcm_rd == PCM_TRACE_LEN) s->pcm_rd = 0; } else { lg = PCM_TRACE_LEN - s->pcm_rd; for (i=0; i<lg/2; i++) { #if !AEC_BIS *p2 = echo_can_update(s->ec, *p1++, *p2); #else /* AEC_BIS */ *p2 = do_AEC(*p1++, *p2); #endif /* AEC_BIS */ p2++; } p1 = (short *)(s->pcm_sent); for (i=0; i<(len - lg)/2; i++) { #if !AEC_BIS *p2 = echo_can_update(s->ec, *p1++, *p2); #else /* AEC_BIS */ *p2 = do_AEC(*p1++, *p2); #endif /* AEC_BIS */ p2++; } s->pcm_rd = len-lg; } }
int main(int argc, char *argv[]) { echo_can_state_t *ctx; awgn_state_t local_noise_source; awgn_state_t far_noise_source; int i; int clean; int residue; int16_t rx; int16_t tx; int j; int k; tone_gen_descriptor_t tone_desc; tone_gen_state_t tone_state; int16_t local_sound[40000]; int local_max; int local_cur; int16_t hoth_noise; //int16_t far_sound[SAMPLE_RATE]; //int16_t result_sound[64000]; //int32_t coeffs[200][128]; //int coeff_index; int far_cur; int result_cur; //int far_tx; AFfilehandle resulthandle; AFfilesetup filesetup; AFfilesetup filesetup2; //int outframes; time_t now; int tone_burst_step; level_measurement_device_t *power_meter_1; level_measurement_device_t *power_meter_2; float pp1; float pp2; int model_number; int use_gui; power_meter_1 = NULL; power_meter_2 = NULL; /* Check which tests we should run */ if (argc < 2) fprintf(stderr, "Usage: echo tests <list of test numbers>\n"); test_list = 0; model_number = 0; use_gui = FALSE; for (i = 1; i < argc; i++) { if (strcasecmp(argv[i], "2a") == 0) test_list |= PERFORM_TEST_2A; else if (strcasecmp(argv[i], "2b") == 0) test_list |= PERFORM_TEST_2B; else if (strcasecmp(argv[i], "2c") == 0) test_list |= PERFORM_TEST_2C; else if (strcasecmp(argv[i], "3a") == 0) test_list |= PERFORM_TEST_3A; else if (strcasecmp(argv[i], "3b") == 0) test_list |= PERFORM_TEST_3B; else if (strcasecmp(argv[i], "3c") == 0) test_list |= PERFORM_TEST_3C; else if (strcasecmp(argv[i], "4") == 0) test_list |= PERFORM_TEST_4; else if (strcasecmp(argv[i], "5") == 0) test_list |= PERFORM_TEST_5; else if (strcasecmp(argv[i], "6") == 0) test_list |= PERFORM_TEST_6; else if (strcasecmp(argv[i], "7") == 0) test_list |= PERFORM_TEST_7; else if (strcasecmp(argv[i], "8") == 0) test_list |= PERFORM_TEST_8; else if (strcasecmp(argv[i], "9") == 0) test_list |= PERFORM_TEST_9; else if (strcasecmp(argv[i], "10a") == 0) test_list |= PERFORM_TEST_10A; else if (strcasecmp(argv[i], "10b") == 0) test_list |= PERFORM_TEST_10B; else if (strcasecmp(argv[i], "10c") == 0) test_list |= PERFORM_TEST_10C; else if (strcasecmp(argv[i], "11") == 0) test_list |= PERFORM_TEST_11; else if (strcasecmp(argv[i], "12") == 0) test_list |= PERFORM_TEST_12; else if (strcasecmp(argv[i], "13") == 0) test_list |= PERFORM_TEST_13; else if (strcasecmp(argv[i], "14") == 0) test_list |= PERFORM_TEST_14; else if (strcasecmp(argv[i], "15") == 0) test_list |= PERFORM_TEST_15; else if (strcmp(argv[i], "-m") == 0) { if (++i < argc) model_number = atoi(argv[i]); } else if (strcmp(argv[i], "-g") == 0) { use_gui = TRUE; } else { fprintf(stderr, "Unknown test '%s' specified\n", argv[i]); exit(2); } } if (test_list == 0) { fprintf(stderr, "No tests have been selected\n"); exit(2); } time(&now); tone_burst_step = 0; ctx = echo_can_create(TEST_EC_TAPS, 0); awgn_init_dbm0(&far_noise_source, 7162534, -50.0f); signal_load(&local_css, "sound_c1_8k.wav"); signal_load(&far_css, "sound_c3_8k.wav"); filesetup = afNewFileSetup(); if (filesetup == AF_NULL_FILESETUP) { fprintf(stderr, " Failed to create file setup\n"); exit(2); } afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE); afInitFileFormat(filesetup, AF_FILE_WAVE); afInitChannels(filesetup, AF_DEFAULT_TRACK, 6); filesetup2 = afNewFileSetup(); if (filesetup2 == AF_NULL_FILESETUP) { fprintf(stderr, " Failed to create file setup\n"); exit(2); } afInitSampleFormat(filesetup2, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); afInitRate(filesetup2, AF_DEFAULT_TRACK, (float) SAMPLE_RATE); afInitFileFormat(filesetup2, AF_FILE_WAVE); afInitChannels(filesetup2, AF_DEFAULT_TRACK, 1); resulthandle = afOpenFile("result_sound.wav", "w", filesetup); if (resulthandle == AF_NULL_FILEHANDLE) { fprintf(stderr, " Failed to open result file\n"); exit(2); } residuehandle = afOpenFile("residue_sound.wav", "w", filesetup2); if (residuehandle == AF_NULL_FILEHANDLE) { fprintf(stderr, " Failed to open residue file\n"); exit(2); } local_cur = 0; far_cur = 0; result_cur = 0; if (channel_model_create(model_number)) { fprintf(stderr, " Failed to create line model\n"); exit(2); } #if defined(ENABLE_GUI) if (use_gui) { start_echo_can_monitor(TEST_EC_TAPS); echo_can_monitor_line_model_update(line_model.coeffs, line_model.taps); } #endif power_meter_1 = level_measurement_device_create(0); power_meter_2 = level_measurement_device_create(0); level_measurement_device(power_meter_1, 0); #if 0 echo_can_flush(ctx); /* Converge the canceller */ signal_restart(&local_css); for (i = 0; i < 800*2; i++) { clean = echo_can_update(ctx, 0, 0); put_residue(clean); } for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION | ECHO_CAN_USE_NLP | ECHO_CAN_USE_CNG); for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); for (i = 0; i < SAMPLE_RATE*10; i++) { tx = signal_amp(&local_css); #if 0 if ((i/10000)%10 == 9) { /* Inject a burst of far sound */ if (far_cur >= far_max) { far_max = afReadFrames(farhandle, AF_DEFAULT_TRACK, far_sound, SAMPLE_RATE); if (far_max < 0) { fprintf(stderr, " Error reading far sound\n"); exit(2); } if (far_max == 0) break; far_cur = 0; } far_tx = far_sound[far_cur++]; } else { far_tx = 0; } #else far_sound[0] = 0; far_tx = 0; #endif channel_model(&tx, &rx, tx, far_tx); //rx += awgn(&far_noise_source); //tx += awgn(&far_noise_source); clean = echo_can_update(ctx, tx, rx); #if defined(XYZZY) if (i%SAMPLE_RATE == 0) { if (coeff_index < 200) { for (j = 0; j < ctx->taps; j++) coeffs[coeff_index][j] = ctx->fir_taps32[j]; coeff_index++; } } #endif result_sound[result_cur++] = tx; result_sound[result_cur++] = rx; result_sound[result_cur++] = clean - far_tx; //result_sound[result_cur++] = ctx->tx_power[2]; //result_sound[result_cur++] = ctx->tx_power[1]; result_sound[result_cur++] = (ctx->tx_power[1] > 64) ? SAMPLE_RATE : -SAMPLE_RATE; //result_sound[result_cur++] = ctx->tap_set*SAMPLE_RATE; //result_sound[result_cur++] = (ctx->nonupdate_dwell > 0) ? SAMPLE_RATE : -SAMPLE_RATE; //result_sound[result_cur++] = ctx->latest_correction >> 8; //result_sound[result_cur++] = level_measurement_device(tx)/(16.0*65536.0); //result_sound[result_cur++] = level_measurement_device(tx)/4096.0; result_sound[result_cur++] = (ctx->tx_power[1] > ctx->rx_power[0]) ? SAMPLE_RATE : -SAMPLE_RATE; //result_sound[result_cur++] = (ctx->tx_power[1] > ctx->rx_power[0]) ? SAMPLE_RATE : -SAMPLE_RATE; //result_sound[result_cur++] = (ctx->narrowband_score)*5; // ? SAMPLE_RATE : -SAMPLE_RATE; //result_sound[result_cur++] = ctx->tap_rotate_counter*10; result_sound[result_cur++] = ctx->vad; put_residue(clean - far_tx); if (result_cur >= 6*SAMPLE_RATE) { outframes = afWriteFrames(resulthandle, AF_DEFAULT_TRACK, result_sound, result_cur/6); if (outframes != result_cur/6) { fprintf(stderr, " Error writing result sound\n"); exit(2); } result_cur = 0; } } if (result_cur > 0) { outframes = afWriteFrames(resulthandle, AF_DEFAULT_TRACK, result_sound, result_cur/6); if (outframes != result_cur/4) { fprintf(stderr, " Error writing result sound\n"); exit(2); } } #endif /* Test 1 - Steady state residual and returned echo level test */ /* This functionality has been merged with test 2 in newer versions of G.168, so test 1 no longer exists. */ /* Test 2 - Convergence and steady state residual and returned echo level test */ if ((test_list & PERFORM_TEST_2A)) { printf("Performing test 2A - Convergence with NLP enabled\n"); /* Test 2A - Convergence with NLP enabled */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION | ECHO_CAN_USE_NLP); /* Converge the canceller */ signal_restart(&local_css); for (i = 0; i < 800*2; i++) { clean = echo_can_update(ctx, 0, 0); put_residue(clean); } for (i = 0; i < SAMPLE_RATE*50; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); pp1 = level_measurement_device(power_meter_1, rx); pp2 = level_measurement_device(power_meter_2, clean); residue = 100.0*pp1/pp2; put_residue(residue); #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_2B)) { printf("Performing test 2B - Convergence with NLP disabled\n"); /* Test 2B - Convergence with NLP disabled */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); /* Converge a canceller */ signal_restart(&local_css); for (i = 0; i < 800*2; i++) { clean = echo_can_update(ctx, 0, 0); put_residue(clean); } for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_2C)) { printf("Performing test 2C - Convergence with background noise present\n"); /* Test 2C - Convergence with background noise present */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); /* Converge a canceller */ signal_restart(&local_css); for (i = 0; i < 800*2; i++) { clean = echo_can_update(ctx, 0, 0); put_residue(clean); } /* TODO: This uses a crude approx. to Hoth noise. We need the real thing. */ awgn_init_dbm0(&far_noise_source, 7162534, -40.0f); hoth_noise = 0; for (i = 0; i < SAMPLE_RATE*5; i++) { hoth_noise = hoth_noise*0.625 + awgn(&far_noise_source)*0.375; tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, hoth_noise); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Now freeze adaption, and measure the echo. */ echo_can_adaption_mode(ctx, 0); for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } /* Test 3 - Performance under double talk conditions */ if ((test_list & PERFORM_TEST_3A)) { printf("Performing test 3A - Double talk test with low cancelled-end levels\n"); /* Test 3A - Double talk test with low cancelled-end levels */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); signal_restart(&local_css); signal_restart(&far_css); /* Apply double talk, with a weak far end signal */ for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); rx = signal_amp(&far_css)/20; channel_model(&tx, &rx, tx, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean - rx); } /* Now freeze adaption. */ echo_can_adaption_mode(ctx, 0); for (i = 0; i < 800*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Now measure the echo */ for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_3B)) { printf("Performing test 3B - Double talk test with high cancelled-end levels\n"); /* Test 3B - Double talk test with high cancelled-end levels */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); signal_restart(&local_css); signal_restart(&far_css); /* Converge the canceller */ for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Apply double talk */ for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); rx = signal_amp(&far_css); channel_model(&tx, &rx, tx, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean - rx); } /* Now freeze adaption. */ echo_can_adaption_mode(ctx, 0); for (i = 0; i < 800*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Now measure the echo */ for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_3C)) { printf("Performing test 3C - Double talk test with simulated conversation\n"); /* Test 3C - Double talk test with simulated conversation */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); signal_restart(&local_css); signal_restart(&far_css); /* Apply double talk */ for (i = 0; i < 800*56; i++) { tx = signal_amp(&local_css); rx = signal_amp(&far_css); channel_model(&tx, &rx, tx, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean - rx); } /* Stop the far signal */ for (i = 0; i < 800*14; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Continue measuring the resulting echo */ for (i = 0; i < 800*50; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Reapply double talk */ signal_restart(&far_css); for (i = 0; i < 800*56; i++) { tx = signal_amp(&local_css); rx = signal_amp(&far_css); channel_model(&tx, &rx, tx, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean - rx); } /* Now the far signal only */ for (i = 0; i < 800*56; i++) { tx = 0; rx = signal_amp(&far_css); channel_model(&tx, &rx, 0, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean - rx); } #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_4)) { printf("Performing test 4 - Leak rate test\n"); /* Test 4 - Leak rate test */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); /* Converge a canceller */ signal_restart(&local_css); for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Put 2 minutes of silence through it */ for (i = 0; i < SAMPLE_RATE*120; i++) { clean = echo_can_update(ctx, 0, 0); put_residue(clean); } /* Now freeze it, and check if it is still well adapted. */ echo_can_adaption_mode(ctx, 0); for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_5)) { printf("Performing test 5 - Infinite return loss convergence test\n"); /* Test 5 - Infinite return loss convergence test */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); /* Converge the canceller */ signal_restart(&local_css); for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Now stop echoing, and see we don't do anything unpleasant as the echo path is open looped. */ for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); rx = 0; tx = codec_munge(tx); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_6)) { printf("Performing test 6 - Non-divergence on narrow-band signals\n"); /* Test 6 - Non-divergence on narrow-band signals */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); /* Converge the canceller */ signal_restart(&local_css); for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Now put 5s bursts of a list of tones through the converged canceller, and check that bothing unpleasant happens. */ for (k = 0; tones_6_4_2_7[k][0]; k++) { make_tone_gen_descriptor(&tone_desc, tones_6_4_2_7[k][0], -11, tones_6_4_2_7[k][1], -9, 1, 0, 0, 0, 1); tone_gen_init(&tone_state, &tone_desc); j = 0; for (i = 0; i < 5; i++) { local_max = tone_gen(&tone_state, local_sound, SAMPLE_RATE); for (j = 0; j < SAMPLE_RATE; j++) { tx = local_sound[j]; channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } #if defined(ENABLE_GUI) if (use_gui) { echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); echo_can_monitor_update_display(); usleep(100000); } #endif } } #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_7)) { printf("Performing test 7 - Stability\n"); /* Test 7 - Stability */ /* Put tones through an unconverged canceller, and check nothing unpleasant happens. */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); make_tone_gen_descriptor(&tone_desc, tones_6_4_2_7[0][0], -11, tones_6_4_2_7[0][1], -9, 1, 0, 0, 0, 1); tone_gen_init(&tone_state, &tone_desc); j = 0; for (i = 0; i < 120; i++) { local_max = tone_gen(&tone_state, local_sound, SAMPLE_RATE); for (j = 0; j < SAMPLE_RATE; j++) { tx = local_sound[j]; channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } #if defined(ENABLE_GUI) if (use_gui) { echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); echo_can_monitor_update_display(); usleep(100000); } #endif } #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } if ((test_list & PERFORM_TEST_8)) { printf("Performing test 8 - Non-convergence on No 5, 6, and 7 in-band signalling\n"); /* Test 8 - Non-convergence on No 5, 6, and 7 in-band signalling */ fprintf(stderr, "Test 8 not yet implemented\n"); } if ((test_list & PERFORM_TEST_9)) { printf("Performing test 9 - Comfort noise test\n"); /* Test 9 - Comfort noise test */ /* Test 9 part 1 - matching */ echo_can_flush(ctx); echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); /* Converge the canceller */ signal_restart(&local_css); for (i = 0; i < SAMPLE_RATE*5; i++) { tx = signal_amp(&local_css); channel_model(&tx, &rx, tx, 0); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION | ECHO_CAN_USE_NLP | ECHO_CAN_USE_CNG); awgn_init_dbm0(&far_noise_source, 7162534, -45.0f); for (i = 0; i < SAMPLE_RATE*30; i++) { tx = 0; rx = awgn(&far_noise_source); channel_model(&tx, &rx, tx, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } awgn_init_dbm0(&local_noise_source, 1234567, -10.0f); for (i = 0; i < SAMPLE_RATE*2; i++) { tx = awgn(&local_noise_source); rx = awgn(&far_noise_source); channel_model(&tx, &rx, tx, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } /* Test 9 part 2 - adjust down */ awgn_init_dbm0(&far_noise_source, 7162534, -55.0f); for (i = 0; i < SAMPLE_RATE*10; i++) { tx = 0; rx = awgn(&far_noise_source); channel_model(&tx, &rx, tx, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } for (i = 0; i < SAMPLE_RATE*2; i++) { tx = awgn(&local_noise_source); rx = awgn(&far_noise_source); channel_model(&tx, &rx, tx, rx); clean = echo_can_update(ctx, tx, rx); put_residue(clean); } #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[ctx->tap_set], TEST_EC_TAPS); #endif } /* Test 10 - FAX test during call establishment phase */ if ((test_list & PERFORM_TEST_10A)) { printf("Performing test 10A - Canceller operation on the calling station side\n"); /* Test 10A - Canceller operation on the calling station side */ fprintf(stderr, "Test 10A not yet implemented\n"); } if ((test_list & PERFORM_TEST_10B)) { printf("Performing test 10B - Canceller operation on the called station side\n"); /* Test 10B - Canceller operation on the called station side */ fprintf(stderr, "Test 10B not yet implemented\n"); } if ((test_list & PERFORM_TEST_10C)) { printf("Performing test 10C - Canceller operation on the calling station side during page\n" "transmission and page breaks (for further study)\n"); /* Test 10C - Canceller operation on the calling station side during page transmission and page breaks (for further study) */ fprintf(stderr, "Test 10C not yet implemented\n"); } if ((test_list & PERFORM_TEST_11)) { printf("Performing test 11 - Tandem echo canceller test (for further study)\n"); /* Test 11 - Tandem echo canceller test (for further study) */ fprintf(stderr, "Test 11 not yet implemented\n"); } if ((test_list & PERFORM_TEST_12)) { printf("Performing test 12 - Residual acoustic echo test (for further study)\n"); /* Test 12 - Residual acoustic echo test (for further study) */ fprintf(stderr, "Test 12 not yet implemented\n"); } if ((test_list & PERFORM_TEST_13)) { printf("Performing test 13 - Performance with ITU-T low-bit rate coders in echo path (Optional, under study)\n"); /* Test 13 - Performance with ITU-T low-bit rate coders in echo path (Optional, under study) */ fprintf(stderr, "Test 13 not yet implemented\n"); } if ((test_list & PERFORM_TEST_14)) { printf("Performing test 14 - Performance with V-series low-speed data modems\n"); /* Test 14 - Performance with V-series low-speed data modems */ fprintf(stderr, "Test 14 not yet implemented\n"); } if ((test_list & PERFORM_TEST_15)) { printf("Performing test 15 - PCM offset test (Optional)\n"); /* Test 15 - PCM offset test (Optional) */ fprintf(stderr, "Test 15 not yet implemented\n"); } echo_can_free(ctx); signal_free(&local_css); signal_free(&far_css); if (afCloseFile(resulthandle) != 0) { fprintf(stderr, " Cannot close speech file '%s'\n", "result_sound.wav"); exit(2); } if (afCloseFile(residuehandle) != 0) { fprintf(stderr, " Cannot close speech file '%s'\n", "residue_sound.wav"); exit(2); } afFreeFileSetup(filesetup); afFreeFileSetup(filesetup2); #if defined(XYZZY) for (j = 0; j < ctx->taps; j++) { for (i = 0; i < coeff_index; i++) fprintf(stderr, "%d ", coeffs[i][j]); fprintf(stderr, "\n"); } #endif printf("Run time %lds\n", time(NULL) - now); #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_wait_to_end(); #endif if (power_meter_1) level_measurement_device_release(power_meter_1); if (power_meter_2) level_measurement_device_release(power_meter_2); printf("Tests passed.\n"); return 0; }