5
* Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
6
* based on ao_esd.c of libao by Stan Seibert - July 2000, July 2001
8
* This file is part of RoarAudio, a cross-platform sound server. See
9
* README for a history of this source code.
11
* This file is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2, or (at your option)
16
* RoarAudio is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with GNU Make; see the file COPYING. If not, write to
23
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
32
#include <roaraudio.h>
34
#include <ao/plugin.h>
36
static char *ao_roar_options[] = {"host","verbose","quiet","matrix","debug"};
39
typedef struct ao_info {
40
int type; // live output or file output?
41
char *name; // full name of driver
42
char *short_name; // short name of driver
43
char *author; // driver author
44
char *comment; // driver comment
45
int preferred_byte_format;
52
static ao_info ao_roar_info ={
56
"Philipp 'ph3-der-loewe' Schafft, Based on code by: Stan Seibert <volsung@asu.edu>",
57
"Outputs to the RoarAudio Sound Daemon.",
65
typedef struct ao_roar_internal {
66
struct roar_vio_calls svio;
71
int ao_plugin_test(void) {
72
struct roar_connection con;
74
if ( roar_simple_connect(&con, NULL, "libao client") == -1 )
77
if (roar_get_standby(&con)) {
78
roar_disconnect(&con);
82
roar_disconnect(&con);
87
ao_info * ao_plugin_driver_info(void) {
92
int ao_plugin_device_init(ao_device * device) {
93
ao_roar_internal * internal;
95
internal = (ao_roar_internal *) calloc(1,sizeof(ao_roar_internal));
100
internal->host = NULL;
102
device->internal = internal;
103
device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED;
108
int ao_plugin_set_option(ao_device * device, const char * key, const char * value) {
109
ao_roar_internal * internal = (ao_roar_internal *) device->internal;
111
if ( strcmp(key, "host") == 0 ) {
112
if(internal->host) free(internal->host);
113
internal->host = strdup(value);
119
int ao_plugin_open(ao_device * device, ao_sample_format * format) {
120
ao_roar_internal * internal = (ao_roar_internal *) device->internal;
123
if ( roar_vio_simple_stream(&(internal->svio), format->rate, format->channels, format->bits,
124
ROAR_CODEC_DEFAULT, internal->host, ROAR_DIR_PLAY, "libao client") == -1 )
127
device->driver_byte_format = AO_FMT_NATIVE;
129
if(!device->inter_matrix){ /* It would be set if an app or user force-sets the mapping; don't overwrite! */
130
switch (format->channels) {
131
case 1: map = "M"; break;
132
case 2: map = "L,R"; break;
133
case 3: map = "L,R,C"; break;
134
case 4: map = "L,R,BL,BR"; break;
135
case 5: map = "L,R,C,BL,BR"; break;
136
case 6: map = "L,R,C,LFE,BL,BR"; break;
138
/* >6 channels will warn about inability to map */
141
device->inter_matrix = strdup(map);
147
int ao_plugin_play(ao_device * device, const char * output_samples, uint_32 num_bytes) {
148
ao_roar_internal * internal = (ao_roar_internal *) device->internal;
150
if (roar_vio_write(&(internal->svio), (char*)output_samples, num_bytes) == -1) {
158
int ao_plugin_close(ao_device * device) {
159
ao_roar_internal * internal = (ao_roar_internal *) device->internal;
161
roar_vio_close(&(internal->svio));
167
void ao_plugin_device_clear(ao_device * device) {
168
ao_roar_internal * internal = (ao_roar_internal *) device->internal;
170
if( internal->host != NULL )
171
free(internal->host);