Update task_audio_mixer.c

This commit is contained in:
twinaphex 2017-05-15 11:07:12 +02:00
parent 375b588847
commit 67610b8263
6 changed files with 69 additions and 129 deletions

View File

@ -1047,6 +1047,19 @@ void audio_driver_destroy(void)
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)
{
switch (action)

View File

@ -37,7 +37,8 @@ enum audio_action
{
AUDIO_ACTION_NONE = 0,
AUDIO_ACTION_RATE_CONTROL_DELTA,
AUDIO_ACTION_MUTE_ENABLE
AUDIO_ACTION_MUTE_ENABLE,
AUDIO_ACTION_MIXER
};
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_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);
bool *audio_get_bool_ptr(enum audio_action action);

View File

@ -2229,19 +2229,6 @@ bool runloop_msg_queue_pull(const char **ret)
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?
* Reasons for exiting:
* a) Shutdown environment callback was invoked.
@ -2612,7 +2599,7 @@ static enum runloop_state runloop_check_state(
command_event(CMD_EVENT_RESET, NULL);
#if 0
task_push_audio_mixer_load("/home/squarepusher/SumertimeBlues.ogg",
runloop_upload_audio, NULL);
NULL, NULL);
#endif
}

View File

@ -20,11 +20,13 @@
#include <string.h>
#include <errno.h>
#include <file/nbio.h>
#include <audio/audio_mixer.h>
#include <streams/file_stream.h>
#include <compat/strl.h>
#include <retro_miscellaneous.h>
#include "../audio/audio_driver.h"
#include "../file_path_special.h"
#include "../verbosity.h"
@ -32,152 +34,92 @@
struct nbio_audio_mixer_handle
{
audio_mixer_sound_t *handle;
bool is_finished;
enum audio_mixer_type type;
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 (nbio->data)
free(nbio->data);
nbio_free(nbio->handle);
nbio->data = NULL;
nbio->handle = NULL;
if (sound)
audio_mixer_destroy(sound);
audio_set_bool(AUDIO_ACTION_MIXER, false);
}
static void task_audio_mixer_load_free(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)
static void task_audio_mixer_load_handler(retro_task_t *task)
{
unsigned i;
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
struct nbio_audio_mixer_handle *image = (struct nbio_audio_mixer_handle*)nbio->data;
void *buffer = NULL;
ssize_t size = 0;
audio_mixer_sound_t *handle = NULL;
struct nbio_audio_mixer_handle *image = (struct nbio_audio_mixer_handle*)task->state;
if (
(image && image->is_finished )
&& (!task_get_cancelled(task)))
if (filestream_read_file(image->path, &buffer, &size) == 0)
{
audio_mixer_sound_t *data = (audio_mixer_sound_t*)calloc(1, sizeof(*data));
if (data)
{
memcpy((void*)data, &image->handle, sizeof(audio_mixer_sound_t));
}
task_set_data(task, data);
nbio->is_finished = true;
return false;
task_set_finished(task, true);
return;
}
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)
{
nbio_handle_t *nbio = NULL;
struct nbio_audio_mixer_handle *image = NULL;
retro_task_t *t = (retro_task_t*)calloc(1, sizeof(*t));
if (!t)
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));
if (!image)
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)))
{
nbio->type = NBIO_TYPE_WAV;
nbio->cb = &cb_nbio_audio_wav_loaded;
image->type = AUDIO_MIXER_TYPE_WAV;
}
else if (strstr(fullpath, file_path_str(FILE_PATH_OGG_EXTENSION)))
{
nbio->type = NBIO_TYPE_OGG;
nbio->cb = &cb_nbio_audio_ogg_loaded;
image->type = AUDIO_MIXER_TYPE_OGG;
}
nbio->data = (struct nbio_audio_mixer_handle*)image;
nbio->is_finished = false;
nbio->status = NBIO_STATUS_INIT;
t->state = nbio;
t->handler = task_file_load_handler;
t->cleanup = task_audio_mixer_load_free;
t->callback = cb;
t->user_data = user_data;
t->state = image;
t->handler = task_audio_mixer_load_handler;
t->callback = NULL;
task_queue_push(t);
return true;
error:
task_audio_mixer_load_free(t);
free(t);
if (nbio)
free(nbio);
error_msg:
RARCH_ERR("[audio mixer load] Failed to open '%s': %s.\n",

View File

@ -111,11 +111,6 @@ void task_file_load_handler(retro_task_t *task)
if (!task_image_load_handler(task))
task_set_finished(task, true);
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:
default:
if (nbio->is_finished)

View File

@ -204,8 +204,6 @@ bool task_push_load_content_with_core_from_menu(
void *user_data);
#endif
bool task_audio_mixer_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);