Created
October 28, 2008 12:36
-
-
Save iratqq/20362 to your computer and use it in GitHub Desktop.
ao_sndio.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* ao_sndio.c | |
* | |
* Original Copyright (C) Aaron Holtzman - May 1999 | |
* Modifications Copyright (C) IWATA Ray - Oct 2008 | |
* | |
* This file is part of libao, a cross-platform library. See | |
* README for a history of this source code. | |
* | |
* libao is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2, or (at your option) | |
* any later version. | |
* | |
* libao is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with GNU Make; see the file COPYING. If not, write to | |
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
* | |
*/ | |
#include <sndio.h> | |
#include "ao/ao.h" | |
#include "ao/plugin.h" | |
static ao_info ao_sndio_info = { | |
AO_TYPE_LIVE, | |
"SNDIO audio driver output ", | |
"sndio", | |
"IWATA Ray <iratqq@gmail.com>", | |
"Outputs audio to the Open Sound System driver.", | |
AO_FMT_NATIVE, | |
20, | |
NULL, | |
1 | |
}; | |
typedef struct ao_sndio_internal { | |
struct sio_hdl *hdl; | |
} ao_sndio_internal; | |
int | |
ao_plugin_test() | |
{ | |
struct sio_hdl *hdl; | |
if ((hdl = sio_open(NULL, SIO_PLAY, 0)) != NULL) | |
return 0; | |
return 1; | |
} | |
ao_info * | |
ao_plugin_driver_info(void) | |
{ | |
return &ao_sndio_info; | |
} | |
int | |
ao_plugin_device_init(ao_device *device) | |
{ | |
ao_sndio_internal *internal; | |
if ((internal = (ao_sndio_internal *)malloc(sizeof(ao_sndio_internal))) == NULL) | |
return 0; | |
internal->hdl = NULL; | |
device->internal = internal; | |
return 1; | |
} | |
int | |
ao_plugin_set_option(ao_device *device, const char *key, const char *value) | |
{ | |
return 1; | |
} | |
int | |
ao_plugin_open(ao_device *device, ao_sample_format *format) | |
{ | |
ao_sndio_internal *internal = (ao_sndio_internal *)device->internal; | |
struct sio_par par; | |
if ((internal->hdl = sio_open(NULL, SIO_PLAY, 0)) == NULL) | |
return 0; | |
if (sio_initpar(&par) == 0) | |
return 0; | |
par.pchan = format->channels; | |
par.bits = format->bits; | |
par.rate = format->rate; | |
switch (format->byte_format) { | |
case AO_FMT_LITTLE: | |
par.le = 1; | |
break; | |
case AO_FMT_BIG: | |
par.le = 0; | |
break; | |
case AO_FMT_NATIVE: | |
par.le = SIO_LE_NATIVE; | |
break; | |
default: | |
return 0; | |
} | |
/* par.bufsz = BUFSIZ; */ | |
if (sio_setpar(internal->hdl, &par) == 0) | |
return 0; | |
device->driver_byte_format = AO_FMT_NATIVE; | |
return sio_start(internal->hdl); | |
} | |
int | |
ao_plugin_play(ao_device *device, const char *output_samples, uint_32 num_bytes) | |
{ | |
size_t nr; | |
ao_sndio_internal *internal = (ao_sndio_internal *)device->internal; | |
if ((nr = sio_write(internal->hdl, (void *)output_samples, num_bytes)) != -1 && nr != 0) | |
return 1; | |
return 0; | |
} | |
int | |
ao_plugin_close(ao_device *device) | |
{ | |
ao_sndio_internal *internal = (ao_sndio_internal *)device->internal; | |
sio_close(internal->hdl); | |
return 1; | |
} | |
void | |
ao_plugin_device_clear(ao_device *device) | |
{ | |
ao_sndio_internal *internal = (ao_sndio_internal *)device->internal; | |
free(internal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment