source: roaraudio/roard/driver_ao.c @ 960:618277a7056e

Last change on this file since 960:618277a7056e was 960:618277a7056e, checked in by phi, 15 years ago

added some codec check. We _assume_ we need to send signed data to all sub drivers in case of bits > 8, in case bits == 8 we just don't know. added warnings

File size: 3.5 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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26#ifdef ROAR_HAVE_LIBAO
27
28int _driver_ao_usage_counter = 0;
29
30void driver_ao_init (void) {
31 if ( _driver_ao_usage_counter++ == 0 )
32  ao_initialize();
33}
34
35void driver_ao_uninit (void) {
36 if ( _driver_ao_usage_counter-- == 1 )
37  ao_shutdown();
38}
39
40int driver_ao_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh) {
41//int driver_ao_open(DRIVER_USERDATA_T * inst, char * device, struct roar_audio_info * info) {
42 ao_device        * aodevice;
43 ao_sample_format     format;
44 int driver;
45
46 ROAR_WARN("The libao driver is obsolete, use another!");
47
48 if ( fh != -1 )
49  return -1;
50
51 driver_ao_init();
52
53 if ( device == NULL ) {
54  driver = ao_default_driver_id();
55 } else {
56  if ( (driver = ao_driver_id(device)) == -1 ) {
57   ROAR_ERR("Can not open audio device via libao's driver '%s'", device);
58   driver_ao_uninit();
59   return -1;
60  }
61 }
62
63 format.bits        = info->bits;
64 format.channels    = info->channels;
65 format.rate        = info->rate;
66
67 if ( info->bits == 8 ) {
68  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");
69/* NOTE: the following is only true for EsounD driver, not for OSS driver, don't know for the others
70  switch (info->codec) {
71   case ROAR_CODEC_PCM_U_LE:
72   case ROAR_CODEC_PCM_U_BE:
73   case ROAR_CODEC_PCM_U_PDP:
74     format.byte_format = AO_FMT_NATIVE;
75    break;
76   default:
77     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");
78     driver_ao_uninit();
79     return -1;
80    break;
81  }
82*/
83 }
84
85 switch (info->codec) {
86  case ROAR_CODEC_PCM_S_LE:
87    format.byte_format = AO_FMT_LITTLE;
88   break;
89  case ROAR_CODEC_PCM_S_BE:
90    format.byte_format = AO_FMT_BIG;
91   break;
92  default:
93   ROAR_ERR("Can not open audio device via libao: codec not supported. You may want to try -oO codec=pcm");
94   driver_ao_uninit();
95   return -1;
96  break;
97 }
98
99 aodevice = ao_open_live(driver, &format, NULL /* no options */);
100
101 if ( aodevice == NULL ) {
102  ROAR_ERR("Can not open audio device via libao.");
103  driver_ao_uninit();
104  return -1;
105 }
106
107 memset(inst, 0, sizeof(struct roar_vio_calls));
108 inst->inst  = (void*) aodevice;
109 inst->write = driver_ao_write;
110
111 return 0;
112}
113
114int driver_ao_close(DRIVER_USERDATA_T   inst) {
115
116 ao_close((ao_device*)(((struct roar_vio_calls *)inst)->inst));
117
118 driver_ao_uninit();
119
120 return 0;
121}
122
123ssize_t driver_ao_write(struct roar_vio_calls * vio, void *buf, size_t count) {
124 if ( ao_play((ao_device*)(vio->inst), buf, count) == 0 )
125  return -1;
126 return count;
127}
128
129#endif
130//ll
Note: See TracBrowser for help on using the repository browser.