source: trunk/third/esound/esdcat.c @ 20226

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