Let qmake generate an install Makefile target to install the binary. Doesn't handle...
[Rockbox.git] / tools / rbspeex / rbspeexenc.c
blobc7ea6e429a7146c5a39dcc908af4df52126c78c5
1 /**************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 Thom Johansen
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ***************************************************************************/
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdbool.h>
24 #include "rbspeex.h"
26 #define USAGE_TEXT \
27 "Usage: rbspeexenc [options] infile outfile\n"\
28 "Options:\n"\
29 " -q x Quality, floating point number in the range [0-10], default 8.0\n"\
30 " -c x Complexity, increases quality for a given bitrate, but encodes\n"\
31 " slower, range [0-10], default 3\n"\
32 " -n Enable narrowband mode, will resample input to 8 kHz\n"\
33 " -v x Volume, amplitude multiplier, default 1.0\n\n"\
34 "rbspeexenc expects a mono 16 bit WAV file as input. Files will be resampled\n"\
35 "to either 16 kHz by default, or 8 kHz if narrowband mode is enabled.\n"\
36 "WARNING: This tool will create files that are only usable by Rockbox!\n"
39 int main(int argc, char **argv)
41 char *inname, *outname;
42 FILE *fin, *fout;
43 int i;
44 int complexity = 3;
45 float quality = 8.f, volume = 1.0f;
46 bool narrowband = false;
47 bool ret;
48 char errstr[512];
50 if (argc < 3) {
51 printf(USAGE_TEXT);
52 return 1;
55 i = 1;
56 while (i < argc - 2) {
57 if (strncmp(argv[i], "-q", 2) == 0)
58 quality = atof(argv[++i]);
59 else if (strncmp(argv[i], "-c", 2) == 0)
60 complexity = atoi(argv[++i]);
61 else if (strncmp(argv[i], "-v", 2) == 0)
62 volume = atof(argv[++i]);
63 else if (strncmp(argv[i], "-n", 2) == 0)
64 narrowband = true;
65 else {
66 printf("Error: unrecognized option '%s'\n", argv[i]);
67 return 1;
69 ++i;
71 inname = argv[argc - 2];
72 outname = argv[argc - 1];
74 if ((fin = fopen(inname, "rb")) == NULL) {
75 printf("Error: could not open input file\n");
76 return 1;
78 if ((fout = fopen(outname, "wb")) == NULL) {
79 printf("Error: could not open output file\n");
80 return 1;
83 ret = encode_file(fin, fout, quality, complexity, narrowband, volume,
84 errstr, sizeof(errstr));
85 fclose(fin);
86 fclose(fout);
87 if (!ret) {
88 /* Attempt to delete unfinished output */
89 printf("Error: %s\n", errstr);
90 remove(outname);
91 return 1;
93 return 0;