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