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