1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include "esd.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <string.h>
int main(int argc, char **argv)
{
char buf[ESD_BUF_SIZE];
int sock = -1, rate = ESD_DEFAULT_RATE;
int length = 0, arg = 0;
int bits = ESD_BITS16, channels = ESD_STEREO;
int mode = ESD_STREAM, func = ESD_PLAY ;
esd_format_t format = 0;
FILE *source = NULL;
char *host = NULL;
char *name = NULL;
for ( arg = 1 ; arg < argc ; arg++)
{
if (!strcmp("-h",argv[arg]))
{
printf("usage:\n\t%s [-s server] [-n name] [-b] [-m] [-r freq] < file\n",
argv[0]);
exit(0);
}
else if ( !strcmp( "-n", argv[ arg ] ) )
name = argv[ ++arg ];
else if ( !strcmp( "-s", argv[ arg ] ) )
host = argv[ ++arg ];
else if ( !strcmp( "-b", argv[ arg ] ) )
bits = ESD_BITS8;
else if ( !strcmp( "-m", argv[ arg ] ) )
channels = ESD_MONO;
else if ( !strcmp( "-r", argv[ arg ] ) )
{
arg++;
rate = atoi( argv[ arg ] );
} else if (source) {
printf("%s: ignoring extra file '%s'\n", argv[0], argv[arg]);
} else {
name = argv[ arg ];
if ( (source = fopen( name, "r" )) == NULL ) {
printf( "%s: couldn't open sound file: %s\n", argv[0], name );
return 1;
}
}
}
/* use stdin if no file specified */
if (!source) {
source = stdin;
}
#ifdef __EMX__
/* Switch input stream to binary mode under EMX */
_fsetmode (source, "b");
#endif
format = bits | channels | mode | func;
fprintf( stderr, "opening socket, format = 0x%08x at %d Hz\n",
format, rate );
/* sock = esd_play_stream( format, rate ); */
sock = esd_play_stream_fallback( format, rate, host, name );
if ( sock <= 0 )
return 1;
while ( ( length = fread( buf, 1, ESD_BUF_SIZE, source ) ) > 0 )
{
/* fprintf( stderr, "read %d\n", length ); */
if ( write( sock, buf, length ) <= 0 )
return 1;
}
close( sock );
return 0;
}
|