2018-12-26 23:40:57 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2014-2017 - Francisco Javier Trujillo Mata
|
|
|
|
*
|
|
|
|
* 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 <malloc.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <audsrv.h>
|
|
|
|
|
2021-10-11 18:01:37 +02:00
|
|
|
#include "../audio_driver.h"
|
2018-12-26 23:40:57 +01:00
|
|
|
|
2019-03-06 20:11:15 +01:00
|
|
|
#define AUDIO_BUFFER 128 * 1024
|
2019-02-22 00:01:36 +01:00
|
|
|
#define AUDIO_CHANNELS 2
|
|
|
|
#define AUDIO_BITS 16
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
typedef struct ps2_audio
|
|
|
|
{
|
2020-01-04 10:32:03 +01:00
|
|
|
/* TODO/FIXME - nonblock is not implemented */
|
|
|
|
bool nonblock;
|
2019-02-20 23:45:30 +01:00
|
|
|
bool running;
|
2018-12-26 23:40:57 +01:00
|
|
|
} ps2_audio_t;
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static void audioConfigure(ps2_audio_t *ps2, unsigned rate)
|
|
|
|
{
|
2018-12-26 23:40:57 +01:00
|
|
|
struct audsrv_fmt_t format;
|
|
|
|
|
2020-01-04 10:32:03 +01:00
|
|
|
format.bits = AUDIO_BITS;
|
|
|
|
format.freq = rate;
|
2019-01-03 13:26:45 +01:00
|
|
|
format.channels = AUDIO_CHANNELS;
|
|
|
|
|
2021-01-30 15:46:02 +01:00
|
|
|
audsrv_set_format(&format);
|
2019-01-03 13:26:45 +01:00
|
|
|
audsrv_set_volume(MAX_VOLUME);
|
2018-12-26 23:40:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *ps2_audio_init(const char *device,
|
|
|
|
unsigned rate, unsigned latency,
|
|
|
|
unsigned block_frames,
|
|
|
|
unsigned *new_rate)
|
|
|
|
{
|
|
|
|
ps2_audio_t *ps2 = (ps2_audio_t*)calloc(1, sizeof(ps2_audio_t));
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
if (!ps2)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
audioConfigure(ps2, rate);
|
2018-12-26 23:40:57 +01:00
|
|
|
|
|
|
|
return ps2;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static void ps2_audio_free(void *data)
|
|
|
|
{
|
2018-12-26 23:40:57 +01:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-07-31 14:41:50 +02:00
|
|
|
if (!ps2)
|
2018-12-26 23:40:57 +01:00
|
|
|
return;
|
|
|
|
|
2019-02-22 00:01:36 +01:00
|
|
|
ps2->running = false;
|
2019-02-20 23:45:30 +01:00
|
|
|
audsrv_stop_audio();
|
2018-12-26 23:40:57 +01:00
|
|
|
free(ps2);
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static ssize_t ps2_audio_write(void *data, const void *buf, size_t size)
|
|
|
|
{
|
2018-12-26 23:40:57 +01:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-01-03 13:26:45 +01:00
|
|
|
|
2018-12-26 23:40:57 +01:00
|
|
|
if (!ps2->running)
|
|
|
|
return -1;
|
|
|
|
|
2020-01-04 10:32:03 +01:00
|
|
|
return audsrv_play_audio(buf, size);
|
2018-12-26 23:40:57 +01:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static bool ps2_audio_alive(void *data)
|
|
|
|
{
|
2019-01-31 15:24:21 +01:00
|
|
|
bool alive = false;
|
2018-12-26 23:40:57 +01:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-01-31 15:24:21 +01:00
|
|
|
|
|
|
|
if (ps2)
|
2018-12-26 23:40:57 +01:00
|
|
|
alive = ps2->running;
|
2019-01-03 13:26:45 +01:00
|
|
|
|
2018-12-26 23:40:57 +01:00
|
|
|
return alive;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static bool ps2_audio_stop(void *data)
|
|
|
|
{
|
2019-01-31 15:24:21 +01:00
|
|
|
bool stop = true;
|
2018-12-26 23:40:57 +01:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
|
|
|
|
2019-01-31 15:24:21 +01:00
|
|
|
if (ps2)
|
|
|
|
{
|
2018-12-26 23:40:57 +01:00
|
|
|
audsrv_stop_audio();
|
2019-02-22 00:01:36 +01:00
|
|
|
ps2->running = false;
|
2018-12-26 23:40:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return stop;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static bool ps2_audio_start(void *data, bool is_shutdown)
|
|
|
|
{
|
2018-12-26 23:40:57 +01:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-01-31 15:24:21 +01:00
|
|
|
bool start = true;
|
2018-12-26 23:40:57 +01:00
|
|
|
|
2019-01-31 15:24:21 +01:00
|
|
|
if (ps2)
|
2019-02-22 00:01:36 +01:00
|
|
|
ps2->running = true;
|
2018-12-26 23:40:57 +01:00
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static void ps2_audio_set_nonblock_state(void *data, bool toggle)
|
|
|
|
{
|
2018-12-26 23:40:57 +01:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-01-07 00:25:45 +01:00
|
|
|
|
2019-01-31 15:24:21 +01:00
|
|
|
if (ps2)
|
2020-01-04 10:32:03 +01:00
|
|
|
ps2->nonblock = toggle;
|
2018-12-26 23:40:57 +01:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static bool ps2_audio_use_float(void *data)
|
|
|
|
{
|
2018-12-26 23:40:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static size_t ps2_audio_write_avail(void *data)
|
|
|
|
{
|
2019-01-03 11:50:24 +01:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
|
|
|
|
2019-01-31 15:24:21 +01:00
|
|
|
if (ps2 && ps2->running)
|
2019-02-22 00:01:36 +01:00
|
|
|
return AUDIO_BUFFER;
|
2019-01-03 13:26:45 +01:00
|
|
|
|
|
|
|
return 0;
|
2019-01-03 11:50:24 +01:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:45 +01:00
|
|
|
static size_t ps2_audio_buffer_size(void *data)
|
|
|
|
{
|
|
|
|
return AUDIO_BUFFER;
|
2019-01-03 11:50:24 +01:00
|
|
|
}
|
|
|
|
|
2018-12-26 23:40:57 +01:00
|
|
|
audio_driver_t audio_ps2 = {
|
|
|
|
ps2_audio_init,
|
|
|
|
ps2_audio_write,
|
|
|
|
ps2_audio_stop,
|
|
|
|
ps2_audio_start,
|
|
|
|
ps2_audio_alive,
|
|
|
|
ps2_audio_set_nonblock_state,
|
|
|
|
ps2_audio_free,
|
|
|
|
ps2_audio_use_float,
|
|
|
|
"ps2",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2019-01-03 12:41:29 +01:00
|
|
|
ps2_audio_write_avail,
|
|
|
|
ps2_audio_buffer_size
|
2018-12-26 23:40:57 +01:00
|
|
|
};
|