2018-12-26 22:40:57 +00: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 <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <audsrv.h>
|
|
|
|
|
2019-06-17 10:49:21 +00:00
|
|
|
#include "../../retroarch.h"
|
2018-12-26 22:40:57 +00:00
|
|
|
|
2019-03-06 19:11:15 +00:00
|
|
|
#define AUDIO_BUFFER 128 * 1024
|
2019-02-21 23:01:36 +00:00
|
|
|
#define AUDIO_CHANNELS 2
|
|
|
|
#define AUDIO_BITS 16
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
typedef struct ps2_audio
|
|
|
|
{
|
2019-01-03 11:41:29 +00:00
|
|
|
bool nonblocking;
|
2019-02-20 22:45:30 +00:00
|
|
|
bool running;
|
2018-12-26 22:40:57 +00:00
|
|
|
|
|
|
|
} ps2_audio_t;
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static void audioConfigure(ps2_audio_t *ps2, unsigned rate)
|
|
|
|
{
|
2018-12-26 22:40:57 +00:00
|
|
|
int err;
|
|
|
|
struct audsrv_fmt_t format;
|
|
|
|
|
2019-01-06 23:25:45 +00:00
|
|
|
format.bits = AUDIO_BITS;
|
|
|
|
format.freq = rate;
|
2019-01-03 12:26:45 +00:00
|
|
|
format.channels = AUDIO_CHANNELS;
|
|
|
|
|
2019-01-06 23:25:45 +00:00
|
|
|
err = audsrv_set_format(&format);
|
2019-01-03 12:26:45 +00:00
|
|
|
|
2019-01-06 23:25:45 +00:00
|
|
|
if (err){
|
2018-12-26 22:40:57 +00:00
|
|
|
printf("set format returned %d\n", err);
|
2019-01-03 12:26:45 +00:00
|
|
|
printf("audsrv returned error string: %s\n", audsrv_get_error_string());
|
2018-12-26 22:40:57 +00:00
|
|
|
}
|
2019-01-03 12:26:45 +00:00
|
|
|
|
|
|
|
audsrv_set_volume(MAX_VOLUME);
|
2018-12-26 22:40:57 +00: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 12:26:45 +00:00
|
|
|
if (!ps2)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
audioConfigure(ps2, rate);
|
2018-12-26 22:40:57 +00:00
|
|
|
|
|
|
|
return ps2;
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static void ps2_audio_free(void *data)
|
|
|
|
{
|
2018-12-26 22:40:57 +00:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
|
|
|
if(!ps2)
|
|
|
|
return;
|
|
|
|
|
2019-02-21 23:01:36 +00:00
|
|
|
ps2->running = false;
|
2019-02-20 22:45:30 +00:00
|
|
|
audsrv_stop_audio();
|
2018-12-26 22:40:57 +00:00
|
|
|
free(ps2);
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static ssize_t ps2_audio_write(void *data, const void *buf, size_t size)
|
|
|
|
{
|
2019-03-06 19:11:15 +00:00
|
|
|
int bytes_sent;
|
2018-12-26 22:40:57 +00:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-01-03 12:26:45 +00:00
|
|
|
|
2018-12-26 22:40:57 +00:00
|
|
|
if (!ps2->running)
|
|
|
|
return -1;
|
|
|
|
|
2019-03-06 19:11:15 +00:00
|
|
|
bytes_sent = audsrv_play_audio(buf, size);
|
2018-12-26 22:40:57 +00:00
|
|
|
|
2019-03-06 19:11:15 +00:00
|
|
|
return bytes_sent;
|
2018-12-26 22:40:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static bool ps2_audio_alive(void *data)
|
|
|
|
{
|
2019-01-31 14:24:21 +00:00
|
|
|
bool alive = false;
|
2018-12-26 22:40:57 +00:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-01-31 14:24:21 +00:00
|
|
|
|
|
|
|
if (ps2)
|
2018-12-26 22:40:57 +00:00
|
|
|
alive = ps2->running;
|
2019-01-03 12:26:45 +00:00
|
|
|
|
2018-12-26 22:40:57 +00:00
|
|
|
return alive;
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static bool ps2_audio_stop(void *data)
|
|
|
|
{
|
2019-01-31 14:24:21 +00:00
|
|
|
bool stop = true;
|
2018-12-26 22:40:57 +00:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
|
|
|
|
2019-01-31 14:24:21 +00:00
|
|
|
if (ps2)
|
|
|
|
{
|
2018-12-26 22:40:57 +00:00
|
|
|
audsrv_stop_audio();
|
2019-02-21 23:01:36 +00:00
|
|
|
ps2->running = false;
|
2018-12-26 22:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return stop;
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static bool ps2_audio_start(void *data, bool is_shutdown)
|
|
|
|
{
|
2018-12-26 22:40:57 +00:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-01-31 14:24:21 +00:00
|
|
|
bool start = true;
|
2018-12-26 22:40:57 +00:00
|
|
|
|
2019-01-31 14:24:21 +00:00
|
|
|
if (ps2)
|
|
|
|
{
|
2019-02-21 23:01:36 +00:00
|
|
|
ps2->running = true;
|
2018-12-26 22:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static void ps2_audio_set_nonblock_state(void *data, bool toggle)
|
|
|
|
{
|
2018-12-26 22:40:57 +00:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
2019-01-06 23:25:45 +00:00
|
|
|
|
2019-01-31 14:24:21 +00:00
|
|
|
if (ps2)
|
2018-12-26 22:40:57 +00:00
|
|
|
ps2->nonblocking = toggle;
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static bool ps2_audio_use_float(void *data)
|
|
|
|
{
|
2018-12-26 22:40:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static size_t ps2_audio_write_avail(void *data)
|
|
|
|
{
|
2019-01-03 10:50:24 +00:00
|
|
|
ps2_audio_t* ps2 = (ps2_audio_t*)data;
|
|
|
|
|
2019-01-31 14:24:21 +00:00
|
|
|
if (ps2 && ps2->running)
|
|
|
|
{
|
2019-02-21 23:01:36 +00:00
|
|
|
return AUDIO_BUFFER;
|
2019-01-03 11:41:29 +00:00
|
|
|
}
|
2019-01-03 12:26:45 +00:00
|
|
|
|
|
|
|
return 0;
|
2019-01-03 10:50:24 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 12:26:45 +00:00
|
|
|
static size_t ps2_audio_buffer_size(void *data)
|
|
|
|
{
|
|
|
|
return AUDIO_BUFFER;
|
2019-01-03 10:50:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 22:40:57 +00: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 11:41:29 +00:00
|
|
|
ps2_audio_write_avail,
|
|
|
|
ps2_audio_buffer_size
|
2018-12-26 22:40:57 +00:00
|
|
|
};
|