source: roaraudio/roard/driver_esd.c @ 504:aa76f8ae6e2e

Last change on this file since 504:aa76f8ae6e2e was 504:aa76f8ae6e2e, checked in by phi, 16 years ago

shutdown() ESD socket

File size: 1.5 KB
Line 
1//driver_esd.c:
2
3#include "roard.h"
4#ifdef ROAR_HAVE_ESD
5
6/*
7 We could use inst as our fh directly. But esd works with unsigned at 8 bits and
8 signed at 16 bits per sample. (why???) so we need to convert because we get signed at both,
9 8 and 16 bits per sample. so we use inst as an array of two ints: 0: fh, 1: are we in 8 bit mode?
10*/
11
12int driver_esd_open(DRIVER_USERDATA_T * inst, char * device, struct roar_audio_info * info) {
13 esd_format_t format = ESD_STREAM | ESD_PLAY;
14 char name[80] = "roard";
15 int * di = malloc(sizeof(int)*2);
16
17 if ( di == NULL )
18  return -1;
19
20 *inst = (DRIVER_USERDATA_T)di;
21
22 format |= info->bits     == 16 ? ESD_BITS16 : ESD_BITS8;
23 format |= info->channels ==  2 ? ESD_STEREO : ESD_MONO;
24
25 di[1] = info->bits == 8;
26
27 di[0] = esd_play_stream_fallback(format, info->rate, device, name);
28
29 shutdown(di[0], SHUT_RD);
30
31 if ( di[0] == -1 ) {
32  free(di);
33  *inst = NULL;
34  return -1;
35 }
36
37 return 0;
38}
39
40int driver_esd_close(DRIVER_USERDATA_T   inst) {
41 int fh = *(int*)inst;
42
43 free((void*)inst);
44
45 return esd_close(fh);
46}
47
48int driver_esd_pause(DRIVER_USERDATA_T   inst, int newstate) {
49 return -1;
50}
51
52int driver_esd_write(DRIVER_USERDATA_T   inst, char * buf, int len) {
53 int * di = (int*)inst;
54
55 if ( di[1] )
56  roar_conv_codec_s2u8(buf, buf, len);
57
58 return write(di[0], buf, len);
59}
60
61int driver_esd_read(DRIVER_USERDATA_T   inst, char * buf, int len) {
62 return read(*(int*)inst, buf, len);
63}
64
65int driver_esd_flush(DRIVER_USERDATA_T   inst) {
66 return 0;
67}
68
69
70#endif
71//ll
Note: See TracBrowser for help on using the repository browser.