Skip to content

Commit

Permalink
(Audio mixer) You can now specifically set a slot to load a sound in
Browse files Browse the repository at this point in the history
- set type to AUDIO_MIXER_SLOT_SELECTION_MANUAL and set idx to the
slot you want to load in (begins at 0)
  • Loading branch information
inactive123 committed Jan 17, 2019
1 parent 2860d6a commit fc57b41
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 24 deletions.
14 changes: 12 additions & 2 deletions audio/audio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions audio/audio_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 13 additions & 4 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
66 changes: 50 additions & 16 deletions tasks/task_audio_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -499,8 +527,11 @@ bool task_push_audio_mixer_load_and_play(const char *fullpath, retro_task_callba
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;
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions tasks/tasks_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "../config.h"
#endif

#include "../audio/audio_driver.h"

#include "../content.h"
#include "../core_type.h"
#include "../msg_hash.h"
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit fc57b41

Please sign in to comment.