From fc57b41ab6b24730627fc9cf8566c19cb91dc36f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 18 Jan 2019 00:23:22 +0100 Subject: [PATCH] (Audio mixer) You can now specifically set a slot to load a sound in - set type to AUDIO_MIXER_SLOT_SELECTION_MANUAL and set idx to the slot you want to load in (begins at 0) --- audio/audio_driver.c | 14 +++++++-- audio/audio_driver.h | 8 +++++ menu/cbs/menu_cbs_ok.c | 17 ++++++++--- tasks/task_audio_mixer.c | 66 ++++++++++++++++++++++++++++++---------- tasks/tasks_internal.h | 10 ++++-- 5 files changed, 91 insertions(+), 24 deletions(-) diff --git a/audio/audio_driver.c b/audio/audio_driver.c index a0358b0cf8..9290dc41b1 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -1172,8 +1172,18 @@ bool audio_driver_mixer_add_stream(audio_mixer_stream_params_t *params) if (params->stream_type == AUDIO_STREAM_TYPE_NONE) return false; - if (!audio_driver_mixer_get_free_stream_slot(&free_slot, params->stream_type)) - return false; + switch (params->slot_selection_type) + { + case AUDIO_MIXER_SLOT_SELECTION_MANUAL: + free_slot = params->slot_selection_idx; + break; + case AUDIO_MIXER_SLOT_SELECTION_AUTOMATIC: + default: + if (!audio_driver_mixer_get_free_stream_slot( + &free_slot, params->stream_type)) + return false; + break; + } if (params->state == AUDIO_STREAM_STATE_NONE) return false; diff --git a/audio/audio_driver.h b/audio/audio_driver.h index a8f13d9213..2e1f59e344 100644 --- a/audio/audio_driver.h +++ b/audio/audio_driver.h @@ -50,6 +50,12 @@ enum audio_action AUDIO_ACTION_MIXER }; +enum audio_mixer_slot_selection_type +{ + AUDIO_MIXER_SLOT_SELECTION_AUTOMATIC = 0, + AUDIO_MIXER_SLOT_SELECTION_MANUAL +}; + enum audio_mixer_stream_type { AUDIO_STREAM_TYPE_NONE = 0, @@ -174,6 +180,8 @@ typedef struct audio_driver typedef struct audio_mixer_stream_params { float volume; + enum audio_mixer_slot_selection_type slot_selection_type; + unsigned slot_selection_idx; enum audio_mixer_stream_type stream_type; enum audio_mixer_type type; enum audio_mixer_state state; diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 55f1a1bc66..d95f527b28 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -2029,7 +2029,10 @@ static int action_ok_audio_add_to_mixer(const char *path, if (filestream_exists(entry_path)) task_push_audio_mixer_load(entry_path, - NULL, NULL, false); + NULL, NULL, false, + AUDIO_MIXER_SLOT_SELECTION_AUTOMATIC, + 0 + ); return 0; } @@ -2048,7 +2051,9 @@ static int action_ok_audio_add_to_mixer_and_play(const char *path, if (filestream_exists(entry_path)) task_push_audio_mixer_load_and_play(entry_path, - NULL, NULL, false); + NULL, NULL, false, + AUDIO_MIXER_SLOT_SELECTION_AUTOMATIC, + 0); return 0; } @@ -2076,7 +2081,9 @@ static int action_ok_audio_add_to_mixer_and_collection(const char *path, if (filestream_exists(combined_path)) task_push_audio_mixer_load(combined_path, - NULL, NULL, false); + NULL, NULL, false, + AUDIO_MIXER_SLOT_SELECTION_AUTOMATIC, + 0); return 0; } @@ -2104,7 +2111,9 @@ static int action_ok_audio_add_to_mixer_and_collection_and_play(const char *path if (filestream_exists(combined_path)) task_push_audio_mixer_load_and_play(combined_path, - NULL, NULL, false); + NULL, NULL, false, + AUDIO_MIXER_SLOT_SELECTION_AUTOMATIC, + 0); return 0; } diff --git a/tasks/task_audio_mixer.c b/tasks/task_audio_mixer.c index 1f952f7ab5..fdcc3e0940 100644 --- a/tasks/task_audio_mixer.c +++ b/tasks/task_audio_mixer.c @@ -44,6 +44,8 @@ typedef struct nbio_buf struct audio_mixer_userdata { enum audio_mixer_stream_type stream_type; + enum audio_mixer_slot_selection_type slot_selection_type; + unsigned slot_selection_idx; }; struct audio_mixer_handle @@ -107,6 +109,8 @@ static void task_audio_mixer_handle_upload_ogg(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_OGG; params.state = AUDIO_STREAM_STATE_STOPPED; @@ -134,6 +138,8 @@ static void task_audio_mixer_handle_upload_ogg_and_play(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_OGG; params.state = AUDIO_STREAM_STATE_PLAYING; @@ -161,6 +167,8 @@ static void task_audio_mixer_handle_upload_flac(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_FLAC; params.state = AUDIO_STREAM_STATE_STOPPED; @@ -188,6 +196,8 @@ static void task_audio_mixer_handle_upload_flac_and_play(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_FLAC; params.state = AUDIO_STREAM_STATE_PLAYING; @@ -215,6 +225,8 @@ static void task_audio_mixer_handle_upload_mp3(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_MP3; params.state = AUDIO_STREAM_STATE_STOPPED; @@ -242,6 +254,8 @@ static void task_audio_mixer_handle_upload_mp3_and_play(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_MP3; params.state = AUDIO_STREAM_STATE_PLAYING; @@ -269,6 +283,8 @@ static void task_audio_mixer_handle_upload_mod(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_MOD; params.state = AUDIO_STREAM_STATE_STOPPED; @@ -296,6 +312,8 @@ static void task_audio_mixer_handle_upload_mod_and_play(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_MOD; params.state = AUDIO_STREAM_STATE_PLAYING; @@ -323,6 +341,8 @@ static void task_audio_mixer_handle_upload_wav(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_WAV; params.state = AUDIO_STREAM_STATE_STOPPED; @@ -350,6 +370,8 @@ static void task_audio_mixer_handle_upload_wav_and_play(void *task_data, return; params.volume = 1.0f; + params.slot_selection_type = user->slot_selection_type; + params.slot_selection_idx = user->slot_selection_idx; params.stream_type = user->stream_type; params.type = AUDIO_MIXER_TYPE_WAV; params.state = AUDIO_STREAM_STATE_PLAYING; @@ -397,8 +419,11 @@ bool task_audio_mixer_load_handler(retro_task_t *task) return true; } -bool task_push_audio_mixer_load_and_play(const char *fullpath, retro_task_callback_t cb, void *user_data, - bool system) +bool task_push_audio_mixer_load_and_play( + const char *fullpath, retro_task_callback_t cb, void *user_data, + bool system, + enum audio_mixer_slot_selection_type slot_selection_type, + int slot_selection_idx) { nbio_handle_t *nbio = NULL; struct audio_mixer_handle *mixer = NULL; @@ -460,14 +485,17 @@ bool task_push_audio_mixer_load_and_play(const char *fullpath, retro_task_callba } if (system) - user->stream_type = AUDIO_STREAM_TYPE_SYSTEM; + user->stream_type = AUDIO_STREAM_TYPE_SYSTEM; else - user->stream_type = AUDIO_STREAM_TYPE_USER; + user->stream_type = AUDIO_STREAM_TYPE_USER; - nbio->data = (struct audio_mixer_handle*)mixer; - nbio->is_finished = false; - nbio->cb = &cb_nbio_audio_mixer_load; - nbio->status = NBIO_STATUS_INIT; + user->slot_selection_type = slot_selection_type; + user->slot_selection_idx = slot_selection_idx; + + nbio->data = (struct audio_mixer_handle*)mixer; + nbio->is_finished = false; + nbio->cb = &cb_nbio_audio_mixer_load; + nbio->status = NBIO_STATUS_INIT; t->state = nbio; t->handler = task_file_load_handler; @@ -499,8 +527,11 @@ error: return false; } -bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb, void *user_data, - bool system) +bool task_push_audio_mixer_load( + const char *fullpath, retro_task_callback_t cb, void *user_data, + bool system, + enum audio_mixer_slot_selection_type slot_selection_type, + int slot_selection_idx) { nbio_handle_t *nbio = NULL; struct audio_mixer_handle *mixer = NULL; @@ -567,14 +598,17 @@ bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb, nbio->status = NBIO_STATUS_INIT; if (system) - user->stream_type = AUDIO_STREAM_TYPE_SYSTEM; + user->stream_type = AUDIO_STREAM_TYPE_SYSTEM; else - user->stream_type = AUDIO_STREAM_TYPE_USER; + user->stream_type = AUDIO_STREAM_TYPE_USER; - t->state = nbio; - t->handler = task_file_load_handler; - t->cleanup = task_audio_mixer_load_free; - t->user_data = user; + user->slot_selection_type = slot_selection_type; + user->slot_selection_idx = slot_selection_idx; + + t->state = nbio; + t->handler = task_file_load_handler; + t->cleanup = task_audio_mixer_load_free; + t->user_data = user; task_queue_push(t); diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h index 427fdf3d79..3eeaec5a0c 100644 --- a/tasks/tasks_internal.h +++ b/tasks/tasks_internal.h @@ -29,6 +29,8 @@ #include "../config.h" #endif +#include "../audio/audio_driver.h" + #include "../content.h" #include "../core_type.h" #include "../msg_hash.h" @@ -262,11 +264,15 @@ enum frontend_powerstate get_last_powerstate(int *percent); bool task_push_audio_mixer_load_and_play( const char *fullpath, retro_task_callback_t cb, void *user_data, - bool system); + bool system, + enum audio_mixer_slot_selection_type slot_selection_type, + int slot_selection_idx); bool task_push_audio_mixer_load( const char *fullpath, retro_task_callback_t cb, void *user_data, - bool system); + bool system, + enum audio_mixer_slot_selection_type slot_selection_type, + int slot_selection_idx); void set_save_state_in_background(bool state);