cannam@125
|
1 /*
|
cannam@125
|
2 ** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
cannam@125
|
3 **
|
cannam@125
|
4 ** All rights reserved.
|
cannam@125
|
5 **
|
cannam@125
|
6 ** Redistribution and use in source and binary forms, with or without
|
cannam@125
|
7 ** modification, are permitted provided that the following conditions are
|
cannam@125
|
8 ** met:
|
cannam@125
|
9 **
|
cannam@125
|
10 ** * Redistributions of source code must retain the above copyright
|
cannam@125
|
11 ** notice, this list of conditions and the following disclaimer.
|
cannam@125
|
12 ** * Redistributions in binary form must reproduce the above copyright
|
cannam@125
|
13 ** notice, this list of conditions and the following disclaimer in
|
cannam@125
|
14 ** the documentation and/or other materials provided with the
|
cannam@125
|
15 ** distribution.
|
cannam@125
|
16 ** * Neither the author nor the names of any contributors may be used
|
cannam@125
|
17 ** to endorse or promote products derived from this software without
|
cannam@125
|
18 ** specific prior written permission.
|
cannam@125
|
19 **
|
cannam@125
|
20 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
cannam@125
|
21 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
cannam@125
|
22 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
cannam@125
|
23 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
cannam@125
|
24 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
cannam@125
|
25 ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
cannam@125
|
26 ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
cannam@125
|
27 ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
cannam@125
|
28 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
cannam@125
|
29 ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
cannam@125
|
30 ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
cannam@125
|
31 */
|
cannam@125
|
32
|
cannam@125
|
33 #include "sfconfig.h"
|
cannam@125
|
34
|
cannam@125
|
35 #include <stdio.h>
|
cannam@125
|
36 #include <stdlib.h>
|
cannam@125
|
37 #include <string.h>
|
cannam@125
|
38 #include <math.h>
|
cannam@125
|
39
|
cannam@125
|
40 #include <sndfile.h>
|
cannam@125
|
41
|
cannam@125
|
42 #define BUFFER_LEN 4096
|
cannam@125
|
43
|
cannam@125
|
44 static void encode_file (const char *infilename, const char *outfilename, int filetype) ;
|
cannam@125
|
45
|
cannam@125
|
46 int
|
cannam@125
|
47 main (int argc, char **argv)
|
cannam@125
|
48 {
|
cannam@125
|
49 if (argc != 2)
|
cannam@125
|
50 { puts ("\nEncode a single input file into a number of different output ") ;
|
cannam@125
|
51 puts ("encodings. These output encodings can then be moved to another ") ;
|
cannam@125
|
52 puts ("OS for testing.\n") ;
|
cannam@125
|
53 puts (" Usage : generate <filename>\n") ;
|
cannam@125
|
54 exit (1) ;
|
cannam@125
|
55 } ;
|
cannam@125
|
56
|
cannam@125
|
57 /* A couple of standard WAV files. Make sure Win32 plays these. */
|
cannam@125
|
58 encode_file (argv [1], "pcmu8.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ;
|
cannam@125
|
59 encode_file (argv [1], "pcm16.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
cannam@125
|
60 encode_file (argv [1], "imaadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM) ;
|
cannam@125
|
61 encode_file (argv [1], "msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM) ;
|
cannam@125
|
62 encode_file (argv [1], "gsm610.wav" , SF_FORMAT_WAV | SF_FORMAT_GSM610) ;
|
cannam@125
|
63
|
cannam@125
|
64 /* Soundforge W64. */
|
cannam@125
|
65 encode_file (argv [1], "pcmu8.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ;
|
cannam@125
|
66 encode_file (argv [1], "pcm16.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_16) ;
|
cannam@125
|
67 encode_file (argv [1], "imaadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM) ;
|
cannam@125
|
68 encode_file (argv [1], "msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM) ;
|
cannam@125
|
69 encode_file (argv [1], "gsm610.w64" , SF_FORMAT_W64 | SF_FORMAT_GSM610) ;
|
cannam@125
|
70
|
cannam@125
|
71 return 0 ;
|
cannam@125
|
72 } /* main */
|
cannam@125
|
73
|
cannam@125
|
74 /*============================================================================================
|
cannam@125
|
75 ** Helper functions and macros.
|
cannam@125
|
76 */
|
cannam@125
|
77
|
cannam@125
|
78 #define PUT_DOTS(k) \
|
cannam@125
|
79 { while (k--) \
|
cannam@125
|
80 putchar ('.') ; \
|
cannam@125
|
81 putchar (' ') ; \
|
cannam@125
|
82 }
|
cannam@125
|
83
|
cannam@125
|
84 /*========================================================================================
|
cannam@125
|
85 */
|
cannam@125
|
86
|
cannam@125
|
87 static void
|
cannam@125
|
88 encode_file (const char *infilename, const char *outfilename, int filetype)
|
cannam@125
|
89 { static float buffer [BUFFER_LEN] ;
|
cannam@125
|
90
|
cannam@125
|
91 SNDFILE *infile, *outfile ;
|
cannam@125
|
92 SF_INFO sfinfo ;
|
cannam@125
|
93 int k, readcount ;
|
cannam@125
|
94
|
cannam@125
|
95 printf (" %s -> %s ", infilename, outfilename) ;
|
cannam@125
|
96 fflush (stdout) ;
|
cannam@125
|
97
|
cannam@125
|
98 k = 16 - strlen (outfilename) ;
|
cannam@125
|
99 PUT_DOTS (k) ;
|
cannam@125
|
100
|
cannam@125
|
101 memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
cannam@125
|
102
|
cannam@125
|
103 if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
|
cannam@125
|
104 { printf ("Error : could not open file : %s\n", infilename) ;
|
cannam@125
|
105 puts (sf_strerror (NULL)) ;
|
cannam@125
|
106 exit (1) ;
|
cannam@125
|
107 }
|
cannam@125
|
108
|
cannam@125
|
109 sfinfo.format = filetype ;
|
cannam@125
|
110
|
cannam@125
|
111 if (! sf_format_check (&sfinfo))
|
cannam@125
|
112 { sf_close (infile) ;
|
cannam@125
|
113 printf ("Invalid encoding\n") ;
|
cannam@125
|
114 return ;
|
cannam@125
|
115 } ;
|
cannam@125
|
116
|
cannam@125
|
117 if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)))
|
cannam@125
|
118 { printf ("Error : could not open file : %s\n", outfilename) ;
|
cannam@125
|
119 puts (sf_strerror (NULL)) ;
|
cannam@125
|
120 exit (1) ;
|
cannam@125
|
121 } ;
|
cannam@125
|
122
|
cannam@125
|
123 while ((readcount = sf_read_float (infile, buffer, BUFFER_LEN)) > 0)
|
cannam@125
|
124 sf_write_float (outfile, buffer, readcount) ;
|
cannam@125
|
125
|
cannam@125
|
126 sf_close (infile) ;
|
cannam@125
|
127 sf_close (outfile) ;
|
cannam@125
|
128
|
cannam@125
|
129 printf ("ok\n") ;
|
cannam@125
|
130
|
cannam@125
|
131 return ;
|
cannam@125
|
132 } /* encode_file */
|
cannam@125
|
133
|