source: roaraudio/roarclients/roarcat.c @ 2681:359a85bcf5e9

Last change on this file since 2681:359a85bcf5e9 was 2681:359a85bcf5e9, checked in by phi, 15 years ago

added new subsystem complex

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