source: roaraudio/roard/driver_esd.c @ 424:bd758712627b

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

added #ifdef ROAR_HAVE_ESD to driver_esd.c

File size: 1.4 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 if ( di[0] == -1 ) {
30  free(di);
31  *inst = NULL;
32  return -1;
33 }
34
35 return 0;
36}
37
38int driver_esd_close(DRIVER_USERDATA_T   inst) {
39 int fh = *(int*)inst;
40
41 free((void*)inst);
42
43 return esd_close(fh);
44}
45
46int driver_esd_pause(DRIVER_USERDATA_T   inst, int newstate) {
47 return -1;
48}
49
50int driver_esd_write(DRIVER_USERDATA_T   inst, char * buf, int len) {
51 int * di = (int*)inst;
52
53 if ( di[1] )
54  roar_conv_codec_s2u8(buf, buf, len);
55
56 return write(di[0], buf, len);
57}
58
59int driver_esd_read(DRIVER_USERDATA_T   inst, char * buf, int len) {
60 return read(*(int*)inst, buf, len);
61}
62
63int driver_esd_flush(DRIVER_USERDATA_T   inst) {
64 return 0;
65}
66
67
68#endif
69//ll
Note: See TracBrowser for help on using the repository browser.