2 ** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** All rights reserved.
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are
10 ** * Redistributions of source code must retain the above copyright
11 ** notice, this list of conditions and the following disclaimer.
12 ** * Redistributions in binary form must reproduce the above copyright
13 ** notice, this list of conditions and the following disclaimer in
14 ** the documentation and/or other materials provided with the
16 ** * Neither the author nor the names of any contributors may be used
17 ** to endorse or promote products derived from this software without
18 ** specific prior written permission.
20 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #define BUFFER_LEN 4096
44 static void encode_file (const char *infilename
, const char *outfilename
, int filetype
) ;
47 main (int argc
, char **argv
)
50 { puts ("\nEncode a single input file into a number of different output ") ;
51 puts ("encodings. These output encodings can then be moved to another ") ;
52 puts ("OS for testing.\n") ;
53 puts (" Usage : generate <filename>\n") ;
57 /* A couple of standard WAV files. Make sure Win32 plays these. */
58 encode_file (argv
[1], "pcmu8.wav" , SF_FORMAT_WAV
| SF_FORMAT_PCM_U8
) ;
59 encode_file (argv
[1], "pcm16.wav" , SF_FORMAT_WAV
| SF_FORMAT_PCM_16
) ;
60 encode_file (argv
[1], "imaadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_MS_ADPCM
) ;
61 encode_file (argv
[1], "msadpcm.wav", SF_FORMAT_WAV
| SF_FORMAT_IMA_ADPCM
) ;
62 encode_file (argv
[1], "gsm610.wav" , SF_FORMAT_WAV
| SF_FORMAT_GSM610
) ;
65 encode_file (argv
[1], "pcmu8.w64" , SF_FORMAT_W64
| SF_FORMAT_PCM_U8
) ;
66 encode_file (argv
[1], "pcm16.w64" , SF_FORMAT_W64
| SF_FORMAT_PCM_16
) ;
67 encode_file (argv
[1], "imaadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_MS_ADPCM
) ;
68 encode_file (argv
[1], "msadpcm.w64", SF_FORMAT_W64
| SF_FORMAT_IMA_ADPCM
) ;
69 encode_file (argv
[1], "gsm610.w64" , SF_FORMAT_W64
| SF_FORMAT_GSM610
) ;
74 /*============================================================================================
75 ** Helper functions and macros.
84 /*========================================================================================
88 encode_file (const char *infilename
, const char *outfilename
, int filetype
)
89 { static float buffer
[BUFFER_LEN
] ;
91 SNDFILE
*infile
, *outfile
;
95 printf (" %s -> %s ", infilename
, outfilename
) ;
98 k
= 16 - strlen (outfilename
) ;
101 if (! (infile
= sf_open (infilename
, SFM_READ
, &sfinfo
)))
102 { printf ("Error : could not open file : %s\n", infilename
) ;
103 puts (sf_strerror (NULL
)) ;
107 sfinfo
.format
= filetype
;
109 if (! sf_format_check (&sfinfo
))
110 { sf_close (infile
) ;
111 printf ("Invalid encoding\n") ;
115 if (! (outfile
= sf_open (outfilename
, SFM_WRITE
, &sfinfo
)))
116 { printf ("Error : could not open file : %s\n", outfilename
) ;
117 puts (sf_strerror (NULL
)) ;
121 while ((readcount
= sf_read_float (infile
, buffer
, BUFFER_LEN
)) > 0)
122 sf_write_float (outfile
, buffer
, readcount
) ;