Esempio n. 1
0
int main(int argc, char *argv[])
{
    int16_t amp[SAMPLES_PER_CHUNK];
    int samples;
    int caller_available_modulations;
    int answerer_available_modulations;
    SNDFILE *inhandle;
    SNDFILE *outhandle;
    int opt;
    int log_audio;
    char *decode_test_file;
    v8_state_t *v8_caller;
    v8_state_t *v8_answerer;
    v8_parms_t v8_call_parms;
    v8_parms_t v8_answer_parms;
    logging_state_t *logging;

    decode_test_file = NULL;
    log_audio = false;
    while ((opt = getopt(argc, argv, "d:l")) != -1)
    {
        switch (opt)
        {
        case 'd':
            decode_test_file = optarg;
            break;
        case 'l':
            log_audio = true;
            break;
        default:
            //usage();
            exit(2);
            break;
        }
    }

    if (decode_test_file)
    {
        caller_available_modulations = V8_MOD_V17
                                     | V8_MOD_V21
                                     | V8_MOD_V22
                                     | V8_MOD_V23HDX
                                     | V8_MOD_V23
                                     | V8_MOD_V26BIS
                                     | V8_MOD_V26TER
                                     | V8_MOD_V27TER
                                     | V8_MOD_V29
                                     | V8_MOD_V32
                                     | V8_MOD_V34HDX
                                     | V8_MOD_V34
                                     | V8_MOD_V90
                                     | V8_MOD_V92;
        answerer_available_modulations = V8_MOD_V17
                                       | V8_MOD_V21
                                       | V8_MOD_V22
                                       | V8_MOD_V23HDX
                                       | V8_MOD_V23
                                       | V8_MOD_V26BIS
                                       | V8_MOD_V26TER
                                       | V8_MOD_V27TER
                                       | V8_MOD_V29
                                       | V8_MOD_V32
                                       | V8_MOD_V34HDX
                                       | V8_MOD_V34
                                       | V8_MOD_V90
                                       | V8_MOD_V92;

        printf("Decode file '%s'\n", decode_test_file);
        v8_call_parms.modem_connect_tone = MODEM_CONNECT_TONES_NONE;
        v8_call_parms.send_ci = true;
        v8_call_parms.v92 = -1;
        v8_call_parms.call_function = V8_CALL_V_SERIES;
        v8_call_parms.modulations = caller_available_modulations;
        v8_call_parms.protocol = V8_PROTOCOL_LAPM_V42;
        v8_call_parms.pcm_modem_availability = 0;
        v8_call_parms.pstn_access = 0;
        v8_call_parms.nsf = -1;
        v8_call_parms.t66 = -1;
        v8_caller = v8_init(NULL,
                            true,
                            &v8_call_parms,
                            handler,
                            (void *) "caller");
        logging = v8_get_logging_state(v8_caller);
        span_log_set_level(logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
        span_log_set_tag(logging, "caller");

        v8_answer_parms.modem_connect_tone = MODEM_CONNECT_TONES_ANSAM_PR;
        v8_answer_parms.send_ci = true;
        v8_answer_parms.v92 = -1;
        v8_answer_parms.call_function = V8_CALL_V_SERIES;
        v8_answer_parms.modulations = answerer_available_modulations;
        v8_answer_parms.protocol = V8_PROTOCOL_LAPM_V42;
        v8_answer_parms.pcm_modem_availability = 0;
        v8_answer_parms.pstn_access = 0;
        v8_answer_parms.nsf = -1;
        v8_answer_parms.t66 = -1;
        v8_answerer = v8_init(NULL,
                              false,
                              &v8_answer_parms,
                              handler,
                              (void *) "answerer");
        logging = v8_get_logging_state(v8_answerer);
        span_log_set_level(logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
        span_log_set_tag(logging, "answerer");

        if ((inhandle = sf_open_telephony_read(decode_test_file, 1)) == NULL)
        {
            fprintf(stderr, "    Cannot open speech file '%s'\n", decode_test_file);
            exit (2);
        }
        /*endif*/

        while ((samples = sf_readf_short(inhandle, amp, SAMPLES_PER_CHUNK)))
        {
            v8_rx(v8_caller, amp, samples);
            v8_rx(v8_answerer, amp, samples);
            v8_tx(v8_caller, amp, samples);
            v8_tx(v8_answerer, amp, samples);
        }
        /*endwhile*/

        v8_free(v8_caller);
        v8_free(v8_answerer);
        if (sf_close_telephony(inhandle))
        {
            fprintf(stderr, "    Cannot close speech file '%s'\n", decode_test_file);
            exit(2);
        }
        /*endif*/
    }
    else
    {
        outhandle = NULL;
        if (log_audio)
        {
            if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 2)) == NULL)
            {
                fprintf(stderr, "    Cannot create audio file '%s'\n", OUTPUT_FILE_NAME);
                exit(2);
            }
            /*endif*/
        }
        /*endif*/

        printf("Test 1: V.8 terminal calls V.8 terminal\n");
        v8_calls_v8_tests(outhandle);

        printf("Test 2: non-V.8 terminal calls V.8 terminal\n");
        non_v8_calls_v8_tests(outhandle);

        printf("Test 3: V.8 terminal calls non-V.8 terminal\n");
        v8_calls_non_v8_tests(outhandle);

        if (outhandle)
        {
            if (sf_close_telephony(outhandle))
            {
                fprintf(stderr, "    Cannot close audio file '%s'\n", OUTPUT_FILE_NAME);
                exit(2);
            }
            /*endif*/
        }
        /*endif*/

        printf("Tests passed.\n");
    }
    return 0;
}
Esempio n. 2
0
static int non_v8_calls_v8_tests(SNDFILE *outhandle)
{
    silence_gen_state_t *non_v8_caller_tx;
    modem_connect_tones_rx_state_t *non_v8_caller_rx;
    v8_state_t *v8_answerer;
    logging_state_t *answerer_logging;
    int answerer_available_modulations;
    int i;
    int samples;
    int remnant;
    int outframes;
    int tone;
    int16_t amp[SAMPLES_PER_CHUNK];
    int16_t out_amp[2*SAMPLES_PER_CHUNK];
    v8_parms_t v8_answer_parms;

    answerer_available_modulations = V8_MOD_V17
                                   | V8_MOD_V21
                                   | V8_MOD_V22
                                   | V8_MOD_V23HDX
                                   | V8_MOD_V23
                                   | V8_MOD_V26BIS
                                   | V8_MOD_V26TER
                                   | V8_MOD_V27TER
                                   | V8_MOD_V29
                                   | V8_MOD_V32
                                   | V8_MOD_V34HDX
                                   | V8_MOD_V34
                                   | V8_MOD_V90
                                   | V8_MOD_V92;
    negotiations_ok = 0;

    non_v8_caller_tx = silence_gen_init(NULL, 10*SAMPLE_RATE);
    non_v8_caller_rx = modem_connect_tones_rx_init(NULL, MODEM_CONNECT_TONES_ANS_PR, NULL, NULL);

    v8_answer_parms.modem_connect_tone = MODEM_CONNECT_TONES_ANSAM_PR;
    v8_answer_parms.send_ci = true;
    v8_answer_parms.v92 = -1;
    v8_answer_parms.call_function = V8_CALL_V_SERIES;
    v8_answer_parms.modulations = answerer_available_modulations;
    v8_answer_parms.protocol = V8_PROTOCOL_LAPM_V42;
    v8_answer_parms.pcm_modem_availability = 0;
    v8_answer_parms.pstn_access = 0;
    v8_answer_parms.nsf = -1;
    v8_answer_parms.t66 = -1;
    v8_answerer = v8_init(NULL,
                          false,
                          &v8_answer_parms,
                          handler,
                          (void *) "answerer");
    answerer_logging = v8_get_logging_state(v8_answerer);
    span_log_set_level(answerer_logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
    span_log_set_tag(answerer_logging, "answerer");
    for (i = 0;  i < 1000;  i++)
    {
        samples = silence_gen(non_v8_caller_tx, amp, SAMPLES_PER_CHUNK);
        if (samples < SAMPLES_PER_CHUNK)
        {
            vec_zeroi16(amp + samples, SAMPLES_PER_CHUNK - samples);
            samples = SAMPLES_PER_CHUNK;
        }
        /*endif*/
        remnant = v8_rx(v8_answerer, amp, samples);
        if (remnant)
            break;
        /*endif*/
        for (i = 0;  i < samples;  i++)
            out_amp[2*i] = amp[i];
        /*endfor*/

        samples = v8_tx(v8_answerer, amp, SAMPLES_PER_CHUNK);
        if (samples < SAMPLES_PER_CHUNK)
        {
            vec_zeroi16(amp + samples, SAMPLES_PER_CHUNK - samples);
            samples = SAMPLES_PER_CHUNK;
        }
        /*endif*/
        span_log_bump_samples(answerer_logging, samples);
        modem_connect_tones_rx(non_v8_caller_rx, amp, samples);
        if ((tone = modem_connect_tones_rx_get(non_v8_caller_rx)) != MODEM_CONNECT_TONES_NONE)
        {
            printf("Detected %s (%d)\n", modem_connect_tone_to_str(tone), tone);
            if (tone == MODEM_CONNECT_TONES_ANSAM_PR)
                negotiations_ok++;
            /*endif*/
        }
        /*endif*/
        for (i = 0;  i < samples;  i++)
            out_amp[2*i + 1] = amp[i];
        /*endfor*/

        if (outhandle)
        {
            outframes = sf_writef_short(outhandle, out_amp, samples);
            if (outframes != samples)
            {
                fprintf(stderr, "    Error writing audio file\n");
                exit(2);
            }
            /*endif*/
        }
        /*endif*/
    }
    /*endfor*/
    silence_gen_free(non_v8_caller_tx);
    modem_connect_tones_rx_free(non_v8_caller_rx);
    v8_free(v8_answerer);

    if (negotiations_ok != 1)
    {
        printf("Tests failed.\n");
        exit(2);
    }
    /*endif*/
    return 0;
}
Esempio n. 3
0
static int v8_calls_non_v8_tests(SNDFILE *outhandle)
{
    v8_state_t *v8_caller;
    modem_connect_tones_tx_state_t *non_v8_answerer_tx;
    logging_state_t *caller_logging;
    int caller_available_modulations;
    int i;
    int samples;
    int outframes;
    int16_t amp[SAMPLES_PER_CHUNK];
    int16_t out_amp[2*SAMPLES_PER_CHUNK];
    v8_parms_t v8_call_parms;

    caller_available_modulations = V8_MOD_V17
                                 | V8_MOD_V21
                                 | V8_MOD_V22
                                 | V8_MOD_V23HDX
                                 | V8_MOD_V23
                                 | V8_MOD_V26BIS
                                 | V8_MOD_V26TER
                                 | V8_MOD_V27TER
                                 | V8_MOD_V29
                                 | V8_MOD_V32
                                 | V8_MOD_V34HDX
                                 | V8_MOD_V34
                                 | V8_MOD_V90
                                 | V8_MOD_V92;
    negotiations_ok = 0;

    v8_call_parms.modem_connect_tone = MODEM_CONNECT_TONES_NONE;
    v8_call_parms.send_ci = true;
    v8_call_parms.v92 = -1;
    v8_call_parms.call_function = V8_CALL_V_SERIES;
    v8_call_parms.modulations = caller_available_modulations;
    v8_call_parms.protocol = V8_PROTOCOL_LAPM_V42;
    v8_call_parms.pcm_modem_availability = 0;
    v8_call_parms.pstn_access = 0;
    v8_call_parms.nsf = -1;
    v8_call_parms.t66 = -1;
    v8_caller = v8_init(NULL,
                        true,
                        &v8_call_parms,
                        handler,
                        (void *) "caller");
    non_v8_answerer_tx = modem_connect_tones_tx_init(NULL, MODEM_CONNECT_TONES_ANS_PR);
    caller_logging = v8_get_logging_state(v8_caller);
    span_log_set_level(caller_logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
    span_log_set_tag(caller_logging, "caller");
    for (i = 0;  i < 1000;  i++)
    {
        samples = v8_tx(v8_caller, amp, SAMPLES_PER_CHUNK);
        if (samples < SAMPLES_PER_CHUNK)
        {
            vec_zeroi16(amp + samples, SAMPLES_PER_CHUNK - samples);
            samples = SAMPLES_PER_CHUNK;
        }
        /*endif*/
        span_log_bump_samples(caller_logging, samples);
        for (i = 0;  i < samples;  i++)
            out_amp[2*i] = amp[i];
        /*endfor*/

        samples = modem_connect_tones_tx(non_v8_answerer_tx, amp, SAMPLES_PER_CHUNK);
        if (samples < SAMPLES_PER_CHUNK)
        {
            vec_zeroi16(amp + samples, SAMPLES_PER_CHUNK - samples);
            samples = SAMPLES_PER_CHUNK;
        }
        /*endif*/
        if (v8_rx(v8_caller, amp, samples))
            break;
        /*endif*/
        for (i = 0;  i < samples;  i++)
            out_amp[2*i + 1] = amp[i];
        /*endfor*/

        if (outhandle)
        {
            outframes = sf_writef_short(outhandle, out_amp, samples);
            if (outframes != samples)
            {
                fprintf(stderr, "    Error writing audio file\n");
                exit(2);
            }
            /*endif*/
        }
        /*endif*/
    }
    /*endfor*/
    v8_free(v8_caller);
    modem_connect_tones_tx_free(non_v8_answerer_tx);

    if (negotiations_ok != 42)
    {
        printf("Tests failed.\n");
        exit(2);
    }
    /*endif*/
    return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    int i;
    int16_t amp[SAMPLES_PER_CHUNK];
    int16_t out_amp[2*SAMPLES_PER_CHUNK];
    v8_state_t v8_caller;
    v8_state_t v8_answerer;
    int outframes;
    int samples;
    int remnant;
    int caller_available_modulations;
    int answerer_available_modulations;
    AFfilehandle inhandle;
    AFfilehandle outhandle;
    AFfilesetup filesetup;
    int opt;
    char *decode_test_file;
    float x;
    
    decode_test_file = NULL;
    while ((opt = getopt(argc, argv, "d:")) != -1)
    {
        switch (opt)
        {
        case 'd':
            decode_test_file = optarg;
            break;
        default:
            //usage();
            exit(2);
            break;
        }
    }

    caller_available_modulations = V8_MOD_V17
                                 | V8_MOD_V21
                                 | V8_MOD_V22
                                 | V8_MOD_V23HALF
                                 | V8_MOD_V23
                                 | V8_MOD_V26BIS
                                 | V8_MOD_V26TER
                                 | V8_MOD_V27TER
                                 | V8_MOD_V29
                                 | V8_MOD_V32
                                 | V8_MOD_V34HALF
                                 | V8_MOD_V34
                                 | V8_MOD_V90
                                 | V8_MOD_V92;
    answerer_available_modulations = V8_MOD_V17
                                   | V8_MOD_V21
                                   | V8_MOD_V22
                                   | V8_MOD_V23HALF
                                   | V8_MOD_V23
                                   | V8_MOD_V26BIS
                                   | V8_MOD_V26TER
                                   | V8_MOD_V27TER
                                   | V8_MOD_V29
                                   | V8_MOD_V32
                                   | V8_MOD_V34HALF
                                   | V8_MOD_V34
                                   | V8_MOD_V90
                                   | V8_MOD_V92;
    
    if (decode_test_file == NULL)
    {
        if ((filesetup = afNewFileSetup()) == 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, 2);
        if ((outhandle = afOpenFile(OUTPUT_FILE_NAME, "w", filesetup)) == AF_NULL_FILEHANDLE)
        {
            fprintf(stderr, "    Cannot create wave file '%s'\n", OUTPUT_FILE_NAME);
            exit(2);
        }
    
        v8_init(&v8_caller, TRUE, caller_available_modulations, handler, (void *) "caller");
        v8_init(&v8_answerer, FALSE, answerer_available_modulations, handler, (void *) "answerer");
        span_log_set_level(&v8_caller.logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
        span_log_set_tag(&v8_caller.logging, "caller");
        span_log_set_level(&v8_answerer.logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
        span_log_set_tag(&v8_answerer.logging, "answerer");
        for (i = 0;  i < 1000;  i++)
        {
            samples = v8_tx(&v8_caller, amp, SAMPLES_PER_CHUNK);
            if (samples < SAMPLES_PER_CHUNK)
            {
                memset(amp + samples, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - samples));
                samples = SAMPLES_PER_CHUNK;
            }
            remnant = v8_rx(&v8_answerer, amp, samples);
            for (i = 0;  i < samples;  i++)
                out_amp[2*i] = amp[i];
            
            samples = v8_tx(&v8_answerer, amp, SAMPLES_PER_CHUNK);
            if (samples < SAMPLES_PER_CHUNK)
            {
                memset(amp + samples, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - samples));
                samples = SAMPLES_PER_CHUNK;
            }
            if (v8_rx(&v8_caller, amp, samples)  &&  remnant)
                break;
            for (i = 0;  i < samples;  i++)
                out_amp[2*i + 1] = amp[i];
    
            outframes = afWriteFrames(outhandle,
                                      AF_DEFAULT_TRACK,
                                      out_amp,
                                      samples);
            if (outframes != samples)
            {
                fprintf(stderr, "    Error writing wave file\n");
                exit(2);
            }
        }
        if (afCloseFile(outhandle))
        {
            fprintf(stderr, "    Cannot close wave file '%s'\n", OUTPUT_FILE_NAME);
            exit(2);
        }
        afFreeFileSetup(filesetup);
        
        v8_release(&v8_caller);
        v8_release(&v8_answerer);
        
        if (negotiations_ok != 2)
        {
            printf("Tests failed.\n");
            exit(2);
        }
        printf("Tests passed.\n");
    }
    else
    {
        printf("Decode file '%s'\n", decode_test_file);
        v8_init(&v8_answerer, FALSE, answerer_available_modulations, handler, (void *) "answerer");
        span_log_set_level(&v8_answerer.logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG);
        span_log_set_tag(&v8_answerer.logging, "decoder");
        if ((inhandle = afOpenFile(decode_test_file, "r", 0)) == AF_NULL_FILEHANDLE)
        {
            fprintf(stderr, "    Cannot open speech file '%s'\n", decode_test_file);
            exit (2);
        }
        /*endif*/
        if ((x = afGetFrameSize(inhandle, AF_DEFAULT_TRACK, 1)) != 2.0)
        {
            fprintf(stderr, "    Unexpected frame size in speech file '%s'\n", decode_test_file);
            exit (2);
        }
        /*endif*/
        if ((x = afGetRate(inhandle, AF_DEFAULT_TRACK)) != (float) SAMPLE_RATE)
        {
            fprintf(stderr, "    Unexpected sample rate in speech file '%s'\n", decode_test_file);
            exit(2);
        }
        /*endif*/
        if ((x = afGetChannels(inhandle, AF_DEFAULT_TRACK)) != 1.0)
        {
            fprintf(stderr, "    Unexpected number of channels in speech file '%s'\n", decode_test_file);
            exit(2);
        }
        /*endif*/
        while ((samples = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, SAMPLES_PER_CHUNK)))
        {
            remnant = v8_rx(&v8_answerer, amp, samples);
        }
        /*endwhile*/
        v8_release(&v8_answerer);
        if (afCloseFile(inhandle) != 0)
        {
            fprintf(stderr, "    Cannot close speech file '%s'\n", decode_test_file);
            exit(2);
        }
        /*endif*/
    }
    return  0;
}