mirror of
https://github.com/libretro/RetroArch
synced 2025-04-04 22:20:25 +00:00
(task_audio_mixer.c) Optimize further
This commit is contained in:
parent
eaba575c9e
commit
421bcb07d3
@ -457,6 +457,15 @@ bool task_push_audio_mixer_load_and_play(
|
|||||||
struct audio_mixer_handle *mixer = NULL;
|
struct audio_mixer_handle *mixer = NULL;
|
||||||
retro_task_t *t = task_init();
|
retro_task_t *t = task_init();
|
||||||
struct audio_mixer_userdata *user = (struct audio_mixer_userdata*)calloc(1, sizeof(*user));
|
struct audio_mixer_userdata *user = (struct audio_mixer_userdata*)calloc(1, sizeof(*user));
|
||||||
|
/* We are comparing against a fixed list of file
|
||||||
|
* extensions, the longest (jpeg) being 4 characters
|
||||||
|
* in length. We therefore only need to extract the first
|
||||||
|
* 5 characters from the extension of the input path
|
||||||
|
* to correctly validate a match */
|
||||||
|
const char *ext = NULL;
|
||||||
|
char ext_lower[6];
|
||||||
|
|
||||||
|
ext_lower[0] = '\0';
|
||||||
|
|
||||||
if (!t || !user)
|
if (!t || !user)
|
||||||
goto error;
|
goto error;
|
||||||
@ -479,34 +488,44 @@ bool task_push_audio_mixer_load_and_play(
|
|||||||
nbio->type = NBIO_TYPE_NONE;
|
nbio->type = NBIO_TYPE_NONE;
|
||||||
mixer->type = AUDIO_MIXER_TYPE_NONE;
|
mixer->type = AUDIO_MIXER_TYPE_NONE;
|
||||||
|
|
||||||
if (string_ends_with(fullpath, ".wav"))
|
/* Get file extension */
|
||||||
|
ext = strrchr(fullpath, '.');
|
||||||
|
|
||||||
|
if (!ext || (*(++ext) == '\0'))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
/* Copy and convert to lower case */
|
||||||
|
strlcpy(ext_lower, ext, sizeof(ext_lower));
|
||||||
|
string_to_lower(ext_lower);
|
||||||
|
|
||||||
|
if (string_is_equal(ext_lower, "wav"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_WAV;
|
mixer->type = AUDIO_MIXER_TYPE_WAV;
|
||||||
nbio->type = NBIO_TYPE_WAV;
|
nbio->type = NBIO_TYPE_WAV;
|
||||||
t->callback = task_audio_mixer_handle_upload_wav_and_play;
|
t->callback = task_audio_mixer_handle_upload_wav_and_play;
|
||||||
}
|
}
|
||||||
else if (string_ends_with(fullpath, ".ogg"))
|
else if (string_is_equal(ext_lower, "ogg"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_OGG;
|
mixer->type = AUDIO_MIXER_TYPE_OGG;
|
||||||
nbio->type = NBIO_TYPE_OGG;
|
nbio->type = NBIO_TYPE_OGG;
|
||||||
t->callback = task_audio_mixer_handle_upload_ogg_and_play;
|
t->callback = task_audio_mixer_handle_upload_ogg_and_play;
|
||||||
}
|
}
|
||||||
else if (string_ends_with(fullpath, ".mp3"))
|
else if (string_is_equal(ext_lower, "mp3"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_MP3;
|
mixer->type = AUDIO_MIXER_TYPE_MP3;
|
||||||
nbio->type = NBIO_TYPE_MP3;
|
nbio->type = NBIO_TYPE_MP3;
|
||||||
t->callback = task_audio_mixer_handle_upload_mp3_and_play;
|
t->callback = task_audio_mixer_handle_upload_mp3_and_play;
|
||||||
}
|
}
|
||||||
else if (string_ends_with(fullpath, ".flac"))
|
else if (string_is_equal(ext_lower, "flac"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_FLAC;
|
mixer->type = AUDIO_MIXER_TYPE_FLAC;
|
||||||
nbio->type = NBIO_TYPE_FLAC;
|
nbio->type = NBIO_TYPE_FLAC;
|
||||||
t->callback = task_audio_mixer_handle_upload_flac_and_play;
|
t->callback = task_audio_mixer_handle_upload_flac_and_play;
|
||||||
}
|
}
|
||||||
else if (
|
else if (
|
||||||
string_ends_with(fullpath, ".mod") ||
|
string_is_equal(ext_lower, "mod") ||
|
||||||
string_ends_with(fullpath, ".s3m") ||
|
string_is_equal(ext_lower, "s3m") ||
|
||||||
string_ends_with(fullpath, ".xm"))
|
string_is_equal(ext_lower, "xm"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_MOD;
|
mixer->type = AUDIO_MIXER_TYPE_MOD;
|
||||||
nbio->type = NBIO_TYPE_MOD;
|
nbio->type = NBIO_TYPE_MOD;
|
||||||
@ -566,6 +585,15 @@ bool task_push_audio_mixer_load(
|
|||||||
struct audio_mixer_handle *mixer = NULL;
|
struct audio_mixer_handle *mixer = NULL;
|
||||||
retro_task_t *t = task_init();
|
retro_task_t *t = task_init();
|
||||||
struct audio_mixer_userdata *user = (struct audio_mixer_userdata*)calloc(1, sizeof(*user));
|
struct audio_mixer_userdata *user = (struct audio_mixer_userdata*)calloc(1, sizeof(*user));
|
||||||
|
/* We are comparing against a fixed list of file
|
||||||
|
* extensions, the longest (jpeg) being 4 characters
|
||||||
|
* in length. We therefore only need to extract the first
|
||||||
|
* 5 characters from the extension of the input path
|
||||||
|
* to correctly validate a match */
|
||||||
|
const char *ext = NULL;
|
||||||
|
char ext_lower[6];
|
||||||
|
|
||||||
|
ext_lower[0] = '\0';
|
||||||
|
|
||||||
if (!t || !user)
|
if (!t || !user)
|
||||||
goto error;
|
goto error;
|
||||||
@ -589,34 +617,44 @@ bool task_push_audio_mixer_load(
|
|||||||
nbio->type = NBIO_TYPE_NONE;
|
nbio->type = NBIO_TYPE_NONE;
|
||||||
mixer->type = AUDIO_MIXER_TYPE_NONE;
|
mixer->type = AUDIO_MIXER_TYPE_NONE;
|
||||||
|
|
||||||
if (string_ends_with(fullpath, ".wav"))
|
/* Get file extension */
|
||||||
|
ext = strrchr(fullpath, '.');
|
||||||
|
|
||||||
|
if (!ext || (*(++ext) == '\0'))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
/* Copy and convert to lower case */
|
||||||
|
strlcpy(ext_lower, ext, sizeof(ext_lower));
|
||||||
|
string_to_lower(ext_lower);
|
||||||
|
|
||||||
|
if (string_is_equal(ext_lower, "wav"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_WAV;
|
mixer->type = AUDIO_MIXER_TYPE_WAV;
|
||||||
nbio->type = NBIO_TYPE_WAV;
|
nbio->type = NBIO_TYPE_WAV;
|
||||||
t->callback = task_audio_mixer_handle_upload_wav;
|
t->callback = task_audio_mixer_handle_upload_wav;
|
||||||
}
|
}
|
||||||
else if (string_ends_with(fullpath, ".ogg"))
|
else if (string_is_equal(ext_lower, "ogg"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_OGG;
|
mixer->type = AUDIO_MIXER_TYPE_OGG;
|
||||||
nbio->type = NBIO_TYPE_OGG;
|
nbio->type = NBIO_TYPE_OGG;
|
||||||
t->callback = task_audio_mixer_handle_upload_ogg;
|
t->callback = task_audio_mixer_handle_upload_ogg;
|
||||||
}
|
}
|
||||||
else if (string_ends_with(fullpath, ".mp3"))
|
else if (string_is_equal(ext_lower, "mp3"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_MP3;
|
mixer->type = AUDIO_MIXER_TYPE_MP3;
|
||||||
nbio->type = NBIO_TYPE_MP3;
|
nbio->type = NBIO_TYPE_MP3;
|
||||||
t->callback = task_audio_mixer_handle_upload_mp3;
|
t->callback = task_audio_mixer_handle_upload_mp3;
|
||||||
}
|
}
|
||||||
else if (string_ends_with(fullpath, ".flac"))
|
else if (string_is_equal(ext_lower, "flac"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_FLAC;
|
mixer->type = AUDIO_MIXER_TYPE_FLAC;
|
||||||
nbio->type = NBIO_TYPE_FLAC;
|
nbio->type = NBIO_TYPE_FLAC;
|
||||||
t->callback = task_audio_mixer_handle_upload_flac;
|
t->callback = task_audio_mixer_handle_upload_flac;
|
||||||
}
|
}
|
||||||
else if (
|
else if (
|
||||||
string_ends_with(fullpath, ".mod") ||
|
string_is_equal(ext_lower, "mod") ||
|
||||||
string_ends_with(fullpath, ".s3m") ||
|
string_is_equal(ext_lower, "s3m") ||
|
||||||
string_ends_with(fullpath, ".xm"))
|
string_is_equal(ext_lower, "xm"))
|
||||||
{
|
{
|
||||||
mixer->type = AUDIO_MIXER_TYPE_MOD;
|
mixer->type = AUDIO_MIXER_TYPE_MOD;
|
||||||
nbio->type = NBIO_TYPE_MOD;
|
nbio->type = NBIO_TYPE_MOD;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user