source: roaraudio/roarclients/roarmon.c @ 1808:073dbd2723d0

Last change on this file since 1808:073dbd2723d0 was 1808:073dbd2723d0, checked in by phi, 15 years ago

added --wave, --midi, --light and --thru (only roarmon) to roarcat/roarmon

File size: 3.5 KB
RevLine 
[0]1//roarcat.c:
2
[669]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
[0]25#include <roaraudio.h>
26
27#define BUFSIZE 1024
28
29void usage (void) {
[991]30 printf("roarmon [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               - Output Wave Audio (PCM)\n"
40        "  --midi               - Output MIDI Audio\n"
41        "  --light              - Output light control\n"
42        "  --thru               - Output copy of other stream\n"
[1507]43        "  --help               - Show this help\n"
[0]44       );
45
46}
47
48int main (int argc, char * argv[]) {
[1195]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_MONITOR;
[0]54 char * server   = NULL;
55 char * k;
56 int    fh;
57 int    i;
[991]58 int    out = -1;
[0]59 char buf[BUFSIZE];
60
61 for (i = 1; i < argc; i++) {
62  k = argv[i];
63
[1195]64 //         esdmon [-s server ][-b] [-m] [-r freq] < file
65
66  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
[58]67   server = argv[++i];
[1507]68  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) {
[0]69   rate = atoi(argv[++i]);
[1507]70  } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) {
[0]71   bits = atoi(argv[++i]);
[1195]72  } else if ( !strcmp(k, "-b") ) {
73   bits = 8;
[1507]74  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) {
[0]75   channels = atoi(argv[++i]);
[1195]76  } else if ( !strcmp(k, "-m") ) {
77   channels = 2;
78  } else if ( !strcmp(k, "--codec") ) {
[570]79   codec = roar_str2codec(argv[++i]);
[1808]80
81  } else if ( !strcmp(k, "--wave") ) {
82   dir   = ROAR_DIR_MONITOR;
83  } else if ( !strcmp(k, "--midi") ) {
84   dir   = ROAR_DIR_MIDI_OUT;
85  } else if ( !strcmp(k, "--light") ) {
86   dir   = ROAR_DIR_LIGHT_OUT;
87  } else if ( !strcmp(k, "--thru") ) {
88   dir   = ROAR_DIR_THRU;
89
[1635]90  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
[0]91   usage();
92   return 0;
[991]93  } else if ( out == -1 ) {
94   if ( (out = open(k, O_CREAT|O_TRUNC|O_WRONLY, 0644)) == -1 ) {
95    fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno));
96    return 1;
97   }
[0]98  } else {
99   fprintf(stderr, "Error: unknown argument: %s\n", k);
100   usage();
101   return 1;
102  }
103 }
104
[991]105 if ( out == -1 )
106  out = ROAR_STDOUT;
107
[1808]108 if ( (fh = roar_simple_stream(rate, channels, bits, codec, server, dir, "roarmon")) == -1 ) {
[991]109  fprintf(stderr, "Error: can not start monitoring\n");
[0]110  return 1;
111 }
112
113 while((i = read(fh, buf, BUFSIZE)))
[991]114  if (write(out, buf, i) != i)
[0]115   break;
116
117 roar_simple_close(fh);
118
119 return 0;
120}
121
122//ll
Note: See TracBrowser for help on using the repository browser.