source: roaraudio/roard/driver_ao.c @ 958:06746d10d7a9

Last change on this file since 958:06746d10d7a9 was 958:06746d10d7a9, checked in by phi, 15 years ago

ported libao driver to new vio interface :)

File size: 2.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 if ( fh != -1 )
47  return -1;
48
49 driver_ao_init();
50
51 if ( device == NULL ) {
52  driver = ao_default_driver_id();
53 } else {
54  if ( (driver = ao_driver_id(device)) == -1 ) {
55   ROAR_ERR("Can not open audio device via libao's driver '%s'", device);
56   driver_ao_uninit();
57   return -1;
58  }
59 }
60
61 format.bits        = info->bits;
62 format.channels    = info->channels;
63 format.rate        = info->rate;
64 format.byte_format = AO_FMT_NATIVE;
65
66 aodevice = ao_open_live(driver, &format, NULL /* no options */);
67
68 if ( aodevice == NULL ) {
69  ROAR_ERR("Can not open audio device via libao.");
70  driver_ao_uninit();
71  return -1;
72 }
73
74 memset(inst, 0, sizeof(struct roar_vio_calls));
75 inst->inst  = (void*) aodevice;
76 inst->write = driver_ao_write;
77
78 return 0;
79}
80
81int driver_ao_close(DRIVER_USERDATA_T   inst) {
82
83 ao_close((ao_device*)(((struct roar_vio_calls *)inst)->inst));
84
85 driver_ao_uninit();
86
87 return 0;
88}
89
90ssize_t driver_ao_write(struct roar_vio_calls * vio, void *buf, size_t count) {
91 if ( ao_play((ao_device*)(vio->inst), buf, count) == 0 )
92  return -1;
93 return count;
94}
95
96#endif
97//ll
Note: See TracBrowser for help on using the repository browser.