source: roaraudio/roarclients/roarcat.c @ 4883:c56aedd9d0cb

Last change on this file since 4883:c56aedd9d0cb was 4883:c56aedd9d0cb, checked in by phi, 13 years ago

Added functions to access symbolic names for audio info parameters (Closes: #51)

File size: 6.5 KB
Line 
1//roarcat.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27
28#define BUFSIZE 1024
29
30void usage (void) {
31 printf("roarcat [OPTIONS]... [FILE]\n");
32
33 printf("\nOptions:\n\n");
34
35 printf("  --server    SERVER    - Set server hostname\n"
36        "  --rate  -R  RATE      - Set sample rate\n"
37        "  --bits  -B  BITS      - Set bits per sample\n"
38        "  --chans -C  CHANNELS  - Set number of channels\n"
39        "  --codec     CODEC     - Set the codec\n"
40        "  --wave                - Use Wave Audio (PCM) as input\n"
41        "  --midi                - Use MIDI Audio as input\n"
42        "  --light               - Use light control input\n"
43        "  --raw                 - Use raw input\n"
44        "  --complex             - Use complex input\n"
45        "  --rdtcs               - Use Radio Data and Transmitter Control System input\n"
46        "  --rel-id ID           - Set ID of relative stream\n"
47        "  --help                - Show this help\n"
48       );
49
50}
51
52int main (int argc, char * argv[]) {
53 int    rate     = -1;
54 int    bits     = -1;
55 int    channels = -1;
56 int    codec    = -1;
57 int    dir      = ROAR_DIR_PLAY;
58 int    rel_id   = -1;
59 char * server   = NULL;
60 char * k;
61 int    i;
62 char * name = "roarcat";
63 struct roar_connection    con;
64 struct roar_stream        s;
65 struct roar_vio_calls     file, * stream;
66 struct roar_vio_defaults  def;
67 int file_opened = 0;
68
69 if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 )
70  return 1;
71
72 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 )
73  return 1;
74
75 for (i = 1; i < argc; i++) {
76  k = argv[i];
77
78  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
79   server = argv[++i];
80  } else if ( !strcmp(k, "-n") ) {
81   name = argv[++i];
82  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) {
83   rate = roar_str2rate(argv[++i]);
84  } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) {
85   bits = roar_str2bits(argv[++i]);
86  } else if ( !strcmp(k, "-b") ) {
87   bits = 8;
88  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) {
89   channels = roar_str2channels(argv[++i]);
90  } else if ( !strcmp(k, "-m") ) {
91   channels = 1;
92  } else if ( !strcmp(k, "--codec") ) {
93   if ( (codec = roar_str2codec(argv[++i])) == -1 ) {
94    fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]);
95    return 1;
96   }
97
98  } else if ( !strcmp(k, "--wave") ) {
99   dir   = ROAR_DIR_PLAY;
100  } else if ( !strcmp(k, "--midi") ) {
101   dir      = ROAR_DIR_MIDI_IN;
102  } else if ( !strcmp(k, "--light") ) {
103   dir   = ROAR_DIR_LIGHT_IN;
104  } else if ( !strcmp(k, "--raw") ) {
105   dir   = ROAR_DIR_RAW_IN;
106  } else if ( !strcmp(k, "--complex") ) {
107   dir   = ROAR_DIR_COMPLEX_IN;
108  } else if ( !strcmp(k, "--rdtcs") ) {
109   dir   = ROAR_DIR_RDTCS_IN;
110
111  } else if ( !strcmp(k, "--rel-id") ) {
112   rel_id = atoi(argv[++i]);
113
114  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
115   usage();
116   return 0;
117  } else if ( !file_opened ) {
118   file_opened = 1;
119   if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) {
120    fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno));
121    return 1;
122   }
123  } else {
124   fprintf(stderr, "Error: unknown argument: %s\n", k);
125   usage();
126   return 1;
127  }
128 }
129
130 switch (dir) {
131  case ROAR_DIR_PLAY:
132    if ( rate     == -1 ) rate     = ROAR_RATE_DEFAULT;
133    if ( bits     == -1 ) bits     = ROAR_BITS_DEFAULT;
134    if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT;
135    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT;
136   break;
137  case ROAR_DIR_MIDI_IN:
138    if ( rate     == -1 ) rate     = 0;
139    if ( bits     == -1 ) bits     = ROAR_MIDI_BITS;
140    if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT;
141    if ( codec    == -1 ) codec    = ROAR_CODEC_MIDI;
142   break;
143  case ROAR_DIR_LIGHT_IN:
144    if ( rate     == -1 ) rate     = 0;
145    if ( bits     == -1 ) bits     = ROAR_LIGHT_BITS;
146    if ( channels == -1 ) channels = 0;
147    if ( codec    == -1 ) codec    = ROAR_CODEC_DMX512;
148   break;
149  case ROAR_DIR_COMPLEX_IN:
150    if ( rate     == -1 ) rate     = ROAR_COMPLEX_RATE;
151    if ( bits     == -1 ) bits     = ROAR_COMPLEX_BITS;
152    if ( channels == -1 ) channels = ROAR_COMPLEX_CHANNELS;
153    if ( codec    == -1 ) codec    = ROAR_COMPLEX_CODEC;
154   break;
155  case ROAR_DIR_RDTCS_IN:
156    if ( rate     == -1 ) rate     = ROAR_RDTCS_RATE;
157    if ( bits     == -1 ) bits     = ROAR_RDTCS_BITS;
158    if ( channels == -1 ) channels = ROAR_RDTCS_CHANNELS;
159    if ( codec    == -1 ) codec    = ROAR_RDTCS_CODEC;
160   break;
161  case ROAR_DIR_RAW_IN:
162  default:
163    if ( rate     == -1 ) rate     = 0;
164    if ( bits     == -1 ) bits     = 0;
165    if ( channels == -1 ) channels = 0;
166    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT;
167   break;
168 }
169
170 if ( roar_simple_connect(&con, server, name) == -1 ) {
171  fprintf(stderr, "Error: can not connect to server\n");
172  return 10;
173 }
174
175 if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) {
176  fprintf(stderr, "Error: can not create stream\n");
177  roar_disconnect(&con);
178  return 20;
179 }
180
181 if ( rel_id != -1 ) {
182  if ( roar_stream_set_rel_id(&s, rel_id) ) {
183   fprintf(stderr, "Error: can not set id or realative stream\n");
184   roar_disconnect(&con);
185   return 21;
186  }
187 }
188
189 if ( roar_stream_connect(&con, &s, dir) == -1 ) {
190  fprintf(stderr, "Error: can not connect stream to server\n");
191  roar_disconnect(&con);
192  return 11;
193 }
194
195 if ( roar_stream_exec(&con, &s) == -1 ) {
196  fprintf(stderr, "Error: can not exec stream\n");
197  roar_disconnect(&con);
198  return 12;
199 }
200
201 if ( (stream = roar_get_connection_vio2(&con)) == NULL ) {
202  fprintf(stderr, "Error: can not get stream vio\n");
203  roar_disconnect(&con);
204  return 13;
205 }
206
207 roar_vio_copy_data(stream, &file);
208
209 roar_vio_close(stream);
210 roar_vio_close(&file);
211
212 return 0;
213}
214
215//ll
Note: See TracBrowser for help on using the repository browser.