Update task_audio_mixer.c
This commit is contained in:
parent
375b588847
commit
67610b8263
|
@ -1047,6 +1047,19 @@ void audio_driver_destroy(void)
|
||||||
current_audio = NULL;
|
current_audio = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void audio_set_bool(enum audio_action action, bool val)
|
||||||
|
{
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case AUDIO_ACTION_MIXER:
|
||||||
|
audio_mixer_active = val;
|
||||||
|
break;
|
||||||
|
case AUDIO_ACTION_NONE:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void audio_set_float(enum audio_action action, float val)
|
void audio_set_float(enum audio_action action, float val)
|
||||||
{
|
{
|
||||||
switch (action)
|
switch (action)
|
||||||
|
|
|
@ -37,7 +37,8 @@ enum audio_action
|
||||||
{
|
{
|
||||||
AUDIO_ACTION_NONE = 0,
|
AUDIO_ACTION_NONE = 0,
|
||||||
AUDIO_ACTION_RATE_CONTROL_DELTA,
|
AUDIO_ACTION_RATE_CONTROL_DELTA,
|
||||||
AUDIO_ACTION_MUTE_ENABLE
|
AUDIO_ACTION_MUTE_ENABLE,
|
||||||
|
AUDIO_ACTION_MIXER
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct audio_driver
|
typedef struct audio_driver
|
||||||
|
@ -218,6 +219,10 @@ void audio_driver_frame_is_reverse(void);
|
||||||
|
|
||||||
void audio_set_float(enum audio_action action, float val);
|
void audio_set_float(enum audio_action action, float val);
|
||||||
|
|
||||||
|
void audio_set_bool(enum audio_action action, bool val);
|
||||||
|
|
||||||
|
void audio_unset_bool(enum audio_action action, bool val);
|
||||||
|
|
||||||
float *audio_get_float_ptr(enum audio_action action);
|
float *audio_get_float_ptr(enum audio_action action);
|
||||||
|
|
||||||
bool *audio_get_bool_ptr(enum audio_action action);
|
bool *audio_get_bool_ptr(enum audio_action action);
|
||||||
|
|
15
retroarch.c
15
retroarch.c
|
@ -2229,19 +2229,6 @@ bool runloop_msg_queue_pull(const char **ret)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static void runloop_upload_audio(void *task_data,
|
|
||||||
void *user_data, const char *err)
|
|
||||||
{
|
|
||||||
audio_mixer_sound_t *handle = (audio_mixer_sound_t*)task_data;
|
|
||||||
|
|
||||||
if (handle)
|
|
||||||
audio_mixer_play(handle, true, 1.0f, NULL);
|
|
||||||
|
|
||||||
free(user_data);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Time to exit out of the main loop?
|
/* Time to exit out of the main loop?
|
||||||
* Reasons for exiting:
|
* Reasons for exiting:
|
||||||
* a) Shutdown environment callback was invoked.
|
* a) Shutdown environment callback was invoked.
|
||||||
|
@ -2612,7 +2599,7 @@ static enum runloop_state runloop_check_state(
|
||||||
command_event(CMD_EVENT_RESET, NULL);
|
command_event(CMD_EVENT_RESET, NULL);
|
||||||
#if 0
|
#if 0
|
||||||
task_push_audio_mixer_load("/home/squarepusher/SumertimeBlues.ogg",
|
task_push_audio_mixer_load("/home/squarepusher/SumertimeBlues.ogg",
|
||||||
runloop_upload_audio, NULL);
|
NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,13 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <file/nbio.h>
|
|
||||||
#include <audio/audio_mixer.h>
|
#include <audio/audio_mixer.h>
|
||||||
|
#include <streams/file_stream.h>
|
||||||
#include <compat/strl.h>
|
#include <compat/strl.h>
|
||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
|
|
||||||
|
#include "../audio/audio_driver.h"
|
||||||
|
|
||||||
#include "../file_path_special.h"
|
#include "../file_path_special.h"
|
||||||
#include "../verbosity.h"
|
#include "../verbosity.h"
|
||||||
|
|
||||||
|
@ -32,152 +34,92 @@
|
||||||
|
|
||||||
struct nbio_audio_mixer_handle
|
struct nbio_audio_mixer_handle
|
||||||
{
|
{
|
||||||
audio_mixer_sound_t *handle;
|
enum audio_mixer_type type;
|
||||||
bool is_finished;
|
char path[4095];
|
||||||
};
|
};
|
||||||
|
|
||||||
static void task_audio_mixer_cleanup(nbio_handle_t *nbio)
|
static void audio_mixer_stopped(audio_mixer_sound_t *sound, unsigned reason)
|
||||||
{
|
{
|
||||||
struct nbio_audio_mixer_handle *image = (struct nbio_audio_mixer_handle*)nbio->data;
|
if (sound)
|
||||||
|
audio_mixer_destroy(sound);
|
||||||
if (nbio->data)
|
audio_set_bool(AUDIO_ACTION_MIXER, false);
|
||||||
free(nbio->data);
|
|
||||||
nbio_free(nbio->handle);
|
|
||||||
nbio->data = NULL;
|
|
||||||
nbio->handle = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void task_audio_mixer_load_free(retro_task_t *task)
|
static void task_audio_mixer_load_handler(retro_task_t *task)
|
||||||
{
|
|
||||||
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
|
||||||
|
|
||||||
if (nbio)
|
|
||||||
{
|
|
||||||
task_audio_mixer_cleanup(nbio);
|
|
||||||
free(nbio);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cb_nbio_audio_wav_loaded(void *data, size_t len)
|
|
||||||
{
|
|
||||||
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
|
||||||
struct nbio_audio_mixer_handle *image =
|
|
||||||
(struct nbio_audio_mixer_handle*)nbio->data;
|
|
||||||
void *ptr = nbio_get_ptr(nbio->handle, &len);
|
|
||||||
|
|
||||||
image->handle = audio_mixer_load_wav(ptr, len);
|
|
||||||
|
|
||||||
if (!image->handle)
|
|
||||||
{
|
|
||||||
task_audio_mixer_cleanup(nbio);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
image->is_finished = true;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cb_nbio_audio_ogg_loaded(void *data, size_t len)
|
|
||||||
{
|
|
||||||
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
|
||||||
struct nbio_audio_mixer_handle
|
|
||||||
*image =
|
|
||||||
(struct nbio_audio_mixer_handle*)nbio->data;
|
|
||||||
|
|
||||||
void *ptr = nbio_get_ptr(nbio->handle, &len);
|
|
||||||
|
|
||||||
image->handle = audio_mixer_load_ogg(ptr, len);
|
|
||||||
|
|
||||||
if (!image->handle)
|
|
||||||
{
|
|
||||||
task_audio_mixer_cleanup(nbio);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
image->is_finished = true;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool task_audio_mixer_load_handler(retro_task_t *task)
|
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
|
void *buffer = NULL;
|
||||||
struct nbio_audio_mixer_handle *image = (struct nbio_audio_mixer_handle*)nbio->data;
|
ssize_t size = 0;
|
||||||
|
audio_mixer_sound_t *handle = NULL;
|
||||||
|
struct nbio_audio_mixer_handle *image = (struct nbio_audio_mixer_handle*)task->state;
|
||||||
|
|
||||||
if (
|
if (filestream_read_file(image->path, &buffer, &size) == 0)
|
||||||
(image && image->is_finished )
|
|
||||||
&& (!task_get_cancelled(task)))
|
|
||||||
{
|
{
|
||||||
audio_mixer_sound_t *data = (audio_mixer_sound_t*)calloc(1, sizeof(*data));
|
task_set_finished(task, true);
|
||||||
|
return;
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
memcpy((void*)data, &image->handle, sizeof(audio_mixer_sound_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
task_set_data(task, data);
|
|
||||||
|
|
||||||
nbio->is_finished = true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
switch (image->type)
|
||||||
|
{
|
||||||
|
case AUDIO_MIXER_TYPE_WAV:
|
||||||
|
handle = audio_mixer_load_wav(buffer, size);
|
||||||
|
break;
|
||||||
|
case AUDIO_MIXER_TYPE_OGG:
|
||||||
|
handle = audio_mixer_load_ogg(buffer, size);
|
||||||
|
break;
|
||||||
|
case AUDIO_MIXER_TYPE_NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle)
|
||||||
|
audio_mixer_play(handle, true, 1.0f, audio_mixer_stopped);
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
audio_set_bool(AUDIO_ACTION_MIXER, true);
|
||||||
|
|
||||||
|
task_set_progress(task, 100);
|
||||||
|
#if 0
|
||||||
|
task_set_title(task, strdup(msg_hash_to_str(MSG_WIFI_SCAN_COMPLETE)));
|
||||||
|
#endif
|
||||||
|
task_set_finished(task, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb, void *user_data)
|
bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb, void *user_data)
|
||||||
{
|
{
|
||||||
nbio_handle_t *nbio = NULL;
|
|
||||||
struct nbio_audio_mixer_handle *image = NULL;
|
struct nbio_audio_mixer_handle *image = NULL;
|
||||||
retro_task_t *t = (retro_task_t*)calloc(1, sizeof(*t));
|
retro_task_t *t = (retro_task_t*)calloc(1, sizeof(*t));
|
||||||
|
|
||||||
if (!t)
|
if (!t)
|
||||||
goto error_msg;
|
goto error_msg;
|
||||||
|
|
||||||
nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));
|
|
||||||
|
|
||||||
if (!nbio)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
strlcpy(nbio->path, fullpath, sizeof(nbio->path));
|
|
||||||
|
|
||||||
image = (struct nbio_audio_mixer_handle*)calloc(1, sizeof(*image));
|
image = (struct nbio_audio_mixer_handle*)calloc(1, sizeof(*image));
|
||||||
if (!image)
|
if (!image)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
nbio->type = NBIO_TYPE_NONE;
|
strlcpy(image->path, fullpath, sizeof(image->path));
|
||||||
|
|
||||||
|
image->type = AUDIO_MIXER_TYPE_NONE;
|
||||||
|
|
||||||
if (strstr(fullpath, file_path_str(FILE_PATH_WAV_EXTENSION)))
|
if (strstr(fullpath, file_path_str(FILE_PATH_WAV_EXTENSION)))
|
||||||
{
|
{
|
||||||
nbio->type = NBIO_TYPE_WAV;
|
image->type = AUDIO_MIXER_TYPE_WAV;
|
||||||
nbio->cb = &cb_nbio_audio_wav_loaded;
|
|
||||||
}
|
}
|
||||||
else if (strstr(fullpath, file_path_str(FILE_PATH_OGG_EXTENSION)))
|
else if (strstr(fullpath, file_path_str(FILE_PATH_OGG_EXTENSION)))
|
||||||
{
|
{
|
||||||
nbio->type = NBIO_TYPE_OGG;
|
image->type = AUDIO_MIXER_TYPE_OGG;
|
||||||
nbio->cb = &cb_nbio_audio_ogg_loaded;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nbio->data = (struct nbio_audio_mixer_handle*)image;
|
t->state = image;
|
||||||
nbio->is_finished = false;
|
t->handler = task_audio_mixer_load_handler;
|
||||||
nbio->status = NBIO_STATUS_INIT;
|
t->callback = NULL;
|
||||||
|
|
||||||
t->state = nbio;
|
|
||||||
t->handler = task_file_load_handler;
|
|
||||||
t->cleanup = task_audio_mixer_load_free;
|
|
||||||
t->callback = cb;
|
|
||||||
t->user_data = user_data;
|
|
||||||
|
|
||||||
task_queue_push(t);
|
task_queue_push(t);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
task_audio_mixer_load_free(t);
|
|
||||||
free(t);
|
free(t);
|
||||||
if (nbio)
|
|
||||||
free(nbio);
|
|
||||||
|
|
||||||
error_msg:
|
error_msg:
|
||||||
RARCH_ERR("[audio mixer load] Failed to open '%s': %s.\n",
|
RARCH_ERR("[audio mixer load] Failed to open '%s': %s.\n",
|
||||||
|
|
|
@ -111,11 +111,6 @@ void task_file_load_handler(retro_task_t *task)
|
||||||
if (!task_image_load_handler(task))
|
if (!task_image_load_handler(task))
|
||||||
task_set_finished(task, true);
|
task_set_finished(task, true);
|
||||||
break;
|
break;
|
||||||
case NBIO_TYPE_OGG:
|
|
||||||
case NBIO_TYPE_WAV:
|
|
||||||
if (!task_audio_mixer_load_handler(task))
|
|
||||||
task_set_finished(task, true);
|
|
||||||
break;
|
|
||||||
case NBIO_TYPE_NONE:
|
case NBIO_TYPE_NONE:
|
||||||
default:
|
default:
|
||||||
if (nbio->is_finished)
|
if (nbio->is_finished)
|
||||||
|
|
|
@ -204,8 +204,6 @@ bool task_push_load_content_with_core_from_menu(
|
||||||
void *user_data);
|
void *user_data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool task_audio_mixer_load_handler(retro_task_t *task);
|
|
||||||
|
|
||||||
void task_file_load_handler(retro_task_t *task);
|
void task_file_load_handler(retro_task_t *task);
|
||||||
|
|
||||||
bool take_screenshot(const char *path, bool silence, bool has_valid_framebuffer);
|
bool take_screenshot(const char *path, bool silence, bool has_valid_framebuffer);
|
||||||
|
|
Loading…
Reference in New Issue