RetroArch/audio/roar.c

117 lines
2.7 KiB
C
Raw Normal View History

2012-04-21 21:13:50 +00:00
/* RetroArch - A frontend for libretro.
2013-01-01 00:37:37 +00:00
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
2010-08-16 19:20:07 +00:00
*
2012-04-21 21:13:50 +00:00
* RetroArch is free software: you can redistribute it and/or modify it under the terms
2010-08-16 19:20:07 +00:00
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
2012-04-21 21:13:50 +00:00
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
2010-08-16 19:20:07 +00:00
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
2012-04-21 21:31:57 +00:00
* You should have received a copy of the GNU General Public License along with RetroArch.
2010-08-16 19:20:07 +00:00
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "driver.h"
#include <stdlib.h>
#include <roaraudio.h>
#include <errno.h>
#include <stdio.h>
2011-12-24 12:46:12 +00:00
#include "../boolean.h"
2011-03-11 18:23:32 +00:00
#include "general.h"
typedef struct
{
roar_vs_t *vss;
bool nonblocking;
} roar_t;
2010-08-16 19:20:07 +00:00
static void *ra_init(const char *device, unsigned rate, unsigned latency)
2010-08-16 19:20:07 +00:00
{
(void)latency;
2010-08-16 19:20:07 +00:00
int err;
2011-12-24 12:46:12 +00:00
roar_t *roar = (roar_t*)calloc(1, sizeof(roar_t));
if (roar == NULL)
return NULL;
2010-08-16 19:20:07 +00:00
roar_vs_t *vss;
2012-09-07 19:56:26 +00:00
if ((vss = roar_vs_new_simple(device, "RetroArch", rate, 2, ROAR_CODEC_PCM_S, 16, ROAR_DIR_PLAY, &err)) == NULL)
2010-08-16 19:20:07 +00:00
{
2012-04-21 21:25:32 +00:00
RARCH_ERR("RoarAudio: \"%s\"\n", roar_vs_strerr(err));
free(roar);
2010-08-16 19:20:07 +00:00
return NULL;
}
2011-03-11 18:23:32 +00:00
roar_vs_role(vss, ROAR_ROLE_GAME, NULL);
roar->vss = vss;
return roar;
2010-08-16 19:20:07 +00:00
}
static ssize_t ra_write(void *data, const void *buf, size_t size)
2010-08-16 19:20:07 +00:00
{
2011-12-24 12:46:12 +00:00
roar_t *roar = (roar_t*)data;
ssize_t rc;
2010-08-16 19:20:07 +00:00
2011-03-11 18:23:32 +00:00
if (size == 0)
2010-08-16 19:20:07 +00:00
return 0;
int err;
size_t written = 0;
while (written < size)
2010-08-16 19:20:07 +00:00
{
2011-03-11 18:23:32 +00:00
size_t write_amt = size - written;
2012-04-09 20:30:29 +00:00
if ((rc = roar_vs_write(roar->vss, (const char*)buf + written, write_amt, &err)) < (ssize_t)write_amt)
{
2011-03-11 18:23:32 +00:00
if (roar->nonblocking)
return rc;
else if (rc < 0)
return -1;
}
written += rc;
2010-08-16 19:20:07 +00:00
}
return size;
}
static bool ra_stop(void *data)
2010-08-16 19:20:07 +00:00
{
(void)data;
2010-08-16 19:20:07 +00:00
return true;
}
static void ra_set_nonblock_state(void *data, bool state)
2010-08-16 19:20:07 +00:00
{
2011-12-24 12:46:12 +00:00
roar_t *roar = (roar_t*)data;
if (roar_vs_blocking(roar->vss, (state) ? ROAR_VS_FALSE : ROAR_VS_TRUE, NULL) < 0)
2012-04-21 21:13:50 +00:00
fprintf(stderr, "RetroArch [ERROR]: Can't set nonblocking. Will not be able to fast-forward.\n");
roar->nonblocking = state;
2010-08-16 19:20:07 +00:00
}
static bool ra_start(void *data)
2010-08-16 19:20:07 +00:00
{
(void)data;
2010-08-16 19:20:07 +00:00
return true;
}
static void ra_free(void *data)
2010-08-16 19:20:07 +00:00
{
2011-12-24 12:46:12 +00:00
roar_t *roar = (roar_t*)data;
roar_vs_close(roar->vss, ROAR_VS_TRUE, NULL);
free(data);
2010-08-16 19:20:07 +00:00
}
const audio_driver_t audio_roar = {
2011-12-24 12:46:12 +00:00
ra_init,
ra_write,
ra_stop,
ra_start,
ra_set_nonblock_state,
ra_free,
NULL,
"roar"
2010-08-16 19:20:07 +00:00
};