[0] | 1 | //roarcatad.c: |
---|
| 2 | |
---|
| 3 | #include <roaraudio.h> |
---|
| 4 | |
---|
| 5 | #define BUFSIZE 1024 |
---|
| 6 | |
---|
| 7 | void usage (void) { |
---|
| 8 | printf("roarcat [OPTIONS]...\n"); |
---|
| 9 | |
---|
| 10 | printf("\nOptions:\n\n"); |
---|
| 11 | |
---|
| 12 | printf(" --server SERVER - Set server hostname\n" |
---|
| 13 | " --rate RATE - Set sample rate\n" |
---|
| 14 | " --bits BITS - Set bits per sample\n" |
---|
| 15 | " --chans CHANNELS - Set number of channels\n" |
---|
| 16 | " --help - Show this help\n" |
---|
| 17 | ); |
---|
| 18 | |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | int main (int argc, char * argv[]) { |
---|
| 22 | int rate = 44100; |
---|
| 23 | int bits = 16; |
---|
| 24 | int channels = 2; |
---|
| 25 | int codec = ROAR_CODEC_DEFAULT; |
---|
| 26 | char * server = NULL; |
---|
| 27 | char * k; |
---|
| 28 | int i; |
---|
| 29 | char buf[BUFSIZE]; |
---|
| 30 | struct roar_connection con; |
---|
| 31 | struct roar_stream s; |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | for (i = 1; i < argc; i++) { |
---|
| 35 | k = argv[i]; |
---|
| 36 | |
---|
| 37 | if ( strcmp(k, "--server") == 0 ) { |
---|
[58] | 38 | server = argv[++i]; |
---|
[0] | 39 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
| 40 | rate = atoi(argv[++i]); |
---|
| 41 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
| 42 | bits = atoi(argv[++i]); |
---|
| 43 | } else if ( strcmp(k, "--channels") == 0 ) { |
---|
| 44 | channels = atoi(argv[++i]); |
---|
| 45 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 46 | usage(); |
---|
| 47 | return 0; |
---|
| 48 | } else { |
---|
| 49 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 50 | usage(); |
---|
| 51 | return 1; |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | if ( roar_simple_connect(&con, server, "roarcatad") == -1 ) { |
---|
| 56 | ROAR_DBG("roar_simple_play(*): roar_simple_connect() faild!"); |
---|
| 57 | return -1; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
| 61 | roar_disconnect(&con); |
---|
| 62 | return -1; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | if ( roar_stream_connect(&con, &s, ROAR_DIR_PLAY) == -1 ) { |
---|
| 66 | roar_disconnect(&con); |
---|
| 67 | return -1; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | while((i = read(0, buf, BUFSIZE))) |
---|
| 71 | if (roar_stream_add_data(&con, &s, buf, i) == -1) |
---|
| 72 | break; |
---|
| 73 | |
---|
| 74 | roar_disconnect(&con); |
---|
| 75 | |
---|
| 76 | return 0; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | //ll |
---|