source: roaraudio/roard/driver_ao.c @ 5056:b31e60545552

Last change on this file since 5056:b31e60545552 was 5056:b31e60545552, checked in by phi, 11 years ago

support auto reconf bits=32->16 in case not supported (See: #48)

File size: 4.3 KB
Line 
1//driver_ao.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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
29static int _driver_ao_usage_counter = 0;
30
31void driver_ao_init (void) {
32 if ( _driver_ao_usage_counter++ == 0 )
33  ao_initialize();
34
35#ifdef ROAR_HAVE_AO_APPEND_GLOBAL_OPTION
36 ao_append_global_option("client_name", "roard");
37#endif
38}
39
40void driver_ao_uninit (void) {
41 if ( _driver_ao_usage_counter-- == 1 )
42  ao_shutdown();
43}
44
45int driver_ao_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
46//int driver_ao_open(DRIVER_USERDATA_T * inst, char * device, struct roar_audio_info * info) {
47 ao_device        * aodevice;
48 ao_sample_format     format;
49 int driver;
50 int autoconfig = 0;
51
52 ROAR_WARN("The libao driver is obsolete, use another!");
53
54 if ( fh != -1 )
55  return -1;
56
57 if ( sstream != NULL ) {
58  autoconfig = streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF);
59 }
60
61 driver_ao_init();
62
63 if ( device == NULL ) {
64  driver = ao_default_driver_id();
65 } else {
66  if ( (driver = ao_driver_id(device)) == -1 ) {
67   ROAR_ERR("Can not open audio device via libao's driver '%s'", device);
68   driver_ao_uninit();
69   return -1;
70  }
71 }
72
73 memset(&format, 0, sizeof(format));
74
75 format.bits        = info->bits;
76 format.channels    = info->channels;
77 format.rate        = info->rate;
78
79 if ( info->bits == 8 ) {
80  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");
81/* NOTE: the following is only true for EsounD driver, not for OSS driver, don't know for the others
82  switch (info->codec) {
83   case ROAR_CODEC_PCM_U_LE:
84   case ROAR_CODEC_PCM_U_BE:
85   case ROAR_CODEC_PCM_U_PDP:
86     format.byte_format = AO_FMT_NATIVE;
87    break;
88   default:
89     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");
90     driver_ao_uninit();
91     return -1;
92    break;
93  }
94*/
95 }
96
97 switch (info->codec) {
98  case ROAR_CODEC_PCM_S_LE:
99    format.byte_format = AO_FMT_LITTLE;
100   break;
101  case ROAR_CODEC_PCM_S_BE:
102    format.byte_format = AO_FMT_BIG;
103   break;
104  default:
105    if ( autoconfig ) {
106     format.byte_format = AO_FMT_NATIVE;
107     info->codec = ROAR_CODEC_DEFAULT;
108    } else {
109     ROAR_ERR("Can not open audio device via libao: codec not supported. You may want to try -oO codec=pcm");
110     driver_ao_uninit();
111     return -1;
112    }
113   break;
114 }
115
116 aodevice = ao_open_live(driver, &format, NULL /* no options */);
117
118 if ( aodevice == NULL && autoconfig ) {
119  format.byte_format = AO_FMT_NATIVE;
120  format.bits        = 16;
121  info->codec        = ROAR_CODEC_DEFAULT;
122  info->bits         = 16;
123  aodevice = ao_open_live(driver, &format, NULL /* no options */);
124 }
125
126 if ( aodevice == NULL ) {
127  ROAR_ERR("Can not open audio device via libao.");
128  driver_ao_uninit();
129  return -1;
130 }
131
132 memset(inst, 0, sizeof(struct roar_vio_calls));
133 inst->inst     = (void*) aodevice;
134 inst->write    = driver_ao_write;
135 inst->close    = driver_ao_close;
136 inst->nonblock = driver_dummy_nonblock;
137
138 return 0;
139}
140
141int driver_ao_close(struct roar_vio_calls * vio) {
142
143 ao_close((ao_device*)vio->inst);
144
145 driver_ao_uninit();
146
147 return 0;
148}
149
150ssize_t driver_ao_write(struct roar_vio_calls * vio, void *buf, size_t count) {
151 if ( ao_play((ao_device*)(vio->inst), buf, count) == 0 )
152  return -1;
153 return count;
154}
155
156#endif
157//ll
Note: See TracBrowser for help on using the repository browser.