[2292] | 1 | //roarmon.c: |
---|
[0] | 2 | |
---|
[669] | 3 | /* |
---|
[2045] | 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 | |
---|
| 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" |
---|
[2241] | 42 | " --raw - Output raw data\n" |
---|
[2681] | 43 | " --complex - Output complex data\n" |
---|
[1808] | 44 | " --thru - Output copy of other stream\n" |
---|
[1814] | 45 | " --rel-id ID - Set ID of relative stream\n" |
---|
[1507] | 46 | " --help - Show this help\n" |
---|
[0] | 47 | ); |
---|
| 48 | |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | int main (int argc, char * argv[]) { |
---|
[2420] | 52 | int rate = -1; |
---|
| 53 | int bits = -1; |
---|
| 54 | int channels = -1; |
---|
| 55 | int codec = -1; |
---|
[1808] | 56 | int dir = ROAR_DIR_MONITOR; |
---|
[1814] | 57 | int rel_id = -1; |
---|
[0] | 58 | char * server = NULL; |
---|
| 59 | char * k; |
---|
| 60 | int i; |
---|
[2045] | 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_STDOUT) == -1 ) |
---|
| 68 | return 1; |
---|
| 69 | |
---|
| 70 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_CREAT|O_TRUNC|O_WRONLY, 0644) == -1 ) |
---|
| 71 | return 1; |
---|
[0] | 72 | |
---|
| 73 | for (i = 1; i < argc; i++) { |
---|
| 74 | k = argv[i]; |
---|
| 75 | |
---|
[1195] | 76 | // esdmon [-s server ][-b] [-m] [-r freq] < file |
---|
| 77 | |
---|
| 78 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
[58] | 79 | server = argv[++i]; |
---|
[1507] | 80 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) { |
---|
[0] | 81 | rate = atoi(argv[++i]); |
---|
[1507] | 82 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
[0] | 83 | bits = atoi(argv[++i]); |
---|
[1195] | 84 | } else if ( !strcmp(k, "-b") ) { |
---|
| 85 | bits = 8; |
---|
[1507] | 86 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
[0] | 87 | channels = atoi(argv[++i]); |
---|
[1195] | 88 | } else if ( !strcmp(k, "-m") ) { |
---|
| 89 | channels = 2; |
---|
| 90 | } else if ( !strcmp(k, "--codec") ) { |
---|
[1897] | 91 | if ( (codec = roar_str2codec(argv[++i])) == -1 ) { |
---|
| 92 | fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]); |
---|
| 93 | return 1; |
---|
| 94 | } |
---|
[1808] | 95 | |
---|
| 96 | } else if ( !strcmp(k, "--wave") ) { |
---|
| 97 | dir = ROAR_DIR_MONITOR; |
---|
| 98 | } else if ( !strcmp(k, "--midi") ) { |
---|
[2407] | 99 | dir = ROAR_DIR_MIDI_OUT; |
---|
[1808] | 100 | } else if ( !strcmp(k, "--light") ) { |
---|
| 101 | dir = ROAR_DIR_LIGHT_OUT; |
---|
[2241] | 102 | } else if ( !strcmp(k, "--raw") ) { |
---|
| 103 | dir = ROAR_DIR_RAW_OUT; |
---|
[2681] | 104 | } else if ( !strcmp(k, "--complex") ) { |
---|
| 105 | dir = ROAR_DIR_COMPLEX_OUT; |
---|
[1808] | 106 | } else if ( !strcmp(k, "--thru") ) { |
---|
| 107 | dir = ROAR_DIR_THRU; |
---|
[1814] | 108 | } else if ( !strcmp(k, "--rel-id") ) { |
---|
| 109 | rel_id = atoi(argv[++i]); |
---|
[1808] | 110 | |
---|
[1635] | 111 | } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) { |
---|
[0] | 112 | usage(); |
---|
| 113 | return 0; |
---|
[2045] | 114 | } else if ( !file_opened ) { |
---|
| 115 | file_opened = 1; |
---|
| 116 | if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) { |
---|
[991] | 117 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 118 | return 1; |
---|
| 119 | } |
---|
[0] | 120 | } else { |
---|
| 121 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 122 | usage(); |
---|
| 123 | return 1; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
[2420] | 127 | switch (dir) { |
---|
| 128 | case ROAR_DIR_MONITOR: |
---|
| 129 | if ( rate == -1 ) rate = ROAR_RATE_DEFAULT; |
---|
| 130 | if ( bits == -1 ) bits = ROAR_BITS_DEFAULT; |
---|
| 131 | if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT; |
---|
| 132 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 133 | break; |
---|
| 134 | case ROAR_DIR_MIDI_OUT: |
---|
| 135 | if ( rate == -1 ) rate = 0; |
---|
| 136 | if ( bits == -1 ) bits = ROAR_MIDI_BITS; |
---|
| 137 | if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
| 138 | if ( codec == -1 ) codec = ROAR_CODEC_MIDI; |
---|
| 139 | break; |
---|
| 140 | case ROAR_DIR_LIGHT_OUT: |
---|
| 141 | if ( rate == -1 ) rate = 0; |
---|
| 142 | if ( bits == -1 ) bits = ROAR_LIGHT_BITS; |
---|
| 143 | if ( channels == -1 ) channels = 0; |
---|
| 144 | if ( codec == -1 ) codec = ROAR_CODEC_DMX512; |
---|
| 145 | break; |
---|
[2681] | 146 | case ROAR_DIR_COMPLEX_IN: |
---|
| 147 | if ( rate == -1 ) rate = ROAR_COMPLEX_RATE; |
---|
| 148 | if ( bits == -1 ) bits = ROAR_COMPLEX_BITS; |
---|
| 149 | if ( channels == -1 ) channels = ROAR_COMPLEX_CHANNELS; |
---|
| 150 | if ( codec == -1 ) codec = ROAR_COMPLEX_CODEC; |
---|
| 151 | break; |
---|
[2420] | 152 | case ROAR_DIR_RAW_OUT: |
---|
| 153 | case ROAR_DIR_THRU: |
---|
| 154 | default: |
---|
| 155 | if ( rate == -1 ) rate = 0; |
---|
| 156 | if ( bits == -1 ) bits = 0; |
---|
| 157 | if ( channels == -1 ) channels = 0; |
---|
| 158 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 159 | break; |
---|
| 160 | } |
---|
| 161 | |
---|
[1814] | 162 | if ( roar_simple_connect(&con, server, "roarmon") == -1 ) { |
---|
| 163 | fprintf(stderr, "Error: can not connect to server\n"); |
---|
| 164 | return 10; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
| 168 | fprintf(stderr, "Error: can not create stream\n"); |
---|
| 169 | roar_disconnect(&con); |
---|
| 170 | return 20; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | if ( rel_id != -1 ) { |
---|
| 174 | if ( roar_stream_set_rel_id(&s, rel_id) ) { |
---|
| 175 | fprintf(stderr, "Error: can not set id or realative stream\n"); |
---|
| 176 | roar_disconnect(&con); |
---|
| 177 | return 21; |
---|
| 178 | } |
---|
[0] | 179 | } |
---|
| 180 | |
---|
[1814] | 181 | if ( roar_stream_connect(&con, &s, dir) == -1 ) { |
---|
| 182 | fprintf(stderr, "Error: can not connect stream to server\n"); |
---|
| 183 | roar_disconnect(&con); |
---|
| 184 | return 11; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | if ( roar_stream_exec(&con, &s) == -1 ) { |
---|
| 188 | fprintf(stderr, "Error: can not exec stream\n"); |
---|
| 189 | roar_disconnect(&con); |
---|
| 190 | return 12; |
---|
| 191 | } |
---|
| 192 | |
---|
[2045] | 193 | if ( roar_get_connection_vio(&con, &stream) == -1 ) { |
---|
| 194 | fprintf(stderr, "Error: can not get stream vio\n"); |
---|
[1814] | 195 | roar_disconnect(&con); |
---|
| 196 | return 13; |
---|
| 197 | } |
---|
| 198 | |
---|
[2045] | 199 | // TODO: FIXME: |
---|
| 200 | // ROAR_SHUTDOWN(fh, SHUT_WR); // we need to have something do do shutdowns here... |
---|
[1814] | 201 | |
---|
[2045] | 202 | roar_vio_copy_data(&file, &stream); |
---|
[0] | 203 | |
---|
[2045] | 204 | roar_vio_close(&stream); |
---|
| 205 | roar_vio_close(&file); |
---|
[0] | 206 | |
---|
| 207 | return 0; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | //ll |
---|