source: roaraudio/roarclients/roarcat.c @ 2241:1545a04f0255

Last change on this file since 2241:1545a04f0255 was 2241:1545a04f0255, checked in by phi, 15 years ago

added --raw to roarcat/roarmon

File size: 3.8 KB
RevLine 
[0]1//roarcat.c:
2
[669]3/*
[2044]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008, 2009
[669]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
[0]25#include <roaraudio.h>
26
27#define BUFSIZE 1024
28
29void usage (void) {
[290]30 printf("roarcat [OPTIONS]... [FILE]\n");
[0]31
32 printf("\nOptions:\n\n");
33
[1507]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"
[1808]39        "  --wave                - Use Wave Audio (PCM) as input\n"
40        "  --midi                - Use MIDI Audio as input\n"
41        "  --light               - Use light control input\n"
[2241]42        "  --raw                 - Use raw input\n"
[1507]43        "  --help                - Show this help\n"
[0]44       );
45
46}
47
48int main (int argc, char * argv[]) {
[1194]49 int    rate     = ROAR_RATE_DEFAULT;
50 int    bits     = ROAR_BITS_DEFAULT;
51 int    channels = ROAR_CHANNELS_DEFAULT;
[0]52 int    codec    = ROAR_CODEC_DEFAULT;
[1808]53 int    dir      = ROAR_DIR_PLAY;
[0]54 char * server   = NULL;
55 char * k;
56 int    fh;
57 int    i;
[289]58 int    in = -1;
[1194]59 char * name = "roarcat";
[0]60 char buf[BUFSIZE];
61
62 for (i = 1; i < argc; i++) {
63  k = argv[i];
64
[1194]65  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
[58]66   server = argv[++i];
[1194]67  } else if ( !strcmp(k, "-n") ) {
68   name = argv[++i];
[1507]69  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) {
[0]70   rate = atoi(argv[++i]);
[1507]71  } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) {
[0]72   bits = atoi(argv[++i]);
[1194]73  } else if ( !strcmp(k, "-b") ) {
74   bits = 8;
[1507]75  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) {
[0]76   channels = atoi(argv[++i]);
[1194]77  } else if ( !strcmp(k, "-m") ) {
78   channels = 1;
79  } else if ( !strcmp(k, "--codec") ) {
[1897]80   if ( (codec = roar_str2codec(argv[++i])) == -1 ) {
81    fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]);
82    return 1;
83   }
[1808]84
85  } else if ( !strcmp(k, "--wave") ) {
86   dir   = ROAR_DIR_PLAY;
87  } else if ( !strcmp(k, "--midi") ) {
88   dir   = ROAR_DIR_MIDI_IN;
[1897]89   if ( codec == ROAR_CODEC_DEFAULT )
90    codec = ROAR_CODEC_MIDI;
[1808]91  } else if ( !strcmp(k, "--light") ) {
92   dir   = ROAR_DIR_LIGHT_IN;
[1897]93   if ( codec == ROAR_CODEC_DEFAULT )
94    codec = ROAR_CODEC_DMX512;
[2241]95  } else if ( !strcmp(k, "--raw") ) {
96   dir   = ROAR_DIR_RAW_IN;
[1808]97
[1635]98  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
[0]99   usage();
100   return 0;
[289]101  } else if ( in == -1 ) {
102   if ( (in = open(k, O_RDONLY, 0644)) == -1 ) {
103    fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno));
104    return 1;
105   }
[0]106  } else {
107   fprintf(stderr, "Error: unknown argument: %s\n", k);
108   usage();
109   return 1;
110  }
111 }
112
[1808]113 if ( (fh = roar_simple_stream(rate, channels, bits, codec, server, dir, name)) == -1 ) {
[0]114  fprintf(stderr, "Error: can not start playback\n");
115  return 1;
116 }
117
[289]118 if ( in == -1 )
119  in = ROAR_STDIN;
120
121 while((i = read(in, buf, BUFSIZE)))
[0]122  if (write(fh, buf, i) != i)
123   break;
124
125 roar_simple_close(fh);
126
[292]127 close(in);
128
[0]129 return 0;
130}
131
132//ll
Note: See TracBrowser for help on using the repository browser.