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