Chris@0: /* Chris@0: ** Copyright (C) 2002-2011 Erik de Castro Lopo Chris@0: ** Chris@0: ** All rights reserved. Chris@0: ** Chris@0: ** Redistribution and use in source and binary forms, with or without Chris@0: ** modification, are permitted provided that the following conditions are Chris@0: ** met: Chris@0: ** Chris@0: ** * Redistributions of source code must retain the above copyright Chris@0: ** notice, this list of conditions and the following disclaimer. Chris@0: ** * Redistributions in binary form must reproduce the above copyright Chris@0: ** notice, this list of conditions and the following disclaimer in Chris@0: ** the documentation and/or other materials provided with the Chris@0: ** distribution. Chris@0: ** * Neither the author nor the names of any contributors may be used Chris@0: ** to endorse or promote products derived from this software without Chris@0: ** specific prior written permission. Chris@0: ** Chris@0: ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@0: ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED Chris@0: ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR Chris@0: ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR Chris@0: ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@0: ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@0: ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; Chris@0: ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, Chris@0: ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR Chris@0: ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF Chris@0: ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@0: */ Chris@0: Chris@0: #include "sfconfig.h" Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include Chris@0: Chris@0: #define BUFFER_LEN 4096 Chris@0: Chris@0: static void encode_file (const char *infilename, const char *outfilename, int filetype) ; Chris@0: Chris@0: int Chris@0: main (int argc, char **argv) Chris@0: { Chris@0: if (argc != 2) Chris@0: { puts ("\nEncode a single input file into a number of different output ") ; Chris@0: puts ("encodings. These output encodings can then be moved to another ") ; Chris@0: puts ("OS for testing.\n") ; Chris@0: puts (" Usage : generate \n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: /* A couple of standard WAV files. Make sure Win32 plays these. */ Chris@0: encode_file (argv [1], "pcmu8.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ; Chris@0: encode_file (argv [1], "pcm16.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; Chris@0: encode_file (argv [1], "imaadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM) ; Chris@0: encode_file (argv [1], "msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM) ; Chris@0: encode_file (argv [1], "gsm610.wav" , SF_FORMAT_WAV | SF_FORMAT_GSM610) ; Chris@0: Chris@0: /* Soundforge W64. */ Chris@0: encode_file (argv [1], "pcmu8.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ; Chris@0: encode_file (argv [1], "pcm16.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_16) ; Chris@0: encode_file (argv [1], "imaadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM) ; Chris@0: encode_file (argv [1], "msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM) ; Chris@0: encode_file (argv [1], "gsm610.w64" , SF_FORMAT_W64 | SF_FORMAT_GSM610) ; Chris@0: Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: Chris@0: /*============================================================================================ Chris@0: ** Helper functions and macros. Chris@0: */ Chris@0: Chris@0: #define PUT_DOTS(k) \ Chris@0: { while (k--) \ Chris@0: putchar ('.') ; \ Chris@0: putchar (' ') ; \ Chris@0: } Chris@0: Chris@0: /*======================================================================================== Chris@0: */ Chris@0: Chris@0: static void Chris@0: encode_file (const char *infilename, const char *outfilename, int filetype) Chris@0: { static float buffer [BUFFER_LEN] ; Chris@0: Chris@0: SNDFILE *infile, *outfile ; Chris@0: SF_INFO sfinfo ; Chris@0: int k, readcount ; Chris@0: Chris@0: printf (" %s -> %s ", infilename, outfilename) ; Chris@0: fflush (stdout) ; Chris@0: Chris@0: k = 16 - strlen (outfilename) ; Chris@0: PUT_DOTS (k) ; Chris@0: Chris@0: if (! (infile = sf_open (infilename, SFM_READ, &sfinfo))) Chris@0: { printf ("Error : could not open file : %s\n", infilename) ; Chris@0: puts (sf_strerror (NULL)) ; Chris@0: exit (1) ; Chris@0: } Chris@0: Chris@0: sfinfo.format = filetype ; Chris@0: Chris@0: if (! sf_format_check (&sfinfo)) Chris@0: { sf_close (infile) ; Chris@0: printf ("Invalid encoding\n") ; Chris@0: return ; Chris@0: } ; Chris@0: Chris@0: if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo))) Chris@0: { printf ("Error : could not open file : %s\n", outfilename) ; Chris@0: puts (sf_strerror (NULL)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: while ((readcount = sf_read_float (infile, buffer, BUFFER_LEN)) > 0) Chris@0: sf_write_float (outfile, buffer, readcount) ; Chris@0: Chris@0: sf_close (infile) ; Chris@0: sf_close (outfile) ; Chris@0: Chris@0: printf ("ok\n") ; Chris@0: Chris@0: return ; Chris@0: } /* encode_file */ Chris@0: