1 | //driver_ao.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
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, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "roard.h" |
---|
27 | #ifdef ROAR_HAVE_LIBAO |
---|
28 | |
---|
29 | int _driver_ao_usage_counter = 0; |
---|
30 | |
---|
31 | void driver_ao_init (void) { |
---|
32 | if ( _driver_ao_usage_counter++ == 0 ) |
---|
33 | ao_initialize(); |
---|
34 | } |
---|
35 | |
---|
36 | void driver_ao_uninit (void) { |
---|
37 | if ( _driver_ao_usage_counter-- == 1 ) |
---|
38 | ao_shutdown(); |
---|
39 | } |
---|
40 | |
---|
41 | int driver_ao_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
42 | //int driver_ao_open(DRIVER_USERDATA_T * inst, char * device, struct roar_audio_info * info) { |
---|
43 | ao_device * aodevice; |
---|
44 | ao_sample_format format; |
---|
45 | int driver; |
---|
46 | |
---|
47 | ROAR_WARN("The libao driver is obsolete, use another!"); |
---|
48 | |
---|
49 | if ( fh != -1 ) |
---|
50 | return -1; |
---|
51 | |
---|
52 | driver_ao_init(); |
---|
53 | |
---|
54 | if ( device == NULL ) { |
---|
55 | driver = ao_default_driver_id(); |
---|
56 | } else { |
---|
57 | if ( (driver = ao_driver_id(device)) == -1 ) { |
---|
58 | ROAR_ERR("Can not open audio device via libao's driver '%s'", device); |
---|
59 | driver_ao_uninit(); |
---|
60 | return -1; |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | memset(&format, 0, sizeof(format)); |
---|
65 | |
---|
66 | format.bits = info->bits; |
---|
67 | format.channels = info->channels; |
---|
68 | format.rate = info->rate; |
---|
69 | |
---|
70 | if ( info->bits == 8 ) { |
---|
71 | ROAR_WARN("This is the libao driver in 8 bit mode, It's not known to me if I need to provide data in signed or in unsigned mode. If your musik sounds strange try -oO codec=pcm_s_le or -oO codec=pcm_u_be"); |
---|
72 | /* NOTE: the following is only true for EsounD driver, not for OSS driver, don't know for the others |
---|
73 | switch (info->codec) { |
---|
74 | case ROAR_CODEC_PCM_U_LE: |
---|
75 | case ROAR_CODEC_PCM_U_BE: |
---|
76 | case ROAR_CODEC_PCM_U_PDP: |
---|
77 | format.byte_format = AO_FMT_NATIVE; |
---|
78 | break; |
---|
79 | default: |
---|
80 | ROAR_ERR("Can not open audio device via libao: codec not supported. You may want to try -oO codec=pcm_u_le or -oO codec=pcm,bits=16"); |
---|
81 | driver_ao_uninit(); |
---|
82 | return -1; |
---|
83 | break; |
---|
84 | } |
---|
85 | */ |
---|
86 | } |
---|
87 | |
---|
88 | switch (info->codec) { |
---|
89 | case ROAR_CODEC_PCM_S_LE: |
---|
90 | format.byte_format = AO_FMT_LITTLE; |
---|
91 | break; |
---|
92 | case ROAR_CODEC_PCM_S_BE: |
---|
93 | format.byte_format = AO_FMT_BIG; |
---|
94 | break; |
---|
95 | default: |
---|
96 | ROAR_ERR("Can not open audio device via libao: codec not supported. You may want to try -oO codec=pcm"); |
---|
97 | driver_ao_uninit(); |
---|
98 | return -1; |
---|
99 | break; |
---|
100 | } |
---|
101 | |
---|
102 | aodevice = ao_open_live(driver, &format, NULL /* no options */); |
---|
103 | |
---|
104 | if ( aodevice == NULL ) { |
---|
105 | ROAR_ERR("Can not open audio device via libao."); |
---|
106 | driver_ao_uninit(); |
---|
107 | return -1; |
---|
108 | } |
---|
109 | |
---|
110 | memset(inst, 0, sizeof(struct roar_vio_calls)); |
---|
111 | inst->inst = (void*) aodevice; |
---|
112 | inst->write = driver_ao_write; |
---|
113 | inst->close = driver_ao_close; |
---|
114 | |
---|
115 | return 0; |
---|
116 | } |
---|
117 | |
---|
118 | int driver_ao_close(struct roar_vio_calls * vio) { |
---|
119 | |
---|
120 | ao_close((ao_device*)vio->inst); |
---|
121 | |
---|
122 | driver_ao_uninit(); |
---|
123 | |
---|
124 | return 0; |
---|
125 | } |
---|
126 | |
---|
127 | ssize_t driver_ao_write(struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
128 | if ( ao_play((ao_device*)(vio->inst), buf, count) == 0 ) |
---|
129 | return -1; |
---|
130 | return count; |
---|
131 | } |
---|
132 | |
---|
133 | #endif |
---|
134 | //ll |
---|