コード例 #1
0
ファイル: ogg_test.c プロジェクト: DannyDaemonic/libsndfile
static void
ogg_float_test (void)
{	const char * filename = "vorbis_float.oga" ;

	SNDFILE * file ;
	SF_INFO sfinfo ;
	float seek_data [10] ;

	print_test_name ("ogg_float_test", filename) ;

	gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 0.95) ;

	memset (&sfinfo, 0, sizeof (sfinfo)) ;

	/* Set up output file type. */
	sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ;
	sfinfo.channels = 1 ;
	sfinfo.samplerate = SAMPLE_RATE ;

	/* Write the output file. */
	file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
	test_write_float_or_die (file, 0, data_out.f, ARRAY_LEN (data_out.f), __LINE__) ;
	sf_close (file) ;

	/* Read the file in again. */
	memset (&sfinfo, 0, sizeof (sfinfo)) ;

	file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
	test_read_float_or_die (file, 0, data_in.f, ARRAY_LEN (data_in.f), __LINE__) ;
	sf_close (file) ;

	puts ("ok") ;

	/* Test seeking. */
	print_test_name ("ogg_seek_test", filename) ;

	file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;

	test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
	test_read_float_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
	compare_float_or_die (seek_data, data_in.f + 10, ARRAY_LEN (seek_data), __LINE__) ;

	sf_close (file) ;

	puts ("ok") ;

	unlink (filename) ;
} /* ogg_float_test */
コード例 #2
0
static void
header_shrink_test (const char *filename, int filetype)
{	SNDFILE *outfile, *infile ;
	SF_INFO sfinfo ;
	sf_count_t frames ;
	float buffer [8], bufferin [8] ;

	print_test_name ("header_shrink_test", filename) ;

	memset (&sfinfo, 0, sizeof (sfinfo)) ;
	sfinfo.samplerate = 44100 ;
	sfinfo.format = filetype | SF_FORMAT_FLOAT ;
	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_FALSE, __LINE__) ;

	sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
	sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, SF_FALSE) ;
	sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;

	test_writef_float_or_die (outfile, 0, buffer, frames, __LINE__) ;
	sf_close (outfile) ;

	/* Open again for read. */
	infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;

	test_readf_float_or_die (infile, 0, bufferin, frames, __LINE__) ;
	sf_close (infile) ;

	compare_float_or_die (buffer, bufferin, frames, __LINE__) ;

	unlink (filename) ;
	puts ("ok") ;
	return ;
} /* header_shrink_test */
コード例 #3
0
ファイル: ogg_test.c プロジェクト: DannyDaemonic/libsndfile
static void
ogg_stereo_seek_test (const char * filename, int format)
{	static float data [SAMPLE_RATE] ;
	static float stereo_out [SAMPLE_RATE * 2] ;

	SNDFILE * file ;
	SF_INFO sfinfo ;
	sf_count_t pos ;
	unsigned k ;

	print_test_name (__func__, filename) ;

	gen_windowed_sine_float (data, ARRAY_LEN (data), 0.95) ;
	for (k = 0 ; k < ARRAY_LEN (data) ; k++)
	{	stereo_out [2 * k] = data [k] ;
		stereo_out [2 * k + 1] = data [ARRAY_LEN (data) - k - 1] ;
		} ;

	memset (&sfinfo, 0, sizeof (sfinfo)) ;

	/* Set up output file type. */
	sfinfo.format = format ;
	sfinfo.channels = 2 ;
	sfinfo.samplerate = SAMPLE_RATE ;

	/* Write the output file. */
	file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
	test_write_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
	sf_close (file) ;

	/* Open file in again for reading. */
	memset (&sfinfo, 0, sizeof (sfinfo)) ;
	file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;

	/* Read in the whole file. */
	test_read_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;

	/* Now hammer seeking code. */
	test_seek_or_die (file, 234, SEEK_SET, 234, sfinfo.channels, __LINE__) ;
	test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
	compare_float_or_die (data, stereo_out + (234 * sfinfo.channels), 10, __LINE__) ;

	test_seek_or_die (file, 442, SEEK_SET, 442, sfinfo.channels, __LINE__) ;
	test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
	compare_float_or_die (data, stereo_out + (442 * sfinfo.channels), 10, __LINE__) ;

	test_seek_or_die (file, 12, SEEK_CUR, 442 + 10 + 12, sfinfo.channels, __LINE__) ;
	test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
	compare_float_or_die (data, stereo_out + ((442 + 10 + 12) * sfinfo.channels), 10, __LINE__) ;

	test_seek_or_die (file, 12, SEEK_CUR, 442 + 20 + 24, sfinfo.channels, __LINE__) ;
	test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
	compare_float_or_die (data, stereo_out + ((442 + 20 + 24) * sfinfo.channels), 10, __LINE__) ;

	pos = 500 - sfinfo.frames ;
	test_seek_or_die (file, pos, SEEK_END, 500, sfinfo.channels, __LINE__) ;
	test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
	compare_float_or_die (data, stereo_out + (500 * sfinfo.channels), 10, __LINE__) ;

	pos = 10 - sfinfo.frames ;
	test_seek_or_die (file, pos, SEEK_END, 10, sfinfo.channels, __LINE__) ;
	test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
	compare_float_or_die (data, stereo_out + (10 * sfinfo.channels), 10, __LINE__) ;

	sf_close (file) ;

	puts ("ok") ;
	unlink (filename) ;
} /* ogg_stereo_seek_test */
コード例 #4
0
ファイル: channel_test.c プロジェクト: 74Labs/libsndfile
static void
channel_test (void)
{	static float	float_data [1024] ;
	static float	read_float [1024] ;
	static int		read_int [1024] ;
	static short	read_short [1024] ;
	unsigned int	ch, k, position = 0 ;

	gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.9) ;

	for (ch = 1 ; ch <= 8 ; ch++)
	{	SNDFILE	*file ;
		SF_INFO	wsfinfo, rsfinfo ;
		sf_count_t wframes = ARRAY_LEN (float_data) / ch ;
		double	maxdiff ;
		char	filename [256] ;

		snprintf (filename, sizeof (filename), "chan_%d.wav", ch) ;
		print_test_name (__func__, filename) ;

		sf_info_setup (&wsfinfo, SF_FORMAT_WAV | SF_FORMAT_FLOAT, 48000, ch) ;
		sf_info_clear (&rsfinfo) ;

		/* Write the test file. */
		file = test_open_file_or_die (filename, SFM_WRITE, &wsfinfo, SF_FALSE, __LINE__) ;
		test_writef_float_or_die (file, 0, float_data, wframes, __LINE__) ;
		sf_close (file) ;

		/* Read it as float and test. */
		file = test_open_file_or_die (filename, SFM_READ, &rsfinfo, SF_FALSE, __LINE__) ;
		exit_if_true (rsfinfo.frames == 0,
				"\n\nLine %d : Frames in file %" PRId64 ".\n\n", __LINE__, rsfinfo.frames) ;
		exit_if_true (wframes != rsfinfo.frames,
				"\n\nLine %d : Wrote %" PRId64 ", read %" PRId64 " frames.\n\n", __LINE__, wframes, rsfinfo.frames) ;

		sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;

		test_readf_float_or_die (file, 0, read_float, rsfinfo.frames, __LINE__) ;
		compare_float_or_die (float_data, read_float, ch * rsfinfo.frames, __LINE__) ;

		/* Read it as short and test. */
		test_seek_or_die (file, 0, SEEK_SET, 0, ch, __LINE__) ;
		test_readf_short_or_die (file, 0, read_short, rsfinfo.frames, __LINE__) ;

		for (k = 0 ; k < ARRAY_LEN (read_float) ; k++)
			read_float [k] = read_short [k] * (0.9 / 0x8000) ;

		maxdiff = max_diff (float_data, read_float, ch * rsfinfo.frames, &position) ;
		exit_if_true (maxdiff > 0.5, "\n\nLine %d : Max diff is %f at index %u\n\n", __LINE__, maxdiff, position) ;

		/* Read it as int and test. */
		test_seek_or_die (file, 0, SEEK_SET, 0, ch, __LINE__) ;
		test_readf_int_or_die (file, 0, read_int, rsfinfo.frames, __LINE__) ;

		for (k = 0 ; k < ARRAY_LEN (read_float) ; k++)
			read_float [k] = read_int [k] * (0.9 / 0x80000000) ;

		maxdiff = max_diff (float_data, read_float, ch * rsfinfo.frames, &position) ;
		exit_if_true (maxdiff > 0.5, "\n\nLine %d : Max diff is %f at index %u\n\n", __LINE__, maxdiff, position) ;

		sf_close (file) ;
		unlink (filename) ;
		printf ("ok\n") ;
		} ;

	return ;
} /* channel_test */