예제 #1
0
static void
name_test (int converter)
{	int k ;

	puts ("    name_test :") ;

	for (k = 0 ; k <= converter ; k++)
	{	printf ("\tName %d : %s\n", k, src_get_name (k)) ;
		printf ("\tDesc %d : %s\n", k, src_get_description (k)) ;
		} ;

	puts ("") ;

	return ;
} /* name_test */
예제 #2
0
static void
name_test (void)
{	const char	*name ;
	int	k = 0 ;

	puts ("    name_test :") ;

	while (1)
	{	name = src_get_name (k) ;
		if (name == NULL)
			break ;
		printf ("\tName %d : %s\n", k, name) ;
		printf ("\tDesc %d : %s\n", k, src_get_description (k)) ;
		k ++ ;
		} ;

	puts ("") ;

	return ;
} /* name_test */
예제 #3
0
PJ_DEF(pj_status_t) pjmedia_resample_create( pj_pool_t *pool,
					     pj_bool_t high_quality,
					     pj_bool_t large_filter,
					     unsigned channel_count,
					     unsigned rate_in,
					     unsigned rate_out,
					     unsigned samples_per_frame,
					     pjmedia_resample **p_resample)
{
    pjmedia_resample *resample;
    int type, err;

    PJ_ASSERT_RETURN(pool && p_resample && rate_in &&
		     rate_out && samples_per_frame, PJ_EINVAL);

    resample = PJ_POOL_ZALLOC_T(pool, pjmedia_resample);
    PJ_ASSERT_RETURN(resample, PJ_ENOMEM);

    /* Select conversion type */
    if (high_quality) {
	type = large_filter ? SRC_SINC_BEST_QUALITY : SRC_SINC_MEDIUM_QUALITY;
    } else {
	type = large_filter ? SRC_SINC_FASTEST : SRC_LINEAR;
    }

    /* Create converter */
    resample->state = src_new(type, channel_count, &err);
    if (resample->state == NULL) {
	PJ_LOG(4,(THIS_FILE, "Error creating resample: %s", 
		  src_strerror(err)));
	return PJMEDIA_ERROR;
    }

    /* Calculate ratio */
    resample->ratio = rate_out * 1.0 / rate_in;

    /* Calculate number of samples for input and output */
    resample->in_samples = samples_per_frame;
    resample->out_samples = rate_out / (rate_in / samples_per_frame);

    resample->frame_in = (float*) 
			 pj_pool_calloc(pool, 
					resample->in_samples + 8, 
					sizeof(float));

    resample->frame_out = (float*) 
			  pj_pool_calloc(pool, 
					 resample->out_samples + 8, 
					 sizeof(float));

    /* Set the converter ratio */
    err = src_set_ratio(resample->state, resample->ratio);
    if (err != 0) {
	PJ_LOG(4,(THIS_FILE, "Error creating resample: %s", 
		  src_strerror(err)));
	return PJMEDIA_ERROR;
    }

    /* Done */

    PJ_LOG(5,(THIS_FILE, 
	      "Resample using libsamplerate %s, type=%s (%s), "
	      "ch=%d, in/out rate=%d/%d", 
	      src_get_version(),
	      src_get_name(type), src_get_description(type),
	      channel_count, rate_in, rate_out));

    *p_resample = resample;

    return PJ_SUCCESS;
}
예제 #4
0
int
main (int argc, char *argv [])
{	CONVERTER_TEST snr_test_data [] =
	{
		{	SRC_ZERO_ORDER_HOLD,
			7,
			BOOLEAN_FALSE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	 36.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	 37.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	 37.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	 38.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	 14.0,	1.0 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	 32.0,	1.0 },
				{	1,	{ 0.3511111111 },		1.33,		1,	 10.0,	1.0 }
				}
			},

		{	SRC_LINEAR,
			7,
			BOOLEAN_FALSE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	 73.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	 74.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	 74.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	 77.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	 97.0,	0.94 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	 60.0,	0.95 },
				{	1,	{ 0.3511111111 },		1.33,		1,	 22.0,	0.99 }
				}
			},

		{	SRC_SINC_FASTEST,
			8,
			BOOLEAN_TRUE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	100.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	 97.0,	1.0 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	100.0,	0.5 },
				{	2,	{ 0.011111, 0.45 },		0.6,		1,	 97.0,	0.5 },
				{	1,	{ 0.3511111111 },		1.33,		1,	 97.0,	1.0 }
				}
			},

		{	SRC_SINC_MEDIUM_QUALITY,
			8,
			BOOLEAN_TRUE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	100.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	 97.0,	1.0 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	100.0,	0.5 },
				{	2,	{ 0.011111, 0.45 },		0.6,		1,	 97.0,	0.5 },
				{	1,	{ 0.43111111111 },		1.33,		1,	 97.0,	1.0 }
				}
			},

		{	SRC_SINC_BEST_QUALITY,
			8,
			BOOLEAN_TRUE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	100.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	 97.0,	1.0 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	100.0,	0.5 },
				{	2,	{ 0.011111, 0.45 },		0.6,		1,	 97.0,	0.5 },
				{	1,	{ 0.47111111111 },		1.33,		1,	 97.0,	1.0 }
				},
			},

	} ; /* snr_test_data */

	double	best_snr, snr, freq3dB, conversion_rate, worst_conv_rate ;
	int 	j, k, converter, verbose = 0 ;

	/* Force output of the Electric Fence banner message. */
	force_efence_banner () ;

	if (argc == 2 && strcmp (argv [1], "--verbose") == 0)
		verbose = 1 ;

	puts ("") ;

	for (j = 0 ; j < ARRAY_LEN (snr_test_data) ; j++)
	{	best_snr = 5000.0 ;
		worst_conv_rate = 1e200 ;

		converter = snr_test_data [j].converter ;

		printf ("    Converter %d : %s\n", converter, src_get_name (converter)) ;
		printf ("    %s\n", src_get_description (converter)) ;

		for (k = 0 ; k < snr_test_data [j].tests ; k++)
		{	snr = snr_test (&(snr_test_data [j].test_data [k]), k, converter, verbose, &conversion_rate) ;
			if (best_snr > snr)
				best_snr = snr ;
			if (worst_conv_rate > conversion_rate)
				worst_conv_rate = conversion_rate ;
			} ;

		printf ("    Worst case Signal-to-Noise Ratio : %.2f dB.\n", best_snr) ;
		printf ("    Worst case conversion rate       : %.0f samples/sec.\n", worst_conv_rate) ;

		if (snr_test_data [j].do_bandwidth_test == BOOLEAN_FALSE)
		{	puts ("    Bandwith test not performed on this converter.\n") ;
			continue ;
			}

		freq3dB = bandwidth_test (converter, verbose) ;

		printf ("    Measured -3dB rolloff point      : %5.2f %%.\n\n", freq3dB) ;
		} ;

	return 0 ;
} /* main */
예제 #5
0
파일: snr_bw_test.c 프로젝트: AugRob/ssr
int
main (int argc, char *argv [])
{	CONVERTER_TEST snr_test_data [] =
	{
		{	SRC_ZERO_ORDER_HOLD,
			8,
			BOOLEAN_FALSE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	 28.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	 36.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	 36.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.0,		1,	150.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	 38.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	 14.0,	.96 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	 12.0,	.96 },
				{	1,	{ 0.3511111111 },		1.33,		1,	 10.0,	1.0 }
				}
			},

		{	SRC_LINEAR,
			8,
			BOOLEAN_FALSE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	 73.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	 73.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	 73.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.0,		1,	150.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	 77.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	 16.0,	0.96 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	 26.0,	0.96 },
				{	1,	{ 0.3511111111 },		1.33,		1,	 14.4,	0.99 }
				}
			},

		{	SRC_SINC_FASTEST,
			9,
			BOOLEAN_TRUE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	 99.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	100.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.0,		1,	150.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	100.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	 97.0,	1.0 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	100.0,	0.5 },
				{	2,	{ 0.011111, 0.45 },		0.6,		1,	 97.0,	0.5 },
				{	1,	{ 0.3511111111 },		1.33,		1,	 97.0,	1.0 }
				}
			},

		{	SRC_SINC_MEDIUM_QUALITY,
			9,
			BOOLEAN_TRUE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	130.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	132.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	138.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.0,		1,	155.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	134.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	127.0,	1.0 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	124.0,	0.5 },
				{	2,	{ 0.011111, 0.45 },		0.6,		1,	126.0,	0.5 },
				{	1,	{ 0.43111111111 },		1.33,		1,	121.0,	1.0 }
				}
			},

		{	SRC_SINC_BEST_QUALITY,
			9,
			BOOLEAN_TRUE,
			{	{	1,	{ 0.01111111111 },		3.0,		1,	147.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.6,		1,	147.0,	1.0 },
				{	1,	{ 0.01111111111 },		0.3,		1,	147.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.0,		1,	155.0,	1.0 },
				{	1,	{ 0.01111111111 },		1.001,		1,	147.0,	1.0 },
				{	2,	{ 0.011111, 0.324 },	1.9999,		2,	147.0,	1.0 },
				{	2,	{ 0.012345, 0.457 },	0.456789,	1,	148.0,	0.5 },
				{	2,	{ 0.011111, 0.45 },		0.6,		1,	149.0,	0.5 },
				{	1,	{ 0.43111111111 },		1.33,		1,	145.0,	1.0 }
				}
			},
		} ; /* snr_test_data */

	double	best_snr, snr, freq3dB ;
	int 	j, k, converter, verbose = 0 ;

	if (argc == 2 && strcmp (argv [1], "--verbose") == 0)
		verbose = 1 ;

	puts ("") ;

	for (j = 0 ; j < ARRAY_LEN (snr_test_data) ; j++)
	{	best_snr = 5000.0 ;

		converter = snr_test_data [j].converter ;

		printf ("    Converter %d : %s\n", converter, src_get_name (converter)) ;
		printf ("    %s\n", src_get_description (converter)) ;

		for (k = 0 ; k < snr_test_data [j].tests ; k++)
		{	snr = snr_test (&(snr_test_data [j].test_data [k]), k, converter, verbose) ;
			if (best_snr > snr)
				best_snr = snr ;
			} ;

		printf ("    Worst case Signal-to-Noise Ratio : %.2f dB.\n", best_snr) ;

		if (snr_test_data [j].do_bandwidth_test == BOOLEAN_FALSE)
		{	puts ("    Bandwith test not performed on this converter.\n") ;
			continue ;
			}

		freq3dB = bandwidth_test (converter, verbose) ;

		printf ("    Measured -3dB rolloff point      : %5.2f %%.\n\n", freq3dB) ;
		} ;

	return 0 ;
} /* main */