xref: /third_party/libsnd/tests/sftest.c (revision b815c7f3)
1/*
2** Copyright (C) 1999-2011 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
23#if HAVE_UNISTD_H
24#include <unistd.h>
25#else
26#include "sf_unistd.h"
27#endif
28
29#include <sndfile.h>
30
31#define	BUFFER_SIZE		(1024)
32
33
34static short buffer [BUFFER_SIZE] ;
35
36int
37main (int argc, char *argv [])
38{	SNDFILE	*file ;
39	SF_INFO sfinfo ;
40	int		k, count, max = 0, total = 0 ;
41
42	if (argc < 2)
43	{	printf ("Expecting input file name.\n") ;
44		return 0 ;
45		} ;
46
47	if (! (file = sf_open (argv [1], SFM_READ, &sfinfo)))
48	{	printf ("sf_open_read failed with error : ") ;
49		puts (sf_strerror (NULL)) ;
50		exit (1) ;
51		} ;
52
53	while ((count = sf_read_short (file, buffer, BUFFER_SIZE)))
54	{	for (k = 0 ; k < count ; k++)
55			if (abs (buffer [k]) > max)
56				max = abs (buffer [k]) ;
57		total += count ;
58		} ;
59
60	printf ("Total         : %d\n", total) ;
61	printf ("Maximun value : %d\n", max) ;
62
63	sf_close (file) ;
64
65	return 0 ;
66} /* main */
67
68