[0] | 1 | //driver_esd.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[0] | 26 | #include "roard.h" |
---|
[424] | 27 | #ifdef ROAR_HAVE_ESD |
---|
[0] | 28 | |
---|
| 29 | /* |
---|
| 30 | We could use inst as our fh directly. But esd works with unsigned at 8 bits and |
---|
| 31 | signed at 16 bits per sample. (why???) so we need to convert because we get signed at both, |
---|
| 32 | 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? |
---|
| 33 | */ |
---|
| 34 | |
---|
[912] | 35 | int driver_esd_open_sysio(DRIVER_USERDATA_T * inst, char * device, struct roar_audio_info * info) { |
---|
[0] | 36 | esd_format_t format = ESD_STREAM | ESD_PLAY; |
---|
| 37 | char name[80] = "roard"; |
---|
| 38 | int * di = malloc(sizeof(int)*2); |
---|
| 39 | |
---|
| 40 | if ( di == NULL ) |
---|
| 41 | return -1; |
---|
| 42 | |
---|
| 43 | *inst = (DRIVER_USERDATA_T)di; |
---|
| 44 | |
---|
| 45 | format |= info->bits == 16 ? ESD_BITS16 : ESD_BITS8; |
---|
| 46 | format |= info->channels == 2 ? ESD_STEREO : ESD_MONO; |
---|
| 47 | |
---|
| 48 | di[1] = info->bits == 8; |
---|
| 49 | |
---|
| 50 | di[0] = esd_play_stream_fallback(format, info->rate, device, name); |
---|
| 51 | |
---|
[504] | 52 | shutdown(di[0], SHUT_RD); |
---|
| 53 | |
---|
[0] | 54 | if ( di[0] == -1 ) { |
---|
| 55 | free(di); |
---|
| 56 | *inst = NULL; |
---|
| 57 | return -1; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | return 0; |
---|
| 61 | } |
---|
| 62 | |
---|
[2367] | 63 | int driver_esd_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
[930] | 64 | |
---|
| 65 | if ( fh != -1 ) |
---|
| 66 | return -1; |
---|
| 67 | |
---|
[1120] | 68 | inst->read = driver_esd_read; |
---|
| 69 | inst->write = driver_esd_write; |
---|
| 70 | inst->nonblock = driver_esd_nonblock; |
---|
| 71 | inst->sync = driver_esd_sync; |
---|
| 72 | |
---|
[912] | 73 | return driver_esd_open_sysio(&(inst->inst), device, info); |
---|
| 74 | } |
---|
| 75 | |
---|
[0] | 76 | int driver_esd_close(DRIVER_USERDATA_T inst) { |
---|
[912] | 77 | int fh; |
---|
| 78 | |
---|
| 79 | inst = ((struct roar_vio_calls *)inst)->inst; |
---|
| 80 | |
---|
| 81 | fh = *(int*)inst; |
---|
[0] | 82 | |
---|
| 83 | free((void*)inst); |
---|
| 84 | |
---|
| 85 | return esd_close(fh); |
---|
| 86 | } |
---|
| 87 | |
---|
[1656] | 88 | ssize_t driver_esd_write(struct roar_vio_calls * inst, void * buf, size_t len) { |
---|
[912] | 89 | int * di = (int*)((struct roar_vio_calls *)inst)->inst; |
---|
[0] | 90 | |
---|
| 91 | if ( di[1] ) |
---|
| 92 | roar_conv_codec_s2u8(buf, buf, len); |
---|
| 93 | |
---|
| 94 | return write(di[0], buf, len); |
---|
| 95 | } |
---|
| 96 | |
---|
[1656] | 97 | ssize_t driver_esd_read(struct roar_vio_calls * inst, void * buf, size_t len) { |
---|
[912] | 98 | return read(*(int*)((struct roar_vio_calls *)inst)->inst, buf, len); |
---|
[0] | 99 | } |
---|
| 100 | |
---|
[1120] | 101 | int driver_esd_nonblock(struct roar_vio_calls * vio, int state) { |
---|
| 102 | return roar_socket_nonblock(*(int*)vio->inst, state); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | int driver_esd_sync (struct roar_vio_calls * vio) { |
---|
[1171] | 106 | return ROAR_FDATASYNC(*(int*)vio->inst); |
---|
[1120] | 107 | } |
---|
[424] | 108 | |
---|
| 109 | #endif |
---|
[0] | 110 | //ll |
---|