aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneonloop2021-09-22 15:37:20 +0000
committerneonloop2021-09-22 15:37:20 +0000
commit7b8ab475d542ff4a94109b0fb1b2575e37feeffa (patch)
tree143bf238ce08127886886db4bef5de3a9b9f4ef5
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
-rw-r--r--core.c1
-rw-r--r--main.c2
-rw-r--r--menu.c5
-rw-r--r--plat_sdl.c18
4 files changed, 18 insertions, 8 deletions
diff --git a/core.c b/core.c
index 6be799f..29544b6 100644
--- a/core.c
+++ b/core.c
@@ -623,6 +623,7 @@ int core_load_content(struct content *content) {
sample_rate = av_info.timing.sample_rate;
frame_rate = av_info.timing.fps;
aspect_ratio = av_info.geometry.aspect_ratio;
+ plat_reinit();
#ifdef MMENU
content_based_name(content, save_template_path, MAX_PATH, save_dir, NULL, ".st%i");
diff --git a/main.c b/main.c
index 7bdcd07..0b1ec36 100644
--- a/main.c
+++ b/main.c
@@ -276,6 +276,7 @@ void load_config(void)
config_read(config);
free(config);
}
+ plat_reinit();
}
void load_config_keys(void)
@@ -554,7 +555,6 @@ int main(int argc, char **argv) {
}
load_config_keys();
- plat_reinit();
#ifdef MMENU
diff --git a/menu.c b/menu.c
index 973a446..23a6a27 100644
--- a/menu.c
+++ b/menu.c
@@ -331,11 +331,6 @@ static int menu_loop_select_content(int id, int keys) {
}
load_config();
-
- if (plat_reinit()) {
- quit(-1);
- }
-
load_config_keys();
if (g_autostateld_opt) {
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_)