int main(int argc, char *argv[])
{
    const char *file_name;
    super_tone_rx_state_t *super;
    super_tone_rx_descriptor_t desc;

    super_tone_rx_make_descriptor(&desc);
#if defined(HAVE_LIBXML2)
    get_tone_set(&desc, "../spandsp/global-tones.xml", (argc > 1)  ?  argv[1]  :  "hk");
#endif
    super_tone_rx_fill_descriptor(&desc);
    if ((super = super_tone_rx_init(NULL, &desc, wakeup, (void *) "test")) == NULL)
    {
        printf("    Failed to create detector.\n");
        exit(2);
    }
    super_tone_rx_segment_callback(super, tone_segment);

    detection_range_tests(super);

    file_name = IN_FILE_NAME;
    file_decode_tests(super, file_name);

    talk_off_tests(super);

    super_tone_rx_free(super);
    printf("Done\n");
    return 0;
}
Example #2
0
int main(int argc, char *argv[])
{
    int x;
    int16_t amp[8000];
    int sample;
    int frames;
    awgn_state_t noise_source;
    super_tone_rx_state_t *super;
    super_tone_rx_descriptor_t desc;

    if ((inhandle = sf_open_telephony_read(IN_FILE_NAME, 1)) == NULL)
    {
        fprintf(stderr, "    Cannot open audio file '%s'\n", IN_FILE_NAME);
        exit(2);
    }
    super_tone_rx_make_descriptor(&desc);
#if defined(HAVE_LIBXML2)
    get_tone_set(&desc, "../spandsp/global-tones.xml", (argc > 1)  ?  argv[1]  :  "hk");
#endif
    super_tone_rx_fill_descriptor(&desc);
    if ((super = super_tone_rx_init(NULL, &desc, wakeup, (void *) "test")) == NULL)
    {
        printf("    Failed to create detector.\n");
        exit(2);
    }
    super_tone_rx_segment_callback(super, tone_segment);
    awgn_init_dbm0(&noise_source, 1234567, -30.0f);
    printf("Processing file\n");
    while ((frames = sf_readf_short(inhandle, amp, 8000)))
    {
        /* Add some noise to the signal for a more meaningful test. */
        //for (sample = 0;  sample < frames;  sample++)
        //    amp[sample] += saturate(amp[sample] + awgn (&noise_source));
        for (sample = 0;  sample < frames;  )
        {
            x = super_tone_rx(super, amp + sample, frames - sample);
            sample += x;
        }
    }
    if (sf_close_telephony(inhandle))
    {
        fprintf(stderr, "    Cannot close audio file '%s'\n", IN_FILE_NAME);
        exit(2);
    }
#if 0
    /* Test for voice immunity */
    for (j = 0;  bellcore_files[j][0];  j++)
    {
        if ((inhandle = sf_open_telephony_read(bellcore_files[j], 1)) == NULL)
        {
            printf("    Cannot open audio file '%s'\n", bellcore_files[j]);
            exit(2);
        }
        while ((frames = sf_readf_short(inhandle, amp, 8000)))
        {
            for (sample = 0;  sample < frames;  )
            {
                x = super_tone_rx(super, amp + sample, frames - sample);
                sample += x;
            }
        }
        if (sf_close_telephony(inhandle))
        {
            printf("    Cannot close speech file '%s'\n", bellcore_files[j]);
            exit(2);
        }
    }
#endif
    super_tone_rx_free(super);
    printf("Done\n");
    return 0;
}
/**
 * Initialize detector.  Call when media bug starts detection
 *
 * @param detector the detector to initialize
 */
static void tone_detector_init(tone_detector_t *detector)
{
	detector->spandsp_detector = super_tone_rx_init(NULL, detector->descriptor->spandsp_tone_descriptor, tone_report_callback, detector);
	super_tone_rx_segment_callback(detector->spandsp_detector, tone_segment_callback);
}
int main(int argc, char *argv[])
{
    int x;
    int16_t amp[8000];
    int sample;
    int frames;
    awgn_state_t noise_source;
    super_tone_rx_state_t *super;
    super_tone_rx_descriptor_t desc;

    if ((inhandle = afOpenFile(IN_FILE_NAME, "r", 0)) == AF_NULL_FILEHANDLE)
    {
        fprintf(stderr, "    Cannot open wave file '%s'\n", IN_FILE_NAME);
        exit(2);
    }
    if ((x = afGetFrameSize(inhandle, AF_DEFAULT_TRACK, 1)) != 2.0)
    {
        printf("    Unexpected frame size in wave file '%s'\n", IN_FILE_NAME);
        exit(2);
    }
    if ((x = afGetRate(inhandle, AF_DEFAULT_TRACK)) != (float) SAMPLE_RATE)
    {
        printf("    Unexpected sample rate in wave file '%s'\n", IN_FILE_NAME);
        exit(2);
    }
    if ((x = afGetChannels(inhandle, AF_DEFAULT_TRACK)) != 1.0)
    {
        printf("    Unexpected number of channels in wave file '%s'\n", IN_FILE_NAME);
        exit(2);
    }
    super_tone_rx_make_descriptor(&desc);
#if defined(HAVE_LIBXML2)
    get_tone_set(&desc, "../spandsp/global-tones.xml", (argc > 1)  ?  argv[1]  :  "hk");
#endif
    super_tone_rx_fill_descriptor(&desc);
    if ((super = super_tone_rx_init(NULL, &desc, wakeup, (void *) "test")) == NULL)
    {
        printf("    Failed to create detector.\n");
        exit(2);
    }
    super_tone_rx_segment_callback(super, tone_segment);
    awgn_init_dbm0(&noise_source, 1234567, -30.0f);
    printf("Processing file\n");
    while ((frames = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, 8000)))
    {
        /* Add some noise to the signal for a more meaningful test. */
        //for (sample = 0;  sample < frames;  sample++)
        //    amp[sample] += saturate(amp[sample] + awgn (&noise_source));
        for (sample = 0;  sample < frames;  )
        {
            x = super_tone_rx(super, amp + sample, frames - sample);
            sample += x;
        }
    }
    if (afCloseFile(inhandle))
    {
        fprintf(stderr, "    Cannot close audio file '%s'\n", IN_FILE_NAME);
        exit(2);
    }
#if 0
    /* Test for voice immunity */
    for (j = 0;  bellcore_files[j][0];  j++)
    {
        if ((inhandle = afOpenFile(bellcore_files[j], "r", 0)) == AF_NULL_FILEHANDLE)
        {
            printf("    Cannot open wave file '%s'\n", bellcore_files[j]);
            exit(2);
        }
        if ((x = afGetFrameSize(inhandle, AF_DEFAULT_TRACK, 1)) != 2.0)
        {
            printf("    Unexpected frame size in wave file '%s'\n", bellcore_files[j]);
            exit(2);
        }
        if ((x = afGetRate(inhandle, AF_DEFAULT_TRACK)) != (float) SAMPLE_RATE)
        {
            printf("    Unexpected sample rate in wave file '%s'\n", bellcore_files[j]);
            exit(2);
        }
        if ((x = afGetChannels(inhandle, AF_DEFAULT_TRACK)) != 1.0)
        {
            printf("    Unexpected number of channels in wave file '%s'\n", bellcore_files[j]);
            exit(2);
        }
        while ((frames = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, 8000)))
        {
            for (sample = 0;  sample < frames;  )
            {
                x = super_tone_rx(super, amp + sample, frames - sample);
                sample += x;
            }
    	}
        if (afCloseFile(inhandle) != 0)
    	{
    	    printf("    Cannot close speech file '%s'\n", bellcore_files[j]);
            exit(2);
    	}
    }
#endif
    super_tone_rx_free(super);
    printf("Done\n");
    return 0;
}