[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 | |
---|
| 29 | void 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" |
---|
[2681] | 43 | " --complex - Use complex input\n" |
---|
[2712] | 44 | " --rdtcs - Use Radio Data and Transmitter Control System input\n" |
---|
[2591] | 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_PLAY; |
---|
[2242] | 57 | int rel_id = -1; |
---|
[0] | 58 | char * server = NULL; |
---|
| 59 | char * k; |
---|
| 60 | int i; |
---|
[1194] | 61 | char * name = "roarcat"; |
---|
[2242] | 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; |
---|
[0] | 67 | |
---|
[2247] | 68 | if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 ) |
---|
[2243] | 69 | return 1; |
---|
| 70 | |
---|
[2246] | 71 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) |
---|
[2243] | 72 | return 1; |
---|
| 73 | |
---|
[0] | 74 | for (i = 1; i < argc; i++) { |
---|
| 75 | k = argv[i]; |
---|
| 76 | |
---|
[1194] | 77 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
[58] | 78 | server = argv[++i]; |
---|
[1194] | 79 | } else if ( !strcmp(k, "-n") ) { |
---|
| 80 | name = argv[++i]; |
---|
[1507] | 81 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) { |
---|
[0] | 82 | rate = atoi(argv[++i]); |
---|
[1507] | 83 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
[0] | 84 | bits = atoi(argv[++i]); |
---|
[1194] | 85 | } else if ( !strcmp(k, "-b") ) { |
---|
| 86 | bits = 8; |
---|
[1507] | 87 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
[0] | 88 | channels = atoi(argv[++i]); |
---|
[1194] | 89 | } else if ( !strcmp(k, "-m") ) { |
---|
| 90 | channels = 1; |
---|
| 91 | } else if ( !strcmp(k, "--codec") ) { |
---|
[1897] | 92 | if ( (codec = roar_str2codec(argv[++i])) == -1 ) { |
---|
| 93 | fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]); |
---|
| 94 | return 1; |
---|
| 95 | } |
---|
[1808] | 96 | |
---|
| 97 | } else if ( !strcmp(k, "--wave") ) { |
---|
| 98 | dir = ROAR_DIR_PLAY; |
---|
| 99 | } else if ( !strcmp(k, "--midi") ) { |
---|
[2407] | 100 | dir = ROAR_DIR_MIDI_IN; |
---|
[1808] | 101 | } else if ( !strcmp(k, "--light") ) { |
---|
| 102 | dir = ROAR_DIR_LIGHT_IN; |
---|
[2241] | 103 | } else if ( !strcmp(k, "--raw") ) { |
---|
| 104 | dir = ROAR_DIR_RAW_IN; |
---|
[2681] | 105 | } else if ( !strcmp(k, "--complex") ) { |
---|
| 106 | dir = ROAR_DIR_COMPLEX_IN; |
---|
[2712] | 107 | } else if ( !strcmp(k, "--rdtcs") ) { |
---|
| 108 | dir = ROAR_DIR_RDTCS_IN; |
---|
[1808] | 109 | |
---|
[2242] | 110 | } else if ( !strcmp(k, "--rel-id") ) { |
---|
| 111 | rel_id = atoi(argv[++i]); |
---|
| 112 | |
---|
[1635] | 113 | } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) { |
---|
[0] | 114 | usage(); |
---|
| 115 | return 0; |
---|
[2242] | 116 | } else if ( !file_opened ) { |
---|
| 117 | file_opened = 1; |
---|
| 118 | if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) { |
---|
[289] | 119 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 120 | return 1; |
---|
| 121 | } |
---|
[0] | 122 | } else { |
---|
| 123 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 124 | usage(); |
---|
| 125 | return 1; |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
[2420] | 129 | switch (dir) { |
---|
| 130 | case ROAR_DIR_PLAY: |
---|
| 131 | if ( rate == -1 ) rate = ROAR_RATE_DEFAULT; |
---|
| 132 | if ( bits == -1 ) bits = ROAR_BITS_DEFAULT; |
---|
| 133 | if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT; |
---|
| 134 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 135 | break; |
---|
| 136 | case ROAR_DIR_MIDI_IN: |
---|
| 137 | if ( rate == -1 ) rate = 0; |
---|
| 138 | if ( bits == -1 ) bits = ROAR_MIDI_BITS; |
---|
| 139 | if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
| 140 | if ( codec == -1 ) codec = ROAR_CODEC_MIDI; |
---|
| 141 | break; |
---|
| 142 | case ROAR_DIR_LIGHT_IN: |
---|
| 143 | if ( rate == -1 ) rate = 0; |
---|
| 144 | if ( bits == -1 ) bits = ROAR_LIGHT_BITS; |
---|
| 145 | if ( channels == -1 ) channels = 0; |
---|
| 146 | if ( codec == -1 ) codec = ROAR_CODEC_DMX512; |
---|
| 147 | break; |
---|
[2681] | 148 | case ROAR_DIR_COMPLEX_IN: |
---|
| 149 | if ( rate == -1 ) rate = ROAR_COMPLEX_RATE; |
---|
| 150 | if ( bits == -1 ) bits = ROAR_COMPLEX_BITS; |
---|
| 151 | if ( channels == -1 ) channels = ROAR_COMPLEX_CHANNELS; |
---|
| 152 | if ( codec == -1 ) codec = ROAR_COMPLEX_CODEC; |
---|
| 153 | break; |
---|
[2712] | 154 | case ROAR_DIR_RDTCS_IN: |
---|
| 155 | if ( rate == -1 ) rate = ROAR_RDTCS_RATE; |
---|
| 156 | if ( bits == -1 ) bits = ROAR_RDTCS_BITS; |
---|
| 157 | if ( channels == -1 ) channels = ROAR_RDTCS_CHANNELS; |
---|
| 158 | if ( codec == -1 ) codec = ROAR_RDTCS_CODEC; |
---|
| 159 | break; |
---|
[2420] | 160 | case ROAR_DIR_RAW_IN: |
---|
| 161 | default: |
---|
| 162 | if ( rate == -1 ) rate = 0; |
---|
| 163 | if ( bits == -1 ) bits = 0; |
---|
| 164 | if ( channels == -1 ) channels = 0; |
---|
| 165 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 166 | break; |
---|
| 167 | } |
---|
| 168 | |
---|
[2646] | 169 | if ( roar_simple_connect(&con, server, "roarcat") == -1 ) { |
---|
[2242] | 170 | fprintf(stderr, "Error: can not connect to server\n"); |
---|
| 171 | return 10; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
| 175 | fprintf(stderr, "Error: can not create stream\n"); |
---|
| 176 | roar_disconnect(&con); |
---|
| 177 | return 20; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | if ( rel_id != -1 ) { |
---|
| 181 | if ( roar_stream_set_rel_id(&s, rel_id) ) { |
---|
| 182 | fprintf(stderr, "Error: can not set id or realative stream\n"); |
---|
| 183 | roar_disconnect(&con); |
---|
| 184 | return 21; |
---|
| 185 | } |
---|
[0] | 186 | } |
---|
| 187 | |
---|
[2242] | 188 | if ( roar_stream_connect(&con, &s, dir) == -1 ) { |
---|
| 189 | fprintf(stderr, "Error: can not connect stream to server\n"); |
---|
| 190 | roar_disconnect(&con); |
---|
| 191 | return 11; |
---|
| 192 | } |
---|
[289] | 193 | |
---|
[2242] | 194 | if ( roar_stream_exec(&con, &s) == -1 ) { |
---|
| 195 | fprintf(stderr, "Error: can not exec stream\n"); |
---|
| 196 | roar_disconnect(&con); |
---|
| 197 | return 12; |
---|
| 198 | } |
---|
[0] | 199 | |
---|
[2242] | 200 | if ( roar_get_connection_vio(&con, &stream) == -1 ) { |
---|
| 201 | fprintf(stderr, "Error: can not get stream vio\n"); |
---|
| 202 | roar_disconnect(&con); |
---|
| 203 | return 13; |
---|
| 204 | } |
---|
[0] | 205 | |
---|
[2242] | 206 | roar_vio_copy_data(&stream, &file); |
---|
| 207 | |
---|
| 208 | roar_vio_close(&stream); |
---|
| 209 | roar_vio_close(&file); |
---|
[292] | 210 | |
---|
[0] | 211 | return 0; |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | //ll |
---|