source: roaraudio/roarclients/roarmon.c @ 2712:af9178518e1b

Last change on this file since 2712:af9178518e1b was 2712:af9178518e1b, checked in by phi, 15 years ago

added RDTCS to basic tools

File size: 6.7 KB
Line 
1//roarmon.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("roarmon [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               - Output Wave Audio (PCM)\n"
40        "  --midi               - Output MIDI Audio\n"
41        "  --light              - Output light control\n"
42        "  --raw                - Output raw data\n"
43        "  --complex            - Output complex data\n"
44        "  --rdtcs              - Output Radio Data and Transmitter Control System data\n"
45        "  --thru               - Output copy of other stream\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_MONITOR;
58 int    rel_id   = -1;
59 char * server   = NULL;
60 char * k;
61 int    i;
62 struct roar_connection    con;
63 struct roar_stream        s;
64 struct roar_vio_calls     file, stream;
65 struct roar_vio_defaults  def;
66 int file_opened = 0;
67
68 if ( roar_vio_open_fh(&file, ROAR_STDOUT) == -1 )
69  return 1;
70
71 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_CREAT|O_TRUNC|O_WRONLY, 0644) == -1 )
72  return 1;
73
74 for (i = 1; i < argc; i++) {
75  k = argv[i];
76
77 //         esdmon [-s server ][-b] [-m] [-r freq] < file
78
79  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
80   server = argv[++i];
81  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) {
82   rate = atoi(argv[++i]);
83  } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) {
84   bits = atoi(argv[++i]);
85  } else if ( !strcmp(k, "-b") ) {
86   bits = 8;
87  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) {
88   channels = atoi(argv[++i]);
89  } else if ( !strcmp(k, "-m") ) {
90   channels = 2;
91  } else if ( !strcmp(k, "--codec") ) {
92   if ( (codec = roar_str2codec(argv[++i])) == -1 ) {
93    fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]);
94    return 1;
95   }
96
97  } else if ( !strcmp(k, "--wave") ) {
98   dir   = ROAR_DIR_MONITOR;
99  } else if ( !strcmp(k, "--midi") ) {
100   dir      = ROAR_DIR_MIDI_OUT;
101  } else if ( !strcmp(k, "--light") ) {
102   dir   = ROAR_DIR_LIGHT_OUT;
103  } else if ( !strcmp(k, "--raw") ) {
104   dir   = ROAR_DIR_RAW_OUT;
105  } else if ( !strcmp(k, "--complex") ) {
106   dir   = ROAR_DIR_COMPLEX_OUT;
107  } else if ( !strcmp(k, "--rdtcs") ) {
108   dir   = ROAR_DIR_RDTCS_OUT;
109  } else if ( !strcmp(k, "--thru") ) {
110   dir   = ROAR_DIR_THRU;
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_MONITOR:
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_OUT:
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_OUT:
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_OUT:
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_OUT:
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_OUT:
162  case ROAR_DIR_THRU:
163  default:
164    if ( rate     == -1 ) rate     = 0;
165    if ( bits     == -1 ) bits     = 0;
166    if ( channels == -1 ) channels = 0;
167    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT;
168   break;
169 }
170
171 if ( roar_simple_connect(&con, server, "roarmon") == -1 ) {
172  fprintf(stderr, "Error: can not connect to server\n");
173  return 10;
174 }
175
176 if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) {
177  fprintf(stderr, "Error: can not create stream\n");
178  roar_disconnect(&con);
179  return 20;
180 }
181
182 if ( rel_id != -1 ) {
183  if ( roar_stream_set_rel_id(&s, rel_id) ) {
184   fprintf(stderr, "Error: can not set id or realative stream\n");
185   roar_disconnect(&con);
186   return 21;
187  }
188 }
189
190 if ( roar_stream_connect(&con, &s, dir) == -1 ) {
191  fprintf(stderr, "Error: can not connect stream to server\n");
192  roar_disconnect(&con);
193  return 11;
194 }
195
196 if ( roar_stream_exec(&con, &s) == -1 ) {
197  fprintf(stderr, "Error: can not exec stream\n");
198  roar_disconnect(&con);
199  return 12;
200 }
201
202 if ( roar_get_connection_vio(&con, &stream) == -1 ) {
203  fprintf(stderr, "Error: can not get stream vio\n");
204  roar_disconnect(&con);
205  return 13;
206 }
207
208// TODO: FIXME:
209// ROAR_SHUTDOWN(fh, SHUT_WR); // we need to have something do do shutdowns here...
210
211 roar_vio_copy_data(&file, &stream);
212
213 roar_vio_close(&stream);
214 roar_vio_close(&file);
215
216 return 0;
217}
218
219//ll
Note: See TracBrowser for help on using the repository browser.