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;
}
/**
 * Allocate the tone descriptor
 *
 * @param descriptor the descriptor to create
 * @param name the descriptor name 
 * @param memory_pool the pool to use
 * @return SWITCH_STATUS_SUCCESS if successful
 */
switch_status_t tone_descriptor_create(tone_descriptor_t **descriptor, const char *name, switch_memory_pool_t *memory_pool)
{
	tone_descriptor_t *ldescriptor = NULL;
	ldescriptor = switch_core_alloc(memory_pool, sizeof(tone_descriptor_t));
	if (!ldescriptor) {
		return SWITCH_STATUS_FALSE;
	}
	memset(ldescriptor, 0, sizeof(tone_descriptor_t));
	ldescriptor->name = switch_core_strdup(memory_pool, name);
	ldescriptor->spandsp_tone_descriptor = super_tone_rx_make_descriptor(NULL);
	*descriptor = ldescriptor;
	return SWITCH_STATUS_SUCCESS;
}
Example #3
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;
}
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;
}