diff options
author | neonloop | 2021-09-22 15:37:20 +0000 |
---|---|---|
committer | neonloop | 2021-09-22 15:37:20 +0000 |
commit | 7b8ab475d542ff4a94109b0fb1b2575e37feeffa (patch) | |
tree | 143bf238ce08127886886db4bef5de3a9b9f4ef5 | |
parent | 2b6772fca188aeb94f3eb9e2511f65c0fcbe4802 (diff) | |
download | picoarch-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.c | 1 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | menu.c | 5 | ||||
-rw-r--r-- | plat_sdl.c | 18 |
4 files changed, 18 insertions, 8 deletions
@@ -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"); @@ -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 @@ -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) { @@ -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_) |