aboutsummaryrefslogtreecommitdiff
path: root/plat_sdl.c
diff options
context:
space:
mode:
authorneonloop2021-09-22 15:37:20 +0000
committerneonloop2021-09-22 15:37:20 +0000
commit7b8ab475d542ff4a94109b0fb1b2575e37feeffa (patch)
tree143bf238ce08127886886db4bef5de3a9b9f4ef5 /plat_sdl.c
parent2b6772fca188aeb94f3eb9e2511f65c0fcbe4802 (diff)
downloadpicoarch-7b8ab475d542ff4a94109b0fb1b2575e37feeffa.tar.gz
picoarch-7b8ab475d542ff4a94109b0fb1b2575e37feeffa.tar.bz2
picoarch-7b8ab475d542ff4a94109b0fb1b2575e37feeffa.zip
Skips audio writing when buffer size is 0
This keeps from hanging when audio is sent before content is loaded (pcsx_rearmed). picoarch cannot know correct frame rate / sample rate before content is loaded (incorrect to call retro_get_system_av_info then) so best to just skip it
Diffstat (limited to 'plat_sdl.c')
-rw-r--r--plat_sdl.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/plat_sdl.c b/plat_sdl.c
index c7c6050..0596ce7 100644
--- a/plat_sdl.c
+++ b/plat_sdl.c
@@ -16,7 +16,6 @@ struct audio_state {
unsigned buf_r;
size_t buf_len;
struct audio_frame *buf;
- int freq;
int in_sample_rate;
int out_sample_rate;
};
@@ -256,6 +255,9 @@ finish:
static void plat_sound_callback(void *unused, uint8_t *stream, int len)
{
int16_t *p = (int16_t *)stream;
+ if (audio.buf_len == 0)
+ return;
+
len /= (sizeof(int16_t) * 2);
while (audio.buf_r != audio.buf_w && len > 0) {
@@ -315,6 +317,9 @@ static int plat_sound_init(void)
float plat_sound_capacity(void)
{
int buffered = 0;
+ if (audio.buf_len == 0)
+ return 1.0;
+
if (audio.buf_w != audio.buf_r) {
buffered = audio.buf_w > audio.buf_r ?
audio.buf_w - audio.buf_r :
@@ -360,14 +365,22 @@ void plat_sound_write(const struct audio_frame *data, int frames)
void plat_sound_resize_buffer(void) {
size_t buf_size;
+ SDL_LockAudio();
+
audio.buf_len = frame_rate > 0
? current_audio_buffer_size * audio.in_sample_rate / frame_rate
- : 2;
+ : 0;
+
+ if (audio.buf_len == 0) {
+ SDL_UnlockAudio();
+ return;
+ }
buf_size = audio.buf_len * sizeof(struct audio_frame);
audio.buf = realloc(audio.buf, buf_size);
if (!audio.buf) {
+ SDL_UnlockAudio();
PA_ERROR("Error initializing sound buffer\n");
plat_sound_finish();
return;
@@ -377,6 +390,7 @@ void plat_sound_resize_buffer(void) {
audio.buf_w = 0;
audio.buf_r = 0;
audio.max_buf_w = audio.buf_len - 1;
+ SDL_UnlockAudio();
}
void plat_sdl_event_handler(void *event_)