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

📄 lossy_comp_test.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 5 页
字号:
		lcomp_test_int		("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;		lcomp_test_float	("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;		lcomp_test_double	("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;		sdlcomp_test_short	("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;		sdlcomp_test_int	("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;		sdlcomp_test_float	("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;		sdlcomp_test_double	("ima.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM, 2, 0.18) ;		test_count++ ;		} ;	if (do_all || ! strcmp (argv [1], "w64_msadpcm"))	{	lcomp_test_short	("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;		lcomp_test_int		("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;		lcomp_test_float	("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;		lcomp_test_double	("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;		sdlcomp_test_short	("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;		sdlcomp_test_int	("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;		sdlcomp_test_float	("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;		sdlcomp_test_double	("msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM, 2, 0.36) ;		test_count++ ;		} ;	/* Lite remove end */	if (do_all || ! strcmp (argv [1], "w64_gsm610"))	{	/* Don't do lcomp_test_XXX as the errors are too big. */		sdlcomp_test_short	("gsm610.w64", SF_FORMAT_W64 | SF_FORMAT_GSM610, 1, 0.2) ;		sdlcomp_test_int	("gsm610.w64", SF_FORMAT_W64 | SF_FORMAT_GSM610, 1, 0.2) ;		/* Lite remove start */		sdlcomp_test_float	("gsm610.w64", SF_FORMAT_W64 | SF_FORMAT_GSM610, 1, 0.2) ;		sdlcomp_test_double	("gsm610.w64", SF_FORMAT_W64 | SF_FORMAT_GSM610, 1, 0.2) ;		/* Lite remove end */		test_count++ ;		} ;	/* Lite remove start */	if (do_all || ! strcmp (argv [1], "vox_adpcm"))	{	lcomp_test_short	("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.17) ;		lcomp_test_int		("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.17) ;		lcomp_test_float	("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.17) ;		lcomp_test_double	("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.17) ;		sdlcomp_test_short	("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.072) ;		sdlcomp_test_int	("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.072) ;		sdlcomp_test_float	("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.072) ;		sdlcomp_test_double	("adpcm.vox", SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, 1, 0.072) ;		test_count++ ;		} ;	if (do_all || ! strcmp (argv [1], "xi_dpcm"))	{	lcomp_test_short	("8bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_8, 1, 0.25) ;		lcomp_test_int		("8bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_8, 1, 0.25) ;		lcomp_test_short	("16bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16, 1, 0.002) ;		lcomp_test_int		("16bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16, 1, 0.002) ;		lcomp_test_float	("16bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16, 1, 0.002) ;		lcomp_test_double	("16bit.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16, 1, 0.002) ;		test_count++ ;		} ;	/* Lite remove end */	if (test_count == 0)	{	printf ("************************************\n") ;		printf ("*  No '%s' test defined.\n", argv [1]) ;		printf ("************************************\n") ;		return 1 ;		} ;	return 0 ;} /* main *//*============================================================================================**	Here are the test functions.*/static voidlcomp_test_short (const char *filename, int filetype, int channels, double margin){	SNDFILE			*file ;	SF_INFO			sfinfo ;	int				k, m, seekpos, sum_abs ;	long			datalen ;	short			*orig, *data ;	print_test_name ("lcomp_test_short", filename) ;	datalen = BUFFER_SIZE / channels ;	data = (short*) data_buffer ;	orig = (short*) orig_buffer ;	gen_signal_double (orig_buffer, 32000.0, channels, datalen) ;	for (k = 0 ; k < channels * datalen ; k++)		orig [k] = (short) (orig_buffer [k]) ;	sfinfo.samplerate	= SAMPLE_RATE ;	sfinfo.frames		= 123456789 ;	/* Ridiculous value. */	sfinfo.channels		= channels ;	sfinfo.format		= filetype ;	if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))	{	printf ("sf_open_write failed with error : ") ;		fflush (stdout) ;		puts (sf_strerror (NULL)) ;		exit (1) ;		} ;	if ((k = sf_writef_short (file, orig, datalen)) != datalen)	{	printf ("sf_writef_short failed with short write (%ld => %d).\n", datalen, k) ;		exit (1) ;		} ;	sf_close (file) ;	memset (data, 0, datalen * sizeof (short)) ;	if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)		memset (&sfinfo, 0, sizeof (sfinfo)) ;	if (! (file = sf_open (filename, SFM_READ, &sfinfo)))	{	printf ("Line %d: sf_open_read failed with error : ", __LINE__) ;		puts (sf_strerror (NULL)) ;		exit (1) ;		} ;	if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))	{	printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;		exit (1) ;		} ;	if (sfinfo.frames < datalen / channels)	{	printf ("Too few frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;		exit (1) ;		} ;	if (sfinfo.frames > (datalen + datalen / 2))	{	printf ("Too many frames in file. (%ld should be a little more than %ld)\n", SF_COUNT_TO_LONG (sfinfo.frames), datalen) ;		exit (1) ;		} ;	if (sfinfo.channels != channels)	{	printf ("Incorrect number of channels in file.\n") ;		exit (1) ;		} ;	check_log_buffer_or_die (file, __LINE__) ;	if ((k = sf_readf_short (file, data, datalen)) != datalen)	{	printf ("Line %d: short read (%d should be %ld).\n", __LINE__, k, datalen) ;		exit (1) ;		} ;	sum_abs = 0 ;	for (k = 0 ; k < datalen ; k++)	{	if (error_function (data [k], orig [k], margin))		{	printf ("Line %d: Incorrect sample A (#%d : %d should be %d).\n", __LINE__, k, data [k], orig [k]) ;			oct_save_short (orig, data, datalen) ;			exit (1) ;			} ;		sum_abs = abs (sum_abs + abs (data [k])) ;		} ;	if (sum_abs < 1.0)	{	printf ("Line %d: Signal is all zeros.\n", __LINE__) ;		exit (1) ;		} ;	if ((k = sf_readf_short (file, data, datalen)) != sfinfo.frames - datalen)	{	printf ("Line %d: Incorrect read length (%ld should be %d).\n", __LINE__,			SF_COUNT_TO_LONG (channels * sfinfo.frames - datalen), k) ;		exit (1) ;		} ;	/*	This check is only for block based encoders which must append silence	**	to the end of a file so as to fill out a block.	*/	for (k = 0 ; k < sfinfo.frames - datalen ; k++)		if (abs (data [channels * k]) > decay_response (channels * k))		{	printf ("Line %d : Incorrect sample B (#%d : abs (%d) should be < %d).\n", __LINE__, channels * k, data [channels * k], decay_response (channels * k)) ;			exit (1) ;			} ;	if (! sfinfo.seekable)	{	unlink (filename) ;		printf ("ok\n") ;		return ;		} ;	/* Now test sf_seek function. */	if ((k = sf_seek (file, 0, SEEK_SET)) != 0)	{	printf ("Line %d: Seek to start of file failed (%d).\n", __LINE__, k) ;		exit (1) ;		} ;	for (m = 0 ; m < 3 ; m++)	{	if ((k = sf_readf_short (file, data, 11)) != 11)		{	printf ("Line %d: Incorrect read length (11 => %d).\n", __LINE__, k) ;			exit (1) ;			} ;		for (k = 0 ; k < channels * 11 ; k++)			if (error_function ((double) data [k], (double) orig [k + channels * m * 11], margin))			{	printf ("Line %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__, m, k + channels * m * 11, orig [k + channels * m * 11], data [k]) ;				for (m = 0 ; m < channels ; m++)					printf ("%d ", data [m]) ;				printf ("\n") ;				exit (1) ;				} ;		} ;	seekpos = BUFFER_SIZE / 10 ;	/* Check seek from start of file. */	if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)	{	printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;		exit (1) ;		} ;	if ((k = sf_readf_short (file, data, 1)) != 1)	{	printf ("Line %d: sf_readf_short (file, data, 1) returned %d.\n", __LINE__, k) ;		exit (1) ;		} ;	if (error_function ((double) data [0], (double) orig [seekpos * channels], margin))	{	printf ("Line %d: sf_seek (SEEK_SET) followed by sf_readf_short failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;		exit (1) ;		} ;	if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)	{	printf ("Line %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;		exit (1) ;		} ;	seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;	k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;	sf_readf_short (file, data, 1) ;	if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)	{	printf ("Line %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;oct_save_short (orig, data, datalen) ;		exit (1) ;		} ;	seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;	/* Check seek backward from current position. */	k = sf_seek (file, -20, SEEK_CUR) ;	sf_readf_short (file, data, 1) ;	if (error_function ((double) data [0], (double) orig [seekpos * channels], margin) || k != seekpos)	{	printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", data [0], orig [seekpos * channels], k, seekpos) ;		exit (1) ;		} ;	/* Check that read past end of file returns number of items. */	sf_seek (file, (short) sfinfo.frames, SEEK_SET) ; 	if ((k = sf_readf_short (file, data, datalen)) != 0) 	{	printf ("Line %d: Return value from sf_readf_short past end of file incorrect (%d).\n", __LINE__, k) ; 		exit (1) ; 		} ;	/* Check seek backward from end. */	if ((k = sf_seek (file, 5 - (short) sfinfo.frames, SEEK_END)) != 5)	{	printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;		exit (1) ;		} ;	sf_readf_short (file, data, channels) ;	if (error_function ((double) data [0], (double) orig [5], margin))	{	printf ("Line %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;		exit (1) ;		} ;	sf_close (file) ;	unlink (filename) ;	printf ("ok\n") ;} /* lcomp_test_short *//*--------------------------------------------------------------------------------------------*/static voidlcomp_test_int (const char *filename, int filetype, int channels, double margin){	SNDFILE		*file ;	SF_INFO		sfinfo ;	int			k, m, *orig, *data, sum_abs ;	long		datalen, seekpos ;	double		scale ;	print_test_name ("lcomp_test_int", filename) ;	datalen = BUFFER_SIZE / channels ;	scale = 1.0 * 0x10000 ;	data = (int*) data_buffer ;	orig = (int*) orig_buffer ;	gen_signal_double (orig_buffer, 32000.0 * scale, channels, datalen) ;	for (k = 0 ; k < channels * datalen ; k++)		orig [k] = orig_buffer [k] ;	sfinfo.samplerate	= SAMPLE_RATE ;	sfinfo.frames		= 123456789 ;	/* Ridiculous value. */	sfinfo.channels		= channels ;	sfinfo.format		= filetype ;	if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))	{	printf ("sf_open_write failed with error : ") ;		puts (sf_strerror (NULL)) ;		exit (1) ;		} ;	if ((k = sf_writef_int (file, orig, datalen)) != datalen)	{	printf ("sf_writef_int failed with short write (%ld => %d).\n", datalen, k) ;		exit (1) ;		} ;	sf_close (file) ;	memset (data, 0, datalen * sizeof (int)) ;	if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)		memset (&sfinfo, 0, sizeof (sfinfo)) ;	if (! (file = sf_open (filename, SFM_READ, &sfinfo)))	{	printf ("sf_open_read failed with error : ") ;		puts (sf_strerror (NULL)) ;		exit (1) ;		} ;	if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))	{	printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;		exit (1) ;		} ;	if (sfinfo.frames < datalen / channels)	{	printf ("Too few.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;		exit (1) ;		} ;	if (sfinfo.frames > (datalen + datalen / 2))	{	printf ("Too many.frames in file. (%ld should be a little more than %ld)\n", datalen, SF_COUNT_TO_LONG (sfinfo.frames)) ;		exit (1) ;		} ;	if (sfinfo.channels != channels)	{	printf ("Incorrect number of channels in file.\n") ;		exit (1) ;		} ;	check_log_buffer_or_die (file, __LINE__) ;	if ((k = sf_readf_int (file, data, datalen)) != datalen)	{	printf ("Line %d: short read (%d should be %ld).\n", __LINE__, k, datalen) ;		exit (1) ;		} ;

⌨️ 快捷键说明

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