source: roaraudio/roard/driver_ao.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

File size: 3.6 KB
Line 
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27#ifdef ROAR_HAVE_LIBAO
28
29int _driver_ao_usage_counter = 0;
30
31void driver_ao_init (void) {
32 if ( _driver_ao_usage_counter++ == 0 )
33  ao_initialize();
34}
35
36void driver_ao_uninit (void) {
37 if ( _driver_ao_usage_counter-- == 1 )
38  ao_shutdown();
39}
40
41int 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 format.bits        = info->bits;
65 format.channels    = info->channels;
66 format.rate        = info->rate;
67
68 if ( info->bits == 8 ) {
69  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_le");
70/* NOTE: the following is only true for EsounD driver, not for OSS driver, don't know for the others
71  switch (info->codec) {
72   case ROAR_CODEC_PCM_U_LE:
73   case ROAR_CODEC_PCM_U_BE:
74   case ROAR_CODEC_PCM_U_PDP:
75     format.byte_format = AO_FMT_NATIVE;
76    break;
77   default:
78     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");
79     driver_ao_uninit();
80     return -1;
81    break;
82  }
83*/
84 }
85
86 switch (info->codec) {
87  case ROAR_CODEC_PCM_S_LE:
88    format.byte_format = AO_FMT_LITTLE;
89   break;
90  case ROAR_CODEC_PCM_S_BE:
91    format.byte_format = AO_FMT_BIG;
92   break;
93  default:
94   ROAR_ERR("Can not open audio device via libao: codec not supported. You may want to try -oO codec=pcm");
95   driver_ao_uninit();
96   return -1;
97  break;
98 }
99
100 aodevice = ao_open_live(driver, &format, NULL /* no options */);
101
102 if ( aodevice == NULL ) {
103  ROAR_ERR("Can not open audio device via libao.");
104  driver_ao_uninit();
105  return -1;
106 }
107
108 memset(inst, 0, sizeof(struct roar_vio_calls));
109 inst->inst  = (void*) aodevice;
110 inst->write = driver_ao_write;
111
112 return 0;
113}
114
115int driver_ao_close(DRIVER_USERDATA_T   inst) {
116
117 ao_close((ao_device*)(((struct roar_vio_calls *)inst)->inst));
118
119 driver_ao_uninit();
120
121 return 0;
122}
123
124ssize_t driver_ao_write(struct roar_vio_calls * vio, void *buf, size_t count) {
125 if ( ao_play((ao_device*)(vio->inst), buf, count) == 0 )
126  return -1;
127 return count;
128}
129
130#endif
131//ll
Note: See TracBrowser for help on using the repository browser.