[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 | |
---|
| 29 | void 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" |
---|
[1814] | 43 | " --rel-id ID - Set ID of relative stream\n" |
---|
[1507] | 44 | " --help - Show this help\n" |
---|
[0] | 45 | ); |
---|
| 46 | |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | int main (int argc, char * argv[]) { |
---|
[1195] | 50 | int rate = ROAR_RATE_DEFAULT; |
---|
| 51 | int bits = ROAR_BITS_DEFAULT; |
---|
| 52 | int channels = ROAR_CHANNELS_DEFAULT; |
---|
[0] | 53 | int codec = ROAR_CODEC_DEFAULT; |
---|
[1808] | 54 | int dir = ROAR_DIR_MONITOR; |
---|
[1814] | 55 | int rel_id = -1; |
---|
[0] | 56 | char * server = NULL; |
---|
| 57 | char * k; |
---|
| 58 | int fh; |
---|
| 59 | int i; |
---|
[991] | 60 | int out = -1; |
---|
[0] | 61 | char buf[BUFSIZE]; |
---|
[1814] | 62 | struct roar_connection con; |
---|
| 63 | struct roar_stream s; |
---|
[0] | 64 | |
---|
| 65 | for (i = 1; i < argc; i++) { |
---|
| 66 | k = argv[i]; |
---|
| 67 | |
---|
[1195] | 68 | // esdmon [-s server ][-b] [-m] [-r freq] < file |
---|
| 69 | |
---|
| 70 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
[58] | 71 | server = argv[++i]; |
---|
[1507] | 72 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) { |
---|
[0] | 73 | rate = atoi(argv[++i]); |
---|
[1507] | 74 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
[0] | 75 | bits = atoi(argv[++i]); |
---|
[1195] | 76 | } else if ( !strcmp(k, "-b") ) { |
---|
| 77 | bits = 8; |
---|
[1507] | 78 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
[0] | 79 | channels = atoi(argv[++i]); |
---|
[1195] | 80 | } else if ( !strcmp(k, "-m") ) { |
---|
| 81 | channels = 2; |
---|
| 82 | } else if ( !strcmp(k, "--codec") ) { |
---|
[570] | 83 | codec = roar_str2codec(argv[++i]); |
---|
[1808] | 84 | |
---|
| 85 | } else if ( !strcmp(k, "--wave") ) { |
---|
| 86 | dir = ROAR_DIR_MONITOR; |
---|
| 87 | } else if ( !strcmp(k, "--midi") ) { |
---|
| 88 | dir = ROAR_DIR_MIDI_OUT; |
---|
| 89 | } else if ( !strcmp(k, "--light") ) { |
---|
| 90 | dir = ROAR_DIR_LIGHT_OUT; |
---|
| 91 | } else if ( !strcmp(k, "--thru") ) { |
---|
| 92 | dir = ROAR_DIR_THRU; |
---|
[1814] | 93 | } else if ( !strcmp(k, "--rel-id") ) { |
---|
| 94 | rel_id = atoi(argv[++i]); |
---|
[1808] | 95 | |
---|
[1635] | 96 | } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) { |
---|
[0] | 97 | usage(); |
---|
| 98 | return 0; |
---|
[991] | 99 | } else if ( out == -1 ) { |
---|
| 100 | if ( (out = open(k, O_CREAT|O_TRUNC|O_WRONLY, 0644)) == -1 ) { |
---|
| 101 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 102 | return 1; |
---|
| 103 | } |
---|
[0] | 104 | } else { |
---|
| 105 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 106 | usage(); |
---|
| 107 | return 1; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
[991] | 111 | if ( out == -1 ) |
---|
| 112 | out = ROAR_STDOUT; |
---|
| 113 | |
---|
[1814] | 114 | if ( roar_simple_connect(&con, server, "roarmon") == -1 ) { |
---|
| 115 | fprintf(stderr, "Error: can not connect to server\n"); |
---|
| 116 | return 10; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
| 120 | fprintf(stderr, "Error: can not create stream\n"); |
---|
| 121 | roar_disconnect(&con); |
---|
| 122 | return 20; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | if ( rel_id != -1 ) { |
---|
| 126 | if ( roar_stream_set_rel_id(&s, rel_id) ) { |
---|
| 127 | fprintf(stderr, "Error: can not set id or realative stream\n"); |
---|
| 128 | roar_disconnect(&con); |
---|
| 129 | return 21; |
---|
| 130 | } |
---|
[0] | 131 | } |
---|
| 132 | |
---|
[1814] | 133 | if ( roar_stream_connect(&con, &s, dir) == -1 ) { |
---|
| 134 | fprintf(stderr, "Error: can not connect stream to server\n"); |
---|
| 135 | roar_disconnect(&con); |
---|
| 136 | return 11; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | if ( roar_stream_exec(&con, &s) == -1 ) { |
---|
| 140 | fprintf(stderr, "Error: can not exec stream\n"); |
---|
| 141 | roar_disconnect(&con); |
---|
| 142 | return 12; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | if ( (fh = roar_get_connection_fh(&con)) == -1 ) { |
---|
| 146 | fprintf(stderr, "Error: can not get stream fh\n"); |
---|
| 147 | roar_disconnect(&con); |
---|
| 148 | return 13; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | ROAR_SHUTDOWN(fh, SHUT_WR); |
---|
| 152 | |
---|
[0] | 153 | while((i = read(fh, buf, BUFSIZE))) |
---|
[991] | 154 | if (write(out, buf, i) != i) |
---|
[0] | 155 | break; |
---|
| 156 | |
---|
| 157 | roar_simple_close(fh); |
---|
| 158 | |
---|
| 159 | return 0; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | //ll |
---|