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