[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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[669] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[0] | 26 | #include <roaraudio.h> |
---|
| 27 | |
---|
| 28 | #define BUFSIZE 1024 |
---|
| 29 | |
---|
| 30 | void usage (void) { |
---|
[290] | 31 | printf("roarcat [OPTIONS]... [FILE]\n"); |
---|
[0] | 32 | |
---|
| 33 | printf("\nOptions:\n\n"); |
---|
| 34 | |
---|
[1507] | 35 | printf(" --server SERVER - Set server hostname\n" |
---|
| 36 | " --rate -R RATE - Set sample rate\n" |
---|
| 37 | " --bits -B BITS - Set bits per sample\n" |
---|
| 38 | " --chans -C CHANNELS - Set number of channels\n" |
---|
| 39 | " --codec CODEC - Set the codec\n" |
---|
[1808] | 40 | " --wave - Use Wave Audio (PCM) as input\n" |
---|
| 41 | " --midi - Use MIDI Audio as input\n" |
---|
| 42 | " --light - Use light control input\n" |
---|
[2241] | 43 | " --raw - Use raw input\n" |
---|
[2681] | 44 | " --complex - Use complex input\n" |
---|
[2712] | 45 | " --rdtcs - Use Radio Data and Transmitter Control System input\n" |
---|
[2591] | 46 | " --rel-id ID - Set ID of relative stream\n" |
---|
[1507] | 47 | " --help - Show this help\n" |
---|
[0] | 48 | ); |
---|
| 49 | |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | int main (int argc, char * argv[]) { |
---|
[2420] | 53 | int rate = -1; |
---|
| 54 | int bits = -1; |
---|
| 55 | int channels = -1; |
---|
| 56 | int codec = -1; |
---|
[1808] | 57 | int dir = ROAR_DIR_PLAY; |
---|
[2242] | 58 | int rel_id = -1; |
---|
[0] | 59 | char * server = NULL; |
---|
| 60 | char * k; |
---|
| 61 | int i; |
---|
[1194] | 62 | char * name = "roarcat"; |
---|
[2242] | 63 | struct roar_connection con; |
---|
| 64 | struct roar_stream s; |
---|
| 65 | struct roar_vio_calls file, stream; |
---|
| 66 | struct roar_vio_defaults def; |
---|
| 67 | int file_opened = 0; |
---|
[0] | 68 | |
---|
[2247] | 69 | if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 ) |
---|
[2243] | 70 | return 1; |
---|
| 71 | |
---|
[2246] | 72 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) |
---|
[2243] | 73 | return 1; |
---|
| 74 | |
---|
[0] | 75 | for (i = 1; i < argc; i++) { |
---|
| 76 | k = argv[i]; |
---|
| 77 | |
---|
[1194] | 78 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
[58] | 79 | server = argv[++i]; |
---|
[1194] | 80 | } else if ( !strcmp(k, "-n") ) { |
---|
| 81 | name = argv[++i]; |
---|
[1507] | 82 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) { |
---|
[0] | 83 | rate = atoi(argv[++i]); |
---|
[1507] | 84 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
[0] | 85 | bits = atoi(argv[++i]); |
---|
[1194] | 86 | } else if ( !strcmp(k, "-b") ) { |
---|
| 87 | bits = 8; |
---|
[1507] | 88 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
[0] | 89 | channels = atoi(argv[++i]); |
---|
[1194] | 90 | } else if ( !strcmp(k, "-m") ) { |
---|
| 91 | channels = 1; |
---|
| 92 | } else if ( !strcmp(k, "--codec") ) { |
---|
[1897] | 93 | if ( (codec = roar_str2codec(argv[++i])) == -1 ) { |
---|
| 94 | fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]); |
---|
| 95 | return 1; |
---|
| 96 | } |
---|
[1808] | 97 | |
---|
| 98 | } else if ( !strcmp(k, "--wave") ) { |
---|
| 99 | dir = ROAR_DIR_PLAY; |
---|
| 100 | } else if ( !strcmp(k, "--midi") ) { |
---|
[2407] | 101 | dir = ROAR_DIR_MIDI_IN; |
---|
[1808] | 102 | } else if ( !strcmp(k, "--light") ) { |
---|
| 103 | dir = ROAR_DIR_LIGHT_IN; |
---|
[2241] | 104 | } else if ( !strcmp(k, "--raw") ) { |
---|
| 105 | dir = ROAR_DIR_RAW_IN; |
---|
[2681] | 106 | } else if ( !strcmp(k, "--complex") ) { |
---|
| 107 | dir = ROAR_DIR_COMPLEX_IN; |
---|
[2712] | 108 | } else if ( !strcmp(k, "--rdtcs") ) { |
---|
| 109 | dir = ROAR_DIR_RDTCS_IN; |
---|
[1808] | 110 | |
---|
[2242] | 111 | } else if ( !strcmp(k, "--rel-id") ) { |
---|
| 112 | rel_id = atoi(argv[++i]); |
---|
| 113 | |
---|
[1635] | 114 | } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) { |
---|
[0] | 115 | usage(); |
---|
| 116 | return 0; |
---|
[2242] | 117 | } else if ( !file_opened ) { |
---|
| 118 | file_opened = 1; |
---|
| 119 | if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) { |
---|
[289] | 120 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 121 | return 1; |
---|
| 122 | } |
---|
[0] | 123 | } else { |
---|
| 124 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 125 | usage(); |
---|
| 126 | return 1; |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
[2420] | 130 | switch (dir) { |
---|
| 131 | case ROAR_DIR_PLAY: |
---|
| 132 | if ( rate == -1 ) rate = ROAR_RATE_DEFAULT; |
---|
| 133 | if ( bits == -1 ) bits = ROAR_BITS_DEFAULT; |
---|
| 134 | if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT; |
---|
| 135 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 136 | break; |
---|
| 137 | case ROAR_DIR_MIDI_IN: |
---|
| 138 | if ( rate == -1 ) rate = 0; |
---|
| 139 | if ( bits == -1 ) bits = ROAR_MIDI_BITS; |
---|
| 140 | if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT; |
---|
| 141 | if ( codec == -1 ) codec = ROAR_CODEC_MIDI; |
---|
| 142 | break; |
---|
| 143 | case ROAR_DIR_LIGHT_IN: |
---|
| 144 | if ( rate == -1 ) rate = 0; |
---|
| 145 | if ( bits == -1 ) bits = ROAR_LIGHT_BITS; |
---|
| 146 | if ( channels == -1 ) channels = 0; |
---|
| 147 | if ( codec == -1 ) codec = ROAR_CODEC_DMX512; |
---|
| 148 | break; |
---|
[2681] | 149 | case ROAR_DIR_COMPLEX_IN: |
---|
| 150 | if ( rate == -1 ) rate = ROAR_COMPLEX_RATE; |
---|
| 151 | if ( bits == -1 ) bits = ROAR_COMPLEX_BITS; |
---|
| 152 | if ( channels == -1 ) channels = ROAR_COMPLEX_CHANNELS; |
---|
| 153 | if ( codec == -1 ) codec = ROAR_COMPLEX_CODEC; |
---|
| 154 | break; |
---|
[2712] | 155 | case ROAR_DIR_RDTCS_IN: |
---|
| 156 | if ( rate == -1 ) rate = ROAR_RDTCS_RATE; |
---|
| 157 | if ( bits == -1 ) bits = ROAR_RDTCS_BITS; |
---|
| 158 | if ( channels == -1 ) channels = ROAR_RDTCS_CHANNELS; |
---|
| 159 | if ( codec == -1 ) codec = ROAR_RDTCS_CODEC; |
---|
| 160 | break; |
---|
[2420] | 161 | case ROAR_DIR_RAW_IN: |
---|
| 162 | default: |
---|
| 163 | if ( rate == -1 ) rate = 0; |
---|
| 164 | if ( bits == -1 ) bits = 0; |
---|
| 165 | if ( channels == -1 ) channels = 0; |
---|
| 166 | if ( codec == -1 ) codec = ROAR_CODEC_DEFAULT; |
---|
| 167 | break; |
---|
| 168 | } |
---|
| 169 | |
---|
[3126] | 170 | if ( roar_simple_connect(&con, server, name) == -1 ) { |
---|
[2242] | 171 | fprintf(stderr, "Error: can not connect to server\n"); |
---|
| 172 | return 10; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
| 176 | fprintf(stderr, "Error: can not create stream\n"); |
---|
| 177 | roar_disconnect(&con); |
---|
| 178 | return 20; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | if ( rel_id != -1 ) { |
---|
| 182 | if ( roar_stream_set_rel_id(&s, rel_id) ) { |
---|
| 183 | fprintf(stderr, "Error: can not set id or realative stream\n"); |
---|
| 184 | roar_disconnect(&con); |
---|
| 185 | return 21; |
---|
| 186 | } |
---|
[0] | 187 | } |
---|
| 188 | |
---|
[2242] | 189 | if ( roar_stream_connect(&con, &s, dir) == -1 ) { |
---|
| 190 | fprintf(stderr, "Error: can not connect stream to server\n"); |
---|
| 191 | roar_disconnect(&con); |
---|
| 192 | return 11; |
---|
| 193 | } |
---|
[289] | 194 | |
---|
[2242] | 195 | if ( roar_stream_exec(&con, &s) == -1 ) { |
---|
| 196 | fprintf(stderr, "Error: can not exec stream\n"); |
---|
| 197 | roar_disconnect(&con); |
---|
| 198 | return 12; |
---|
| 199 | } |
---|
[0] | 200 | |
---|
[2242] | 201 | if ( roar_get_connection_vio(&con, &stream) == -1 ) { |
---|
| 202 | fprintf(stderr, "Error: can not get stream vio\n"); |
---|
| 203 | roar_disconnect(&con); |
---|
| 204 | return 13; |
---|
| 205 | } |
---|
[0] | 206 | |
---|
[2242] | 207 | roar_vio_copy_data(&stream, &file); |
---|
| 208 | |
---|
| 209 | roar_vio_close(&stream); |
---|
| 210 | roar_vio_close(&file); |
---|
[292] | 211 | |
---|
[0] | 212 | return 0; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | //ll |
---|