Debian Codegraph @

testsuite/play_client_main.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2000 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author: Alan W Black ([email protected]) */
34 /* Date: October 2000 */
35 /*************************************************************************/
36 /* */
37 /* Read and play a waveform by sending it to a server */
38 /* */
39 /*************************************************************************/
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include "cst_wave.h"
43 #include "cst_audio.h"
44
45 int play_client_main_usage()
46 {
47 printf("simple audio server: client program\n");
48 printf("usage: play_client [-s SERVERNAME] [-p PORTNUMBER] [-e ENCODING ] WAVEFORM0 ...\n");
49 printf("Send waveforms to a named audio sever\n");
50 printf("Default server is \"localhost\" default port is %d\n",
51 CST_AUDIO_DEFAULT_PORT);
52 printf("Default encoding is short, but you can choose ulaw too\n");
53 printf("If encoding is ulaw, transfer is as 8 bit mulaw (i.e. quicker)\n");
54
55 return 0;
56 }
57
58 int main(int argc, char **argv)
59 {
60 cst_wave *w;
61 int port;
62 char *server;
63 char *encoding;
64 int i,iw;
65
66 port = CST_AUDIO_DEFAULT_PORT;
67 server = CST_AUDIO_DEFAULT_SERVER;
68 encoding = CST_AUDIO_DEFAULT_ENCODING;
69
70 if (argc == 1)
71 {
72 play_client_main_usage();
73 return 1;
74 }
75
76 if ((cst_streq("-h",argv[1])) ||
77 (cst_streq("-help",argv[1])) ||
78 (cst_streq("--help",argv[1])))
79 {
80 play_client_main_usage();
81 return 1;
82 }
83 iw = 1;
84
85 if (cst_streq("-s",argv[iw]))
86 {
87 if (argc < iw+1)
88 {
89 fprintf(stderr,"ERROR: no servername given\n");
90 play_client_main_usage();
91 return 1;
92 }
93 server = argv[iw+1];
94 iw+=2;
95 }
96
97 if (cst_streq("-p",argv[iw]))
98 {
99 if (argc < iw+1)
100 {
101 fprintf(stderr,"ERROR: no port given\n");
102 play_client_main_usage();
103 return 1;
104 }
105 port = atoi(argv[iw+1]);
106 iw+=2;
107 }
108
109 if (cst_streq("-e",argv[iw]))
110 {
111 if (argc < iw+1)
112 {
113 fprintf(stderr,"ERROR: no encoding given\n");
114 play_client_main_usage();
115 return 1;
116 }
117 encoding = argv[iw+1];
118 iw+=2;
119 }
120
121 for (i=iw; i<argc; i++)
122 {
123 w = new_wave();
124 if (cst_wave_load_riff(w,argv[i]) != CST_OK_FORMAT)
125 {
126 fprintf(stderr,
127 "play_wave: can't read file or wrong format \"%s\"\n",
128 argv[i]);
129 continue;
130 }
131 play_wave_client(w,server,port,encoding);
132 delete_wave(w);
133 }
134
135 return 0;
136 }