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