mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-07 09:57:49 +00:00
Reimplement task_audio_mixer.c
This commit is contained in:
parent
b3faed3906
commit
9a90477c6d
@ -35,7 +35,9 @@
|
|||||||
|
|
||||||
struct audio_mixer_handle
|
struct audio_mixer_handle
|
||||||
{
|
{
|
||||||
audio_mixer_sound_t *handle;
|
nbio_buf_t *buffer;
|
||||||
|
bool copy_data_over;
|
||||||
|
bool is_finished;
|
||||||
enum audio_mixer_type type;
|
enum audio_mixer_type type;
|
||||||
char path[4095];
|
char path[4095];
|
||||||
};
|
};
|
||||||
@ -51,7 +53,14 @@ static void audio_mixer_stopped(audio_mixer_sound_t *sound, unsigned reason)
|
|||||||
|
|
||||||
static void task_audio_mixer_load_free(retro_task_t *task)
|
static void task_audio_mixer_load_free(retro_task_t *task)
|
||||||
{
|
{
|
||||||
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
||||||
|
struct audio_mixer_handle *image = (struct audio_mixer_handle*)nbio->data;
|
||||||
|
|
||||||
|
if (image)
|
||||||
|
{
|
||||||
|
if (image->buffer)
|
||||||
|
free(image->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
if (nbio)
|
if (nbio)
|
||||||
{
|
{
|
||||||
@ -67,35 +76,85 @@ static int cb_nbio_audio_mixer_load(void *data, size_t len)
|
|||||||
(struct audio_mixer_handle*)nbio->data : NULL;
|
(struct audio_mixer_handle*)nbio->data : NULL;
|
||||||
void *ptr = nbio_get_ptr(nbio->handle, &len);
|
void *ptr = nbio_get_ptr(nbio->handle, &len);
|
||||||
|
|
||||||
switch (image->type)
|
image->buffer = (nbio_buf_t*)calloc(1, sizeof(*image->buffer));
|
||||||
{
|
|
||||||
case AUDIO_MIXER_TYPE_OGG:
|
|
||||||
handle = audio_mixer_load_ogg(ptr, len);
|
|
||||||
break;
|
|
||||||
case AUDIO_MIXER_TYPE_WAV:
|
|
||||||
handle = audio_mixer_load_wav(ptr, len);
|
|
||||||
break;
|
|
||||||
case AUDIO_MIXER_TYPE_NONE:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (handle)
|
if (!image->buffer)
|
||||||
{
|
return -1;
|
||||||
audio_mixer_play(handle, true, 1.0f, audio_mixer_stopped);
|
|
||||||
|
|
||||||
image->handle = handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
image->buffer->buf = ptr;
|
||||||
|
image->buffer->bufsize = len;
|
||||||
|
image->copy_data_over = true;
|
||||||
nbio->is_finished = true;
|
nbio->is_finished = true;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void task_audio_mixer_handle_upload(void *task_data,
|
static void task_audio_mixer_handle_upload_ogg(void *task_data,
|
||||||
void *user_data, const char *err)
|
void *user_data, const char *err)
|
||||||
{
|
{
|
||||||
audio_set_bool(AUDIO_ACTION_MIXER, true);
|
nbio_buf_t *img = (nbio_buf_t*)task_data;
|
||||||
|
|
||||||
|
if (!img)
|
||||||
|
return;
|
||||||
|
|
||||||
|
{
|
||||||
|
audio_mixer_sound_t *handle = audio_mixer_load_ogg(img->buf, img->bufsize);
|
||||||
|
audio_mixer_play(handle, true, 1.0f, audio_mixer_stopped);
|
||||||
|
|
||||||
|
audio_set_bool(AUDIO_ACTION_MIXER, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(img);
|
||||||
|
free(user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void task_audio_mixer_handle_upload_wav(void *task_data,
|
||||||
|
void *user_data, const char *err)
|
||||||
|
{
|
||||||
|
nbio_buf_t *img = (nbio_buf_t*)task_data;
|
||||||
|
|
||||||
|
if (!img)
|
||||||
|
return;
|
||||||
|
{
|
||||||
|
audio_mixer_sound_t *handle = audio_mixer_load_wav(img->buf, img->bufsize);
|
||||||
|
audio_mixer_play(handle, true, 1.0f, audio_mixer_stopped);
|
||||||
|
|
||||||
|
audio_set_bool(AUDIO_ACTION_MIXER, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(img);
|
||||||
|
free(user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool task_audio_mixer_load_handler(retro_task_t *task)
|
||||||
|
{
|
||||||
|
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
|
||||||
|
struct audio_mixer_handle *image = (struct audio_mixer_handle*)nbio->data;
|
||||||
|
|
||||||
|
if (
|
||||||
|
nbio->is_finished
|
||||||
|
&& (image && !image->is_finished)
|
||||||
|
&& (image->copy_data_over)
|
||||||
|
&& (!task_get_cancelled(task)))
|
||||||
|
{
|
||||||
|
nbio_buf_t *img = (nbio_buf_t*)calloc(1, sizeof(*img));
|
||||||
|
|
||||||
|
if (img)
|
||||||
|
{
|
||||||
|
img->buf = image->buffer->buf;
|
||||||
|
img->bufsize = image->buffer->bufsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
task_set_data(task, img);
|
||||||
|
|
||||||
|
image->copy_data_over = false;
|
||||||
|
image->is_finished = true;
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 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)
|
||||||
@ -118,6 +177,8 @@ bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb,
|
|||||||
if (!image)
|
if (!image)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
image->is_finished = false;
|
||||||
|
|
||||||
strlcpy(image->path, fullpath, sizeof(image->path));
|
strlcpy(image->path, fullpath, sizeof(image->path));
|
||||||
|
|
||||||
nbio->type = NBIO_TYPE_NONE;
|
nbio->type = NBIO_TYPE_NONE;
|
||||||
@ -126,10 +187,14 @@ bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb,
|
|||||||
if (strstr(fullpath, file_path_str(FILE_PATH_WAV_EXTENSION)))
|
if (strstr(fullpath, file_path_str(FILE_PATH_WAV_EXTENSION)))
|
||||||
{
|
{
|
||||||
image->type = AUDIO_MIXER_TYPE_WAV;
|
image->type = AUDIO_MIXER_TYPE_WAV;
|
||||||
|
nbio->type = NBIO_TYPE_WAV;
|
||||||
|
t->callback = task_audio_mixer_handle_upload_wav;
|
||||||
}
|
}
|
||||||
else if (strstr(fullpath, file_path_str(FILE_PATH_OGG_EXTENSION)))
|
else if (strstr(fullpath, file_path_str(FILE_PATH_OGG_EXTENSION)))
|
||||||
{
|
{
|
||||||
image->type = AUDIO_MIXER_TYPE_OGG;
|
image->type = AUDIO_MIXER_TYPE_OGG;
|
||||||
|
nbio->type = NBIO_TYPE_OGG;
|
||||||
|
t->callback = task_audio_mixer_handle_upload_ogg;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbio->data = (struct audio_mixer_handle*)image;
|
nbio->data = (struct audio_mixer_handle*)image;
|
||||||
@ -140,7 +205,6 @@ bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb,
|
|||||||
t->state = nbio;
|
t->state = nbio;
|
||||||
t->handler = task_file_load_handler;
|
t->handler = task_file_load_handler;
|
||||||
t->cleanup = task_audio_mixer_load_free;
|
t->cleanup = task_audio_mixer_load_free;
|
||||||
t->callback = task_audio_mixer_handle_upload;
|
|
||||||
t->user_data = user_data;
|
t->user_data = user_data;
|
||||||
|
|
||||||
task_queue_push(t);
|
task_queue_push(t);
|
||||||
|
@ -109,6 +109,11 @@ 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)
|
||||||
|
@ -38,6 +38,12 @@ RETRO_BEGIN_DECLS
|
|||||||
|
|
||||||
typedef int (*transfer_cb_t)(void *data, size_t len);
|
typedef int (*transfer_cb_t)(void *data, size_t len);
|
||||||
|
|
||||||
|
typedef struct nbio_buf
|
||||||
|
{
|
||||||
|
void *buf;
|
||||||
|
unsigned bufsize;
|
||||||
|
} nbio_buf_t;
|
||||||
|
|
||||||
enum content_mode_load
|
enum content_mode_load
|
||||||
{
|
{
|
||||||
CONTENT_MODE_LOAD_NONE = 0,
|
CONTENT_MODE_LOAD_NONE = 0,
|
||||||
@ -205,6 +211,8 @@ bool task_push_load_content_with_core_from_menu(
|
|||||||
|
|
||||||
void task_file_load_handler(retro_task_t *task);
|
void task_file_load_handler(retro_task_t *task);
|
||||||
|
|
||||||
|
bool task_audio_mixer_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);
|
||||||
|
|
||||||
bool event_load_save_files(void);
|
bool event_load_save_files(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user