1 | //roarcat.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
5 | * |
---|
6 | * This file is part of roarclients a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
22 | * |
---|
23 | */ |
---|
24 | |
---|
25 | #include <roaraudio.h> |
---|
26 | |
---|
27 | #define BUFSIZE 1024 |
---|
28 | |
---|
29 | void usage (void) { |
---|
30 | printf("roarcat [OPTIONS]... [FILE]\n"); |
---|
31 | |
---|
32 | printf("\nOptions:\n\n"); |
---|
33 | |
---|
34 | printf(" --server SERVER - Set server hostname\n" |
---|
35 | " --rate -R RATE - Set sample rate\n" |
---|
36 | " --bits -B BITS - Set bits per sample\n" |
---|
37 | " --chans -C CHANNELS - Set number of channels\n" |
---|
38 | " --codec CODEC - Set the codec\n" |
---|
39 | " --wave - Use Wave Audio (PCM) as input\n" |
---|
40 | " --midi - Use MIDI Audio as input\n" |
---|
41 | " --light - Use light control input\n" |
---|
42 | " --help - Show this help\n" |
---|
43 | ); |
---|
44 | |
---|
45 | } |
---|
46 | |
---|
47 | int main (int argc, char * argv[]) { |
---|
48 | int rate = ROAR_RATE_DEFAULT; |
---|
49 | int bits = ROAR_BITS_DEFAULT; |
---|
50 | int channels = ROAR_CHANNELS_DEFAULT; |
---|
51 | int codec = ROAR_CODEC_DEFAULT; |
---|
52 | int dir = ROAR_DIR_PLAY; |
---|
53 | char * server = NULL; |
---|
54 | char * k; |
---|
55 | int fh; |
---|
56 | int i; |
---|
57 | int in = -1; |
---|
58 | char * name = "roarcat"; |
---|
59 | char buf[BUFSIZE]; |
---|
60 | |
---|
61 | for (i = 1; i < argc; i++) { |
---|
62 | k = argv[i]; |
---|
63 | |
---|
64 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
65 | server = argv[++i]; |
---|
66 | } else if ( !strcmp(k, "-n") ) { |
---|
67 | name = argv[++i]; |
---|
68 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) { |
---|
69 | rate = atoi(argv[++i]); |
---|
70 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
71 | bits = atoi(argv[++i]); |
---|
72 | } else if ( !strcmp(k, "-b") ) { |
---|
73 | bits = 8; |
---|
74 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
75 | channels = atoi(argv[++i]); |
---|
76 | } else if ( !strcmp(k, "-m") ) { |
---|
77 | channels = 1; |
---|
78 | } else if ( !strcmp(k, "--codec") ) { |
---|
79 | if ( (codec = roar_str2codec(argv[++i])) == -1 ) { |
---|
80 | fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]); |
---|
81 | return 1; |
---|
82 | } |
---|
83 | |
---|
84 | } else if ( !strcmp(k, "--wave") ) { |
---|
85 | dir = ROAR_DIR_PLAY; |
---|
86 | } else if ( !strcmp(k, "--midi") ) { |
---|
87 | dir = ROAR_DIR_MIDI_IN; |
---|
88 | if ( codec == ROAR_CODEC_DEFAULT ) |
---|
89 | codec = ROAR_CODEC_MIDI; |
---|
90 | } else if ( !strcmp(k, "--light") ) { |
---|
91 | dir = ROAR_DIR_LIGHT_IN; |
---|
92 | if ( codec == ROAR_CODEC_DEFAULT ) |
---|
93 | codec = ROAR_CODEC_DMX512; |
---|
94 | |
---|
95 | } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) { |
---|
96 | usage(); |
---|
97 | return 0; |
---|
98 | } else if ( in == -1 ) { |
---|
99 | if ( (in = open(k, O_RDONLY, 0644)) == -1 ) { |
---|
100 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
101 | return 1; |
---|
102 | } |
---|
103 | } else { |
---|
104 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
105 | usage(); |
---|
106 | return 1; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | if ( (fh = roar_simple_stream(rate, channels, bits, codec, server, dir, name)) == -1 ) { |
---|
111 | fprintf(stderr, "Error: can not start playback\n"); |
---|
112 | return 1; |
---|
113 | } |
---|
114 | |
---|
115 | if ( in == -1 ) |
---|
116 | in = ROAR_STDIN; |
---|
117 | |
---|
118 | while((i = read(in, buf, BUFSIZE))) |
---|
119 | if (write(fh, buf, i) != i) |
---|
120 | break; |
---|
121 | |
---|
122 | roar_simple_close(fh); |
---|
123 | |
---|
124 | close(in); |
---|
125 | |
---|
126 | return 0; |
---|
127 | } |
---|
128 | |
---|
129 | //ll |
---|