1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <roaraudio.h>
#include <boolean.h>
#include "../audio_driver.h"
#include "../../verbosity.h"
typedef struct
{
roar_vs_t *vss;
bool nonblocking;
bool is_paused;
} roar_t;
static void *ra_init(const char *device, unsigned rate, unsigned latency,
unsigned block_frames, unsigned *new_rate)
{
int err;
roar_vs_t *vss = NULL;
roar_t *roar = (roar_t*)calloc(1, sizeof(roar_t));
if (!roar)
return NULL;
(void)latency;
if (!(vss = roar_vs_new_simple(device, "RetroArch", rate, 2, ROAR_CODEC_PCM_S, 16, ROAR_DIR_PLAY, &err)))
{
RARCH_ERR("RoarAudio: \"%s\"\n", roar_vs_strerr(err));
free(roar);
return NULL;
}
roar_vs_role(vss, ROAR_ROLE_GAME, NULL);
roar->vss = vss;
return roar;
}
static ssize_t ra_write(void *data, const void *buf, size_t size)
{
int err;
size_t written = 0;
roar_t *roar = (roar_t*)data;
if (size == 0)
return 0;
while (written < size)
{
ssize_t rc;
size_t write_amt = size - written;
if ((rc = roar_vs_write(roar->vss,
(const char*)buf + written, write_amt, &err)) < (ssize_t)write_amt)
{
if (roar->nonblocking)
return rc;
else if (rc < 0)
return -1;
}
written += rc;
}
return size;
}
static bool ra_stop(void *data)
{
roar_t *roar = (roar_t*)data;
if (roar)
roar->is_paused = true;
return true;
}
static bool ra_alive(void *data)
{
roar_t *roar = (roar_t*)data;
if (!roar)
return false;
return !roar->is_paused;
}
static void ra_set_nonblock_state(void *data, bool state)
{
roar_t *roar = (roar_t*)data;
if (roar_vs_blocking(roar->vss, (state) ? ROAR_VS_FALSE : ROAR_VS_TRUE, NULL) < 0)
{
RARCH_ERR("Can't set nonblocking. Will not be able to fast-forward.\n");
}
roar->nonblocking = state;
}
static bool ra_start(void *data, bool is_shutdown)
{
roar_t *roar = (roar_t*)data;
if (roar)
roar->is_paused = false;
return true;
}
static void ra_free(void *data)
{
roar_t *roar = (roar_t*)data;
roar_vs_close(roar->vss, ROAR_VS_TRUE, NULL);
free(data);
}
static bool ra_use_float(void *data)
{
return false;
}
static size_t ra_write_avail(void *data)
{
(void)data;
return 0;
}
audio_driver_t audio_roar = {
ra_init,
ra_write,
ra_stop,
ra_start,
ra_alive,
ra_set_nonblock_state,
ra_free,
ra_use_float,
"roar",
NULL,
NULL,
ra_write_avail,
NULL
};
|