⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 command_test.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (sfinfo.channels != 1)	{	printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;		exit (1) ;		} ;	/* Read double_data and check that it is normalised (ie default). */	if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)	{	printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;		exit (1) ;		} ;	for (k = 0 ; k < BUFFER_LEN ; k++)		if (double_data [k] >= 1.0)		{	printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__, k, double_data [k]) ;			exit (1) ;			} ;	/* Seek to start of file, turn normalisation off, read double_data and check again. */	sf_seek (file, 0, SEEK_SET) ;	sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;	if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)	{	printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;		exit (1) ;		} ;	for (k = 0 ; k < BUFFER_LEN ; k++)		if (double_data [k] < 1.0)		{	printf ("\n\nLine %d: double_data [%d] == %f which is less than 1.0\n", __LINE__, k, double_data [k]) ;			exit (1) ;			} ;	/* Seek to start of file, turn normalisation on, read double_data and do final check. */	sf_seek (file, 0, SEEK_SET) ;	sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ;	if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)	{	printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;		exit (1) ;		} ;	for (k = 0 ; k < BUFFER_LEN ; k++)		if (double_data [k] > 1.0)		{	printf ("\n\nLine %d: double_data [%d] == %f which is greater than 1.0\n", __LINE__, k, double_data [k]) ;			exit (1) ;			} ;	sf_close (file) ;	unlink (filename) ;	printf ("ok\n") ;} /* double_norm_test */static	voidformat_tests	(void){	SF_FORMAT_INFO format_info ;	SF_INFO		sfinfo ;	const char	*last_name ;	int 		k, count ;	print_test_name ("format_tests", "(null)") ;	/* Clear out SF_INFO struct and set channels > 0. */	memset (&sfinfo, 0, sizeof (sfinfo)) ;	sfinfo.channels = 1 ;	/* First test simple formats. */	sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;	if (count < 0 || count > 30)	{	printf ("Line %d: Weird count.\n", __LINE__) ;		exit (1) ;		} ;	format_info.format = 0 ;	sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ;	last_name = format_info.name ;	for (k = 1 ; k < count ; k ++)	{	format_info.format = k ;		sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ;		if (strcmp (last_name, format_info.name) >= 0)		{	printf ("\n\nLine %d: format names out of sequence `%s' < `%s'.\n", __LINE__, last_name, format_info.name) ;			exit (1) ;			} ;		sfinfo.format = format_info.format ;		if (! sf_format_check (&sfinfo))		{	printf ("\n\nLine %d: sf_format_check failed.\n", __LINE__) ;			printf ("        Name : %s\n", format_info.name) ;			printf ("        Format      : 0x%X\n", sfinfo.format) ;			printf ("        Channels    : 0x%X\n", sfinfo.channels) ;			printf ("        Sample Rate : 0x%X\n", sfinfo.samplerate) ;			exit (1) ;			} ;		last_name = format_info.name ;		} ;	format_info.format = 666 ;	sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ;	/* Now test major formats. */	sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ;	if (count < 0 || count > 30)	{	printf ("Line %d: Weird count.\n", __LINE__) ;		exit (1) ;		} ;	format_info.format = 0 ;	sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ;	last_name = format_info.name ;	for (k = 1 ; k < count ; k ++)	{	format_info.format = k ;		sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ;		if (strcmp (last_name, format_info.name) >= 0)		{	printf ("\n\nLine %d: format names out of sequence (%d) `%s' < `%s'.\n", __LINE__, k, last_name, format_info.name) ;			exit (1) ;			} ;		last_name = format_info.name ;		} ;	format_info.format = 666 ;	sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ;	/* Now test subtype formats. */	sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;	if (count < 0 || count > 30)	{	printf ("Line %d: Weird count.\n", __LINE__) ;		exit (1) ;		} ;	format_info.format = 0 ;	sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;	last_name = format_info.name ;	for (k = 1 ; k < count ; k ++)	{	format_info.format = k ;		sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;		} ;	format_info.format = 666 ;	sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;	printf ("ok\n") ;} /* format_tests */static	voidcalc_peak_test (int filetype, const char *filename){	SNDFILE		*file ;	SF_INFO		sfinfo ;	int			k, format ;	double		peak ;	print_test_name ("calc_peak_test", filename) ;	format = (filetype | SF_FORMAT_PCM_16) ;	sfinfo.samplerate	= 44100 ;	sfinfo.format		= format ;	sfinfo.channels		= 1 ;	sfinfo.frames		= BUFFER_LEN ;	/* Create double_data with max value of 0.5. */	for (k = 0 ; k < BUFFER_LEN ; k++)		double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ;	file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;	test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;	sf_close (file) ;	file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;	if (sfinfo.format != format)	{	printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;		exit (1) ;		} ;	if (sfinfo.frames != BUFFER_LEN)	{	printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;		exit (1) ;		} ;	if (sfinfo.channels != 1)	{	printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;		exit (1) ;		} ;	sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ;	if (fabs (peak - (1 << 14)) > 1.0)	{	printf ("Line %d : Peak value should be %d (is %f).\n", __LINE__, (1 << 14), peak) ;		exit (1) ;		} ;	sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ;	if (fabs (peak - 0.5) > 4e-5)	{	printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ;		exit (1) ;		} ;	sf_close (file) ;	format = (filetype | SF_FORMAT_FLOAT) ;	sfinfo.samplerate	= 44100 ;	sfinfo.format		= format ;	sfinfo.channels		= 1 ;	sfinfo.frames		= BUFFER_LEN ;	/* Create double_data with max value of 0.5. */	for (k = 0 ; k < BUFFER_LEN ; k++)		double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ;	file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;	test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;	sf_close (file) ;	file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;	if (sfinfo.format != format)	{	printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ;		exit (1) ;		} ;	if (sfinfo.frames != BUFFER_LEN)	{	printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;		exit (1) ;		} ;	if (sfinfo.channels != 1)	{	printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;		exit (1) ;		} ;	sf_command (file, SFC_CALC_SIGNAL_MAX, &peak, sizeof (peak)) ;	if (fabs (peak - 0.5) > 1e-5)	{	printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ;		exit (1) ;		} ;	sf_command (file, SFC_CALC_NORM_SIGNAL_MAX, &peak, sizeof (peak)) ;	if (fabs (peak - 0.5) > 1e-5)	{	printf ("Line %d : Peak value should be %f (is %f).\n", __LINE__, 0.5, peak) ;		exit (1) ;		} ;	sf_close (file) ;	unlink (filename) ;	printf ("ok\n") ;} /* calc_peak_test */static voidtruncate_test (const char *filename, int filetype){	SNDFILE 	*file ;	SF_INFO		sfinfo ;	sf_count_t	len ;	int			*int_data ;	print_test_name ("truncate_test", filename) ;	sfinfo.samplerate	= 11025 ;	sfinfo.format		= filetype ;	sfinfo.channels		= 2 ;	int_data = (int*) double_data ;	file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;	test_write_int_or_die (file, 0, int_data, BUFFER_LEN, __LINE__) ;	len = 100 ;	if (sf_command (file, SFC_FILE_TRUNCATE, &len, sizeof (len)))	{	printf ("Line %d: sf_command (SFC_FILE_TRUNCATE) returned error.\n", __LINE__) ;		exit (1) ;		} ;	test_seek_or_die (file, 0, SEEK_CUR, len, 2, __LINE__) ;	test_seek_or_die (file, 0, SEEK_END, len, 2, __LINE__) ;	sf_close (file) ;	unlink (filename) ;	puts ("ok") ;} /* truncate_test */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -