[668] | 1 | //driver_ao.c: |
---|
| 2 | |
---|
| 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 |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
[0] | 24 | |
---|
| 25 | #include "roard.h" |
---|
[425] | 26 | #ifdef ROAR_HAVE_LIBAO |
---|
[0] | 27 | |
---|
| 28 | int driver_ao_open(DRIVER_USERDATA_T * inst, char * device, struct roar_audio_info * info) { |
---|
| 29 | ao_device * aodevice; |
---|
| 30 | ao_sample_format format; |
---|
| 31 | int driver; |
---|
| 32 | |
---|
| 33 | ao_initialize(); |
---|
| 34 | |
---|
| 35 | if ( device == NULL ) { |
---|
| 36 | driver = ao_default_driver_id(); |
---|
| 37 | } else { |
---|
| 38 | if ( (driver = ao_driver_id(device)) == -1 ) { |
---|
| 39 | ROAR_ERR("Can not open audio device via libao's driver '%s'", device); |
---|
| 40 | return -1; |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | format.bits = info->bits; |
---|
| 45 | format.channels = info->channels; |
---|
| 46 | format.rate = info->rate; |
---|
| 47 | format.byte_format = AO_FMT_NATIVE; |
---|
| 48 | |
---|
| 49 | aodevice = ao_open_live(driver, &format, NULL /* no options */); |
---|
| 50 | |
---|
| 51 | if ( aodevice == NULL ) { |
---|
| 52 | ROAR_ERR("Can not open audio device via libao."); |
---|
| 53 | return -1; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | *((ao_device**)inst) = aodevice; |
---|
| 57 | |
---|
| 58 | return 0; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | int driver_ao_close(DRIVER_USERDATA_T inst) { |
---|
| 62 | |
---|
| 63 | ao_close((ao_device*)inst); |
---|
| 64 | |
---|
| 65 | ao_shutdown(); |
---|
| 66 | |
---|
| 67 | return -1; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | int driver_ao_pause(DRIVER_USERDATA_T inst, int newstate) { |
---|
| 71 | return -1; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | int driver_ao_write(DRIVER_USERDATA_T inst, char * buf, int len) { |
---|
| 75 | return ao_play((ao_device*)inst, buf, len); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | int driver_ao_read(DRIVER_USERDATA_T inst, char * buf, int len) { |
---|
| 79 | return -1; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | int driver_ao_flush(DRIVER_USERDATA_T inst) { |
---|
| 83 | return 0; |
---|
| 84 | } |
---|
| 85 | |
---|
[425] | 86 | #endif |
---|
[0] | 87 | //ll |
---|