1b815c7f3Sopenharmony_ci/*
2b815c7f3Sopenharmony_ci** Copyright (C) 2006-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
3b815c7f3Sopenharmony_ci**
4b815c7f3Sopenharmony_ci** This program is free software; you can redistribute it and/or modify
5b815c7f3Sopenharmony_ci** it under the terms of the GNU General Public License as published by
6b815c7f3Sopenharmony_ci** the Free Software Foundation; either version 2 of the License, or
7b815c7f3Sopenharmony_ci** (at your option) any later version.
8b815c7f3Sopenharmony_ci**
9b815c7f3Sopenharmony_ci** This program is distributed in the hope that it will be useful,
10b815c7f3Sopenharmony_ci** but WITHOUT ANY WARRANTY; without even the implied warranty of
11b815c7f3Sopenharmony_ci** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12b815c7f3Sopenharmony_ci** GNU General Public License for more details.
13b815c7f3Sopenharmony_ci**
14b815c7f3Sopenharmony_ci** You should have received a copy of the GNU General Public License
15b815c7f3Sopenharmony_ci** along with this program; if not, write to the Free Software
16b815c7f3Sopenharmony_ci** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17b815c7f3Sopenharmony_ci*/
18b815c7f3Sopenharmony_ci
19b815c7f3Sopenharmony_ci#include "sfconfig.h"
20b815c7f3Sopenharmony_ci
21b815c7f3Sopenharmony_ci#include <stdio.h>
22b815c7f3Sopenharmony_ci#include <stdlib.h>
23b815c7f3Sopenharmony_ci#include <string.h>
24b815c7f3Sopenharmony_ci
25b815c7f3Sopenharmony_ci#if HAVE_UNISTD_H
26b815c7f3Sopenharmony_ci#include <unistd.h>
27b815c7f3Sopenharmony_ci#else
28b815c7f3Sopenharmony_ci#include "sf_unistd.h"
29b815c7f3Sopenharmony_ci#endif
30b815c7f3Sopenharmony_ci
31b815c7f3Sopenharmony_ci#include <sndfile.h>
32b815c7f3Sopenharmony_ci
33b815c7f3Sopenharmony_ci#include "utils.h"
34b815c7f3Sopenharmony_ci
35b815c7f3Sopenharmony_ci#define	BUFFER_LEN		(1024 * 1024)
36b815c7f3Sopenharmony_ci#define	BUFFER_COUNT	(768)
37b815c7f3Sopenharmony_ci
38b815c7f3Sopenharmony_cistatic void largefile_test (int filetype, const char * filename) ;
39b815c7f3Sopenharmony_ci
40b815c7f3Sopenharmony_ciint
41b815c7f3Sopenharmony_cimain (void)
42b815c7f3Sopenharmony_ci{
43b815c7f3Sopenharmony_ci	largefile_test (SF_FORMAT_WAV, "largefile.wav") ;
44b815c7f3Sopenharmony_ci	largefile_test (SF_FORMAT_AIFF, "largefile.aiff") ;
45b815c7f3Sopenharmony_ci
46b815c7f3Sopenharmony_ci	return 0 ;
47b815c7f3Sopenharmony_ci} /* main */
48b815c7f3Sopenharmony_ci
49b815c7f3Sopenharmony_cistatic void
50b815c7f3Sopenharmony_cilargefile_test (int filetype, const char * filename)
51b815c7f3Sopenharmony_ci{	static float data [BUFFER_LEN] ;
52b815c7f3Sopenharmony_ci	SNDFILE		*file ;
53b815c7f3Sopenharmony_ci	SF_INFO		sfinfo ;
54b815c7f3Sopenharmony_ci	int k ;
55b815c7f3Sopenharmony_ci
56b815c7f3Sopenharmony_ci	print_test_name ("largefile_test", filename) ;
57b815c7f3Sopenharmony_ci
58b815c7f3Sopenharmony_ci	sfinfo.samplerate	= 44100 ;
59b815c7f3Sopenharmony_ci	sfinfo.channels		= 2 ;
60b815c7f3Sopenharmony_ci	sfinfo.frames		= 0 ;
61b815c7f3Sopenharmony_ci	sfinfo.format = (filetype | SF_FORMAT_PCM_32) ;
62b815c7f3Sopenharmony_ci
63b815c7f3Sopenharmony_ci	file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
64b815c7f3Sopenharmony_ci
65b815c7f3Sopenharmony_ci	for (k = 0 ; k < BUFFER_COUNT ; k++)
66b815c7f3Sopenharmony_ci		test_write_float_or_die (file, k, data, BUFFER_LEN, __LINE__) ;
67b815c7f3Sopenharmony_ci
68b815c7f3Sopenharmony_ci	sf_close (file) ;
69b815c7f3Sopenharmony_ci
70b815c7f3Sopenharmony_ci	file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
71b815c7f3Sopenharmony_ci
72b815c7f3Sopenharmony_ci	if ((sfinfo.frames * sfinfo.channels) / BUFFER_LEN != BUFFER_COUNT)
73b815c7f3Sopenharmony_ci	{	printf ("\n\nLine %d : bad frame count.\n", __LINE__) ;
74b815c7f3Sopenharmony_ci		exit (1) ;
75b815c7f3Sopenharmony_ci		} ;
76b815c7f3Sopenharmony_ci
77b815c7f3Sopenharmony_ci	sf_close (file) ;
78b815c7f3Sopenharmony_ci
79b815c7f3Sopenharmony_ci	unlink (filename) ;
80b815c7f3Sopenharmony_ci	puts ("ok") ;
81b815c7f3Sopenharmony_ci
82b815c7f3Sopenharmony_ci
83b815c7f3Sopenharmony_ci	return ;
84b815c7f3Sopenharmony_ci} /* largefile_test */
85b815c7f3Sopenharmony_ci
86