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

📄 header_test.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* Now write some frames. */	frames = ARRAY_LEN (buffer) / sfinfo.channels ;	for (k = 0 ; k < 6 ; k++)	{	test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ;		test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ;		/* Open file again and make sure no errors in log buffer. */		infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;		check_log_buffer_or_die (infile, __LINE__) ;		sf_close (infile) ;		if (sfinfo.frames != k * frames)		{	printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ;			dump_log_buffer (infile) ;			exit (1) ;			} ;		if ((k & 1) == 0)			test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ;		else			test_writef_short_or_die (outfile, k, buffer, frames, __LINE__) ;		} ;	sf_close (outfile) ;	unlink (filename) ;	puts ("ok") ;	return ;} /* update_seek_short_test */static voidupdate_seek_int_test	(const char *filename, int filetype){	SNDFILE *outfile, *infile ;	SF_INFO sfinfo ;    sf_count_t frames ;    int buffer [8] ;	int k ;	print_test_name ("update_seek_int_test", filename) ;	memset (buffer, 0, sizeof (buffer)) ;	/* Create sound outfile with no data. */	sfinfo.format = filetype | SF_FORMAT_PCM_32 ;	sfinfo.samplerate = 48000 ;	sfinfo.channels = 2 ;	if (sf_format_check (&sfinfo) == SF_FALSE)		sfinfo.channels = 1 ;	outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;	sf_close (outfile) ;	/* Open again for read/write. */	outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;	/*	** In auto header update mode, seeking to the end of the file with    ** SEEK_SET will fail from the 2nd seek on.  seeking to 0, SEEK_END	** will seek to 0 anyway	*/	if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)    {	printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;		exit (1) ;		} ;	/* Now write some frames. */	frames = ARRAY_LEN (buffer) / sfinfo.channels ;	for (k = 0 ; k < 6 ; k++)	{	test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ;		test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ;		/* Open file again and make sure no errors in log buffer. */		infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;		check_log_buffer_or_die (infile, __LINE__) ;		sf_close (infile) ;		if (sfinfo.frames != k * frames)		{	printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ;			dump_log_buffer (infile) ;			exit (1) ;			} ;		if ((k & 1) == 0)			test_write_int_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ;		else			test_writef_int_or_die (outfile, k, buffer, frames, __LINE__) ;		} ;	sf_close (outfile) ;	unlink (filename) ;	puts ("ok") ;	return ;} /* update_seek_int_test */static voidupdate_seek_float_test	(const char *filename, int filetype){	SNDFILE *outfile, *infile ;	SF_INFO sfinfo ;    sf_count_t frames ;    float buffer [8] ;	int k ;	print_test_name ("update_seek_float_test", filename) ;	memset (buffer, 0, sizeof (buffer)) ;	/* Create sound outfile with no data. */	sfinfo.format = filetype | SF_FORMAT_FLOAT ;	sfinfo.samplerate = 48000 ;	sfinfo.channels = 2 ;	if (sf_format_check (&sfinfo) == SF_FALSE)		sfinfo.channels = 1 ;	outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;	sf_close (outfile) ;	/* Open again for read/write. */	outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;	/*	** In auto header update mode, seeking to the end of the file with    ** SEEK_SET will fail from the 2nd seek on.  seeking to 0, SEEK_END	** will seek to 0 anyway	*/	if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)    {	printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;		exit (1) ;		} ;	/* Now write some frames. */	frames = ARRAY_LEN (buffer) / sfinfo.channels ;	for (k = 0 ; k < 6 ; k++)	{	test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ;		test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ;		/* Open file again and make sure no errors in log buffer. */		infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;		check_log_buffer_or_die (infile, __LINE__) ;		sf_close (infile) ;		if (sfinfo.frames != k * frames)		{	printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ;			dump_log_buffer (infile) ;			exit (1) ;			} ;		if ((k & 1) == 0)			test_write_float_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ;		else			test_writef_float_or_die (outfile, k, buffer, frames, __LINE__) ;		} ;	sf_close (outfile) ;	unlink (filename) ;	puts ("ok") ;	return ;} /* update_seek_float_test */static voidupdate_seek_double_test	(const char *filename, int filetype){	SNDFILE *outfile, *infile ;	SF_INFO sfinfo ;    sf_count_t frames ;    double buffer [8] ;	int k ;	print_test_name ("update_seek_double_test", filename) ;	memset (buffer, 0, sizeof (buffer)) ;	/* Create sound outfile with no data. */	sfinfo.format = filetype | SF_FORMAT_DOUBLE ;	sfinfo.samplerate = 48000 ;	sfinfo.channels = 2 ;	if (sf_format_check (&sfinfo) == SF_FALSE)		sfinfo.channels = 1 ;	outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;	sf_close (outfile) ;	/* Open again for read/write. */	outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;	/*	** In auto header update mode, seeking to the end of the file with    ** SEEK_SET will fail from the 2nd seek on.  seeking to 0, SEEK_END	** will seek to 0 anyway	*/	if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)    {	printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;		exit (1) ;		} ;	/* Now write some frames. */	frames = ARRAY_LEN (buffer) / sfinfo.channels ;	for (k = 0 ; k < 6 ; k++)	{	test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ;		test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ;		/* Open file again and make sure no errors in log buffer. */		infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;		check_log_buffer_or_die (infile, __LINE__) ;		sf_close (infile) ;		if (sfinfo.frames != k * frames)		{	printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", __LINE__, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ;			dump_log_buffer (infile) ;			exit (1) ;			} ;		if ((k & 1) == 0)			test_write_double_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ;		else			test_writef_double_or_die (outfile, k, buffer, frames, __LINE__) ;		} ;	sf_close (outfile) ;	unlink (filename) ;	puts ("ok") ;	return ;} /* update_seek_double_test */static voidextra_header_test (const char *filename, int filetype){	SNDFILE *outfile, *infile ;	SF_INFO sfinfo ;    sf_count_t frames ;    short buffer [8] ;	int k = 0 ;	print_test_name ("extra_header_test", filename) ;	sfinfo.samplerate = 44100 ;	sfinfo.format = (filetype | SF_FORMAT_PCM_16) ;	sfinfo.channels = 1 ;	memset (buffer, 0xA0, sizeof (buffer)) ;	/* Now write some frames. */	frames = ARRAY_LEN (buffer) / sfinfo.channels ;	/* Test the file with extra header data. */	outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, 399) ;	sf_set_string (outfile, SF_STR_TITLE, filename) ;	test_writef_short_or_die (outfile, k, buffer, frames, 401) ;	sf_set_string (outfile, SF_STR_COPYRIGHT, "(c) 1980 Erik") ;	sf_close (outfile) ;#if 1	/*	**  Erik de Castro Lopo <erikd@mega-nerd.com> May 23 2004.	**	** This file has extra string data in the header and therefore cannot	** currently be opened in SFM_RDWR mode. This is fixable, but its in	** a part of the code I don't want to fiddle with until the Ogg/Vorbis	** integration is done.	*/	if ((infile = sf_open (filename, SFM_RDWR, &sfinfo)) != NULL)	{	printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ;		exit (1) ;		} ;	unlink (filename) ;	puts ("ok") ;	return ;#else	hexdump_file (filename, 0, 100000) ;	/* Open again for read/write. */	outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, 428) ;	/*	** In auto header update mode, seeking to the end of the file with    ** SEEK_SET will fail from the 2nd seek on.  seeking to 0, SEEK_END	** will seek to 0 anyway	*/	if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)    {	printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;		exit (1) ;		} ;	/* Now write some frames. */	frames = ARRAY_LEN (buffer) / sfinfo.channels ;	for (k = 1 ; k < 6 ; k++)	{		printf ("\n*** pass %d\n", k) ;		memset (buffer, 0xA0 + k, sizeof (buffer)) ;		test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, 449) ;		test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, 450) ;		/* Open file again and make sure no errors in log buffer. */		if (0)		{	infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, 454) ;			check_log_buffer_or_die (infile, 455) ;			sf_close (infile) ;			} ;		if (sfinfo.frames != k * frames)		{	printf ("\n\nLine %d : Incorrect sample count (%ld should be %ld)\n", 460, SF_COUNT_TO_LONG (sfinfo.frames), SF_COUNT_TO_LONG (k + frames)) ;			dump_log_buffer (infile) ;			exit (1) ;			} ;		if ((k & 1) == 0)			test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, 466) ;		else			test_writef_short_or_die (outfile, k, buffer, frames, 468) ;		hexdump_file (filename, 0, 100000) ;		} ;	sf_close (outfile) ;	unlink (filename) ;	puts ("ok") ;	return ;#endif} /* extra_header_test */

⌨️ 快捷键说明

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