source: roaraudio/roarclients/roarcat2sock.c @ 5249:26fb6a2e20fc

Last change on this file since 5249:26fb6a2e20fc was 5109:4f9fc788fe91, checked in by phi, 13 years ago

Started to use compiler attributes (Also see: #130)

File size: 2.5 KB
Line 
1//roarcat2sock.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27
28#define BUFSIZE 1024
29
30void usage (void) {
31 printf("roarcat2sock [OPTIONS]...\n");
32
33 printf("\nOptions:\n\n");
34
35 printf("  --server SERVER    - Set server hostname\n"
36        "  --rate   RATE      - Set sample rate\n"
37        "  --bits   BITS      - Set bits per sample\n"
38        "  --chans  CHANNELS  - Set number of channels\n"
39        "  --help             - Show this help\n"
40       );
41
42}
43
44int main (int argc, char * argv[]) {
45 int    rate     = 44100;
46 int    bits     = 16;
47 int    channels = 2;
48 int    codec    = ROAR_CODEC_DEFAULT;
49 char * server   = NULL;
50 char * k;
51 int    i;
52 int    fh;
53 char buf[BUFSIZE];
54 struct roar_connection con;
55
56
57 roar_debug_bin_obsolete(argv[0], "roarcat", NULL);
58
59 for (i = 1; i < argc; i++) {
60  k = argv[i];
61
62  if ( strcmp(k, "--server") == 0 ) {
63   server = argv[++i];
64  } else if ( strcmp(k, "--rate") == 0 ) {
65   rate = atoi(argv[++i]);
66  } else if ( strcmp(k, "--bits") == 0 ) {
67   bits = atoi(argv[++i]);
68  } else if ( strcmp(k, "--channels") == 0 ) {
69   channels = atoi(argv[++i]);
70  } else if ( strcmp(k, "--help") == 0 ) {
71   usage();
72   return 0;
73  } else {
74   fprintf(stderr, "Error: unknown argument: %s\n", k);
75   usage();
76   return 1;
77  }
78 }
79
80 if ( roar_simple_connect(&con, server, "roarcat2sock") == -1 ) {
81  ROAR_DBG("roar_simple_play(*): roar_simple_connect() faild!");
82  return 1;
83 }
84
85 if ( (fh = roar_simple_new_stream(&con, rate, channels, bits, codec, ROAR_DIR_PLAY)) == -1 ) {
86  roar_disconnect(&con);
87  return 1;
88 }
89
90 while((i = read(0, buf, BUFSIZE)))
91  write(fh, buf, i);
92
93 close(fh);
94
95 roar_disconnect(&con);
96
97 return 0;
98}
99
100//ll
Note: See TracBrowser for help on using the repository browser.