1 /*
2  * madplay - MPEG audio decoder and player
3  * Copyright (C) 2000-2004 Robert Leslie
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * $Id: mad123.c,v 1.8 2004/01/23 09:41:31 rob Exp $
20  */
21 
22 # ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 # endif
25 
26 # include "global.h"
27 
28 # include <stdio.h>
29 # include <stdlib.h>
30 
31 # include "getopt.h"
32 
33 /* banner output from mpg123 */
34 /*
35 High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3.
36 Version 0.59r (1999/Jun/15). Written and copyrights by Michael Hipp.
37 Uses code from various people. See 'README' for more!
38 THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
39 
40 */
41 
42 /* short usage output from mpg123 */
43 /*
44 usage: mpg123 [option(s)] [file(s) | URL(s) | -]
45 supported options [defaults in brackets]:
46    -v    increase verbosity level       -q    quiet (don't print title)
47    -t    testmode (no output)           -s    write to stdout
48    -w <filename> write Output as WAV file
49    -k n  skip first n frames [0]        -n n  decode only n frames [all]
50    -c    check range violations         -y    DISABLE resync on errors
51    -b n  output buffer: n Kbytes [0]    -f n  change scalefactor [32768]
52    -r n  set/force samplerate [auto]    -g n  set audio hardware output gain
53    -os,-ol,-oh  output to built-in speaker,line-out connector,headphones
54                                         -a d  set audio device
55    -2    downsample 1:2 (22 kHz)        -4    downsample 1:4 (11 kHz)
56    -d n  play every n'th frame only     -h n  play every frame n times
57    -0    decode channel 0 (left) only   -1    decode channel 1 (right) only
58    -m    mix both channels (mono)       -p p  use HTTP proxy p [$HTTP_PROXY]
59    -@ f  read filenames/URLs from f
60    -z    shuffle play (with wildcards)  -Z    random play
61    -u a  HTTP authentication string     -E f  Equalizer, data from file
62    -C    enable control keys
63 See the manpage mpg123(1) or call mpg123 with --longhelp for more information.
64 */
65 
66 /* long usage output from mpg123 */
67 /*
68 usage: mpg123 [option(s)] [file(s) | URL(s) | -]
69 supported options:
70 
71  -k <n> --skip <n>
72  -a <f> --audiodevice <f>
73  -2     --2to1             2:1 Downsampling
74  -4     --4to1             4:1 Downsampling
75  -t     --test
76  -s     --stdout
77  -S     --STDOUT           Play AND output stream (not implemented yet)
78  -c     --check
79  -v[*]  --verbose          Increase verboselevel
80  -q     --quiet            Enables quiet mode
81  -y     --resync           DISABLES resync on error
82  -0     --left --single0   Play only left channel
83  -1     --right --single1  Play only right channel
84  -m     --mono --mix       Mix stereo to mono
85         --stereo           Duplicate mono channel
86         --reopen           Force close/open on audiodevice
87  -g     --gain             Set audio hardware output gain
88  -r     --rate             Force a specific audio output rate
89         --8bit             Force 8 bit output
90  -o h   --headphones       Output on headphones
91  -o s   --speaker          Output on speaker
92  -o l   --lineout          Output to lineout
93  -f <n> --scale <n>        Scale output samples (soft gain)
94  -n     --frames <n>       Play only <n> frames of every stream
95  -b <n> --buffer <n>       Set play buffer ("output cache")
96  -d     --doublespeed      Play only every second frame
97  -h     --halfspeed        Play every frame twice
98  -p <f> --proxy <f>        Set WWW proxy
99  -@ <f> --list <f>         Play songs in <f> file-list
100  -z     --shuffle          Shuffle song-list before playing
101  -Z     --random           full random play
102         --equalizer        Exp.: scales freq. bands acrd. to 'equalizer.dat'
103         --aggressive       Tries to get higher priority (nice)
104  -u     --auth             Set auth values for HTTP access
105  -w <f> --wav <f>          Writes samples as WAV file in <f> (- is stdout)
106         --au <f>           Writes samples as Sun AU file in <f> (- is stdout)
107         --cdr <f>          Writes samples as CDR file in <f> (- is stdout)
108  -E <s> --esd <s>          Plays to  ESD server <s>
109 
110 See the manpage mpg123(1) for more information.
111 */
112 
113 static
114 struct option const options[] = {
115   { "skip",        required_argument, 0,  'k' },
116   { "audiodevice", required_argument, 0,  'a' },
117   { "2to1",        no_argument,       0,  '2' },
118   { "4to1",        no_argument,       0,  '4' },
119   { "test",        no_argument,       0,  't' },
120   { "stdout",      no_argument,       0,  's' },
121   { "STDOUT",      no_argument,       0,  'S' },
122   { "check",       no_argument,       0,  'c' },
123   { "verbose",     no_argument,       0,  'v' },
124   { "quiet",       no_argument,       0,  'q' },
125   { "resync",      no_argument,       0,  'y' },
126   { "left",        no_argument,       0,  '0' },
127   { "single0",     no_argument,       0,  '0' },
128   { "right",       no_argument,       0,  '1' },
129   { "single1",     no_argument,       0,  '1' },
130   { "mono",        no_argument,       0,  'm' },
131   { "mix",         no_argument,       0,  'm' },
132   { "stereo",      no_argument,       0, -'s' },
133   { "reopen",      no_argument,       0, -'r' },
134   { "gain",        required_argument, 0,  'g' },
135   { "rate",        required_argument, 0,  'r' },
136   { "8bit",        no_argument,       0, -'8' },
137   { "headphones",  no_argument,       0,  'o' },
138   { "speaker",     no_argument,       0,  'o' },
139   { "lineout",     no_argument,       0,  'o' },
140   { "scale",       required_argument, 0,  'f' },
141   { "frames",      required_argument, 0,  'n' },
142   { "buffer",      required_argument, 0,  'b' },
143   { "doublespeed", required_argument, 0,  'd' },
144   { "halfspeed",   required_argument, 0,  'h' },
145   { "proxy",       required_argument, 0,  'p' },
146   { "list",        required_argument, 0,  '@' },
147   { "shuffle",     no_argument,       0,  'z' },
148   { "random",      no_argument,       0,  'Z' },
149   { "equalizer",   required_argument, 0,  'E' },
150   { "aggressive",  no_argument,       0, -'a' },
151   { "auth",        required_argument, 0,  'u' },
152   { "wav",         required_argument, 0,  'w' },
153   { "au",          required_argument, 0, -'m' },
154   { "cdr",         required_argument, 0, -'c' },
155   { "esd",         required_argument, 0, -'e' },
156   { 0 }
157 };
158 
159 static
160 struct {
161   int verbosity;
162 } config = {
163   0	/* verbosity */
164 };
165 
main(int argc,char * argv[])166 int main(int argc, char *argv[])
167 {
168   int opt, index;
169 
170   while ((opt = getopt_long(argc, argv,
171 			    "vqtsSw:k:n:cyb:f:r:g:o:a:24d:h:01mp:@:zZu:E:C",
172 			    options, &index)) != -1) {
173     switch (opt) {
174     case 'v':
175       ++config.verbosity;
176       break;
177 
178     case 'q':
179       config.verbosity = -1;
180       break;
181 
182     case '?':
183       exit(1);
184     }
185   }
186 
187   if (config.verbosity >= 0) {
188     fprintf(stderr,
189 	    "High Quality MPEG 1.0/2.0/2.5 Audio Player"
190 	    " for Layer I, II, and III.\n"
191 	    "Version 0.59r (2000/Oct/04)."
192 	    " Written and copyright by Robert Leslie.\n"
193 	    "Uses mpg123 command interface. See the documentation!\n"
194 	    "THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY!"
195 	    " USE AT YOUR OWN RISK!\n");
196   }
197 
198   /* ... */
199 
200   return 0;
201 }
202