Attempt to copy over audio mixer data

This commit is contained in:
twinaphex 2017-05-15 01:28:34 +02:00
parent ba5f7ff5e4
commit c898ef1d6d
4 changed files with 63 additions and 48 deletions

View File

@ -45,37 +45,6 @@
#define AUDIO_MIXER_MAX_VOICES 8 #define AUDIO_MIXER_MAX_VOICES 8
#define AUDIO_MIXER_TEMP_OGG_BUFFER 8192 #define AUDIO_MIXER_TEMP_OGG_BUFFER 8192
enum audio_mixer_type
{
AUDIO_MIXER_TYPE_NONE = 0,
AUDIO_MIXER_TYPE_WAV,
AUDIO_MIXER_TYPE_OGG
};
struct audio_mixer_sound
{
enum audio_mixer_type type;
union
{
struct
{
/* wav */
unsigned frames;
const float* pcm;
} wav;
#ifdef HAVE_STB_VORBIS
struct
{
/* ogg */
unsigned size;
const void* data;
} ogg;
#endif
} types;
};
struct audio_mixer_voice struct audio_mixer_voice
{ {
bool repeat; bool repeat;

View File

@ -27,11 +27,46 @@
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <boolean.h> #include <boolean.h>
#include <retro_common_api.h> #include <retro_common_api.h>
RETRO_BEGIN_DECLS RETRO_BEGIN_DECLS
enum audio_mixer_type
{
AUDIO_MIXER_TYPE_NONE = 0,
AUDIO_MIXER_TYPE_WAV,
AUDIO_MIXER_TYPE_OGG
};
struct audio_mixer_sound
{
enum audio_mixer_type type;
union
{
struct
{
/* wav */
unsigned frames;
const float* pcm;
} wav;
#ifdef HAVE_STB_VORBIS
struct
{
/* ogg */
unsigned size;
const void* data;
} ogg;
#endif
} types;
};
typedef struct audio_mixer_sound audio_mixer_sound_t; typedef struct audio_mixer_sound audio_mixer_sound_t;
typedef struct audio_mixer_voice audio_mixer_voice_t; typedef struct audio_mixer_voice audio_mixer_voice_t;

View File

@ -39,6 +39,7 @@
#include <compat/strl.h> #include <compat/strl.h>
#include <compat/getopt.h> #include <compat/getopt.h>
#include <audio/audio_mixer.h>
#include <compat/posix_string.h> #include <compat/posix_string.h>
#include <file/file_path.h> #include <file/file_path.h>
#include <retro_stat.h> #include <retro_stat.h>
@ -2261,7 +2262,11 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
static void runloop_upload_audio(void *task_data, static void runloop_upload_audio(void *task_data,
void *user_data, const char *err) void *user_data, const char *err)
{ {
RARCH_LOG("GETS HERE.\n"); audio_mixer_sound_t *handle = (audio_mixer_sound_t*)task_data;
if (handle)
audio_mixer_play(handle, true, 1.0f, NULL);
free(user_data); free(user_data);
} }
#endif #endif

View File

@ -32,8 +32,8 @@
struct nbio_audio_mixer_handle struct nbio_audio_mixer_handle
{ {
audio_mixer_sound_t *handle;
bool is_finished; bool is_finished;
void *handle;
}; };
static void task_audio_mixer_cleanup(nbio_handle_t *nbio) static void task_audio_mixer_cleanup(nbio_handle_t *nbio)
@ -64,20 +64,16 @@ static int cb_nbio_audio_wav_loaded(void *data, size_t len)
struct nbio_audio_mixer_handle *image = nbio ? struct nbio_audio_mixer_handle *image = nbio ?
(struct nbio_audio_mixer_handle*)nbio->data : NULL; (struct nbio_audio_mixer_handle*)nbio->data : NULL;
void *ptr = nbio_get_ptr(nbio->handle, &len); void *ptr = nbio_get_ptr(nbio->handle, &len);
audio_mixer_sound_t *audmix = audio_mixer_load_wav(ptr, len);
if (!audmix || image->handle = audio_mixer_load_wav(ptr, len);
!audio_mixer_play(audmix, true, 0.0f, NULL)
) if (!image->handle)
{ {
task_audio_mixer_cleanup(nbio); task_audio_mixer_cleanup(nbio);
return -1; return -1;
} }
free(ptr);
image->is_finished = true; image->is_finished = true;
nbio->is_finished = true;
return 0; return 0;
} }
@ -90,18 +86,16 @@ static int cb_nbio_audio_ogg_loaded(void *data, size_t len)
(struct nbio_audio_mixer_handle*)nbio->data : NULL; (struct nbio_audio_mixer_handle*)nbio->data : NULL;
void *ptr = nbio_get_ptr(nbio->handle, &len); void *ptr = nbio_get_ptr(nbio->handle, &len);
audio_mixer_sound_t *audmix = audio_mixer_load_ogg(ptr, len);
if (!audmix || image->handle = audio_mixer_load_ogg(ptr, len);
!audio_mixer_play(audmix, true, 0.0f, NULL)
) if (!image->handle)
{ {
task_audio_mixer_cleanup(nbio); task_audio_mixer_cleanup(nbio);
return -1; return -1;
} }
image->is_finished = true; image->is_finished = true;
nbio->is_finished = true;
return 0; return 0;
} }
@ -112,10 +106,22 @@ bool task_audio_mixer_load_handler(retro_task_t *task)
nbio_handle_t *nbio = (nbio_handle_t*)task->state; nbio_handle_t *nbio = (nbio_handle_t*)task->state;
struct nbio_audio_mixer_handle *image = (struct nbio_audio_mixer_handle*)nbio->data; struct nbio_audio_mixer_handle *image = (struct nbio_audio_mixer_handle*)nbio->data;
if ( nbio->is_finished if (
&& (image && image->is_finished ) (image && image->is_finished )
&& (!task_get_cancelled(task))) && (!task_get_cancelled(task)))
{
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; return false;
}
return true; return true;
} }