• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ** Copyright (C) 2001-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 
19 #include "sfconfig.h"
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <math.h>
25 
26 #if HAVE_UNISTD_H
27 #include <unistd.h>
28 #else
29 #include "sf_unistd.h"
30 #endif
31 
32 #include <sndfile.h>
33 
34 #include "utils.h"
35 
36 static	void	stdout_test	(int typemajor, int count) ;
37 
38 int
main(int argc,char * argv[])39 main (int argc, char *argv [])
40 {	int		do_all, test_count = 0 ;
41 
42 	if (argc != 2)
43 	{	fprintf (stderr, "This program cannot be run by itself. It needs\n") ;
44 		fprintf (stderr, "to be run from the stdio_test program.\n") ;
45 		exit (1) ;
46 		} ;
47 
48 	do_all = ! strcmp (argv [1], "all") ;
49 
50 	if (do_all || ! strcmp (argv [1], "raw"))
51 	{	stdout_test	(SF_FORMAT_RAW, PIPE_TEST_LEN) ;
52 		test_count ++ ;
53 		} ;
54 
55 	if (do_all || ! strcmp (argv [1], "wav"))
56 	{	stdout_test	(SF_FORMAT_WAV, PIPE_TEST_LEN) ;
57 		test_count ++ ;
58 		} ;
59 
60 	if (do_all || ! strcmp (argv [1], "aiff"))
61 	{	stdout_test	(SF_FORMAT_AIFF, PIPE_TEST_LEN) ;
62 		test_count ++ ;
63 		} ;
64 
65 	if (do_all || ! strcmp (argv [1], "au"))
66 	{	stdout_test	(SF_FORMAT_AU, PIPE_TEST_LEN) ;
67 		test_count ++ ;
68 		} ;
69 
70 	if (do_all || ! strcmp (argv [1], "paf"))
71 	{	stdout_test	(SF_FORMAT_PAF, PIPE_TEST_LEN) ;
72 		test_count ++ ;
73 		} ;
74 
75 	if (do_all || ! strcmp (argv [1], "svx"))
76 	{	stdout_test	(SF_FORMAT_SVX, PIPE_TEST_LEN) ;
77 		test_count ++ ;
78 		} ;
79 
80 	if (do_all || ! strcmp (argv [1], "nist"))
81 	{	stdout_test	(SF_FORMAT_NIST, PIPE_TEST_LEN) ;
82 		test_count ++ ;
83 		} ;
84 
85 	if (do_all || ! strcmp (argv [1], "ircam"))
86 	{	stdout_test	(SF_FORMAT_IRCAM, PIPE_TEST_LEN) ;
87 		test_count ++ ;
88 		} ;
89 
90 	if (do_all || ! strcmp (argv [1], "voc"))
91 	{	stdout_test	(SF_FORMAT_VOC, PIPE_TEST_LEN) ;
92 		test_count ++ ;
93 		} ;
94 
95 	if (do_all || ! strcmp (argv [1], "w64"))
96 	{	stdout_test	(SF_FORMAT_W64, PIPE_TEST_LEN) ;
97 		test_count ++ ;
98 		} ;
99 
100 	if (do_all || ! strcmp (argv [1], "mat4"))
101 	{	stdout_test	(SF_FORMAT_MAT4, PIPE_TEST_LEN) ;
102 		test_count ++ ;
103 		} ;
104 
105 	if (do_all || ! strcmp (argv [1], "mat5"))
106 	{	stdout_test	(SF_FORMAT_MAT5, PIPE_TEST_LEN) ;
107 		test_count ++ ;
108 		} ;
109 
110 	if (do_all || ! strcmp (argv [1], "pvf"))
111 	{	stdout_test	(SF_FORMAT_PVF, PIPE_TEST_LEN) ;
112 		test_count ++ ;
113 		} ;
114 
115 	if (test_count == 0)
116 	{	fprintf (stderr, "\n******************************************\n") ;
117 		fprintf (stderr, "*  stdout_test : No '%s' test defined.\n", argv [1]) ;
118 		fprintf (stderr, "******************************************\n") ;
119 		return 1 ;
120 		} ;
121 
122 	return 0 ;
123 } /* main */
124 
125 static	void
stdout_test(int typemajor,int count)126 stdout_test	(int typemajor, int count)
127 {	static	short	data [PIPE_TEST_LEN] ;
128 
129 	SNDFILE		*file ;
130 	SF_INFO		sfinfo ;
131 	int			k, total, this_write ;
132 
133 	sfinfo.samplerate	= 44100 ;
134 	sfinfo.format		= (typemajor | SF_FORMAT_PCM_16) ;
135 	sfinfo.channels		= 1 ;
136 	sfinfo.frames		= 0 ;
137 
138 	/* Create some random data. */
139 	for (k = 0 ; k < PIPE_TEST_LEN ; k++)
140 		data [k] = PIPE_INDEX (k) ;
141 
142 	if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL)
143 	{	fprintf (stderr, "%s % d: sf_open_write failed with error : %s\n",
144 									__func__, __LINE__, sf_strerror (NULL)) ;
145 		exit (1) ;
146 		} ;
147 
148 	if (sfinfo.frames != 0)
149 	{	fprintf (stderr, "%s % d: Frames is %d (should be 0).\n",
150 									__func__, __LINE__, (int) sfinfo.frames) ;
151 		exit (1) ;
152 		} ;
153 
154 	total = 0 ;
155 
156 	while (total < count)
157 	{	this_write = (count - total > 1024) ? 1024 : count - total ;
158 		if ((k = sf_write_short (file, data + total, this_write)) != this_write)
159 		{	fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ;
160 			exit (1) ;
161 			} ;
162 		total += k ;
163 		} ;
164 
165 	sf_close (file) ;
166 
167 	return ;
168 } /* stdout_test */
169 
170