source: roaraudio/roard/driver_ao.c @ 5011:512edfc544df

Last change on this file since 5011:512edfc544df was 4967:572924bdd4c6, checked in by phi, 13 years ago

make some vars file local as they do not need to be global

File size: 3.6 KB
RevLine 
[668]1//driver_ao.c:
2
3/*
[4708]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
[668]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
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[668]23 *
24 */
[0]25
26#include "roard.h"
[425]27#ifdef ROAR_HAVE_LIBAO
[0]28
[4967]29static int _driver_ao_usage_counter = 0;
[958]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
[2367]41int driver_ao_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
[958]42//int driver_ao_open(DRIVER_USERDATA_T * inst, char * device, struct roar_audio_info * info) {
[0]43 ao_device        * aodevice;
44 ao_sample_format     format;
45 int driver;
46
[960]47 ROAR_WARN("The libao driver is obsolete, use another!");
48
[958]49 if ( fh != -1 )
50  return -1;
51
52 driver_ao_init();
[0]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);
[958]59   driver_ao_uninit();
[0]60   return -1;
61  }
62 }
63
[4399]64 memset(&format, 0, sizeof(format));
65
[0]66 format.bits        = info->bits;
67 format.channels    = info->channels;
68 format.rate        = info->rate;
[960]69
70 if ( info->bits == 8 ) {
[3618]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");
[960]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 }
[0]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.");
[958]106  driver_ao_uninit();
[0]107  return -1;
108 }
109
[958]110 memset(inst, 0, sizeof(struct roar_vio_calls));
111 inst->inst  = (void*) aodevice;
112 inst->write = driver_ao_write;
[3588]113 inst->close = driver_ao_close;
[0]114
115 return 0;
116}
117
[3588]118int driver_ao_close(struct roar_vio_calls * vio) {
[0]119
[3588]120 ao_close((ao_device*)vio->inst);
[0]121
[958]122 driver_ao_uninit();
[0]123
[958]124 return 0;
[0]125}
126
[958]127ssize_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;
[0]131}
132
[425]133#endif
[0]134//ll
Note: See TracBrowser for help on using the repository browser.