AudioLib: Fix improper matching of loop tags with initial substrings of them, and add proper support for LOOP as a synonym of LOOP_START.

git-svn-id: https://svn.eduke32.com/eduke32@5899 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2016-10-14 07:40:59 +00:00
parent 8169365820
commit c9de8faefb
4 changed files with 32 additions and 18 deletions

View file

@ -194,7 +194,7 @@ extern const int16_t *MV_RightVolume;
extern int32_t MV_SampleSize; extern int32_t MV_SampleSize;
extern int32_t MV_RightChannelOffset; extern int32_t MV_RightChannelOffset;
#define loopStartTagCount 2 #define loopStartTagCount 3
extern const char *loopStartTags[loopStartTagCount]; extern const char *loopStartTags[loopStartTagCount];
#define loopEndTagCount 2 #define loopEndTagCount 2
extern const char *loopEndTags[loopEndTagCount]; extern const char *loopEndTags[loopEndTagCount];

View file

@ -553,7 +553,6 @@ int32_t MV_PlayFLAC(char *ptr, uint32_t ptrlength, int32_t loopstart, int32_t lo
if (tags->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) if (tags->type == FLAC__METADATA_TYPE_VORBIS_COMMENT)
{ {
FLAC__uint32 comment; FLAC__uint32 comment;
uint8_t loopTagCount;
for (comment = 0; comment < tags->data.vorbis_comment.num_comments; ++comment) for (comment = 0; comment < tags->data.vorbis_comment.num_comments; ++comment)
{ {
const char *entry = (const char *)tags->data.vorbis_comment.comments[comment].entry; const char *entry = (const char *)tags->data.vorbis_comment.comments[comment].entry;
@ -563,23 +562,29 @@ int32_t MV_PlayFLAC(char *ptr, uint32_t ptrlength, int32_t loopstart, int32_t lo
const size_t field = value - entry; const size_t field = value - entry;
value += 1; value += 1;
for (loopTagCount = 0; loopTagCount < loopStartTagCount && vc_loopstart == NULL; for (size_t t = 0; t < loopStartTagCount && vc_loopstart == NULL; ++t)
++loopTagCount) {
if (strncasecmp(entry, loopStartTags[loopTagCount], field) == 0) char const * const tag = loopStartTags[t];
if (field == strlen(tag) && strncasecmp(entry, tag, field) == 0)
vc_loopstart = strdup(value); vc_loopstart = strdup(value);
}
for (loopTagCount = 0; loopTagCount < loopEndTagCount && vc_loopend == NULL; for (size_t t = 0; t < loopEndTagCount && vc_loopend == NULL; ++t)
++loopTagCount) {
if (strncasecmp(entry, loopEndTags[loopTagCount], field) == 0) char const * const tag = loopEndTags[t];
if (field == strlen(tag) && strncasecmp(entry, tag, field) == 0)
vc_loopend = strdup(value); vc_loopend = strdup(value);
}
for (loopTagCount = 0; loopTagCount < loopLengthTagCount && vc_looplength == NULL; for (size_t t = 0; t < loopLengthTagCount && vc_looplength == NULL; ++t)
++loopTagCount) {
if (strncasecmp(entry, loopLengthTags[loopTagCount], field) == 0) char const * const tag = loopLengthTags[t];
if (field == strlen(tag) && strncasecmp(entry, tag, field) == 0)
vc_looplength = strdup(value); vc_looplength = strdup(value);
} }
} }
} }
}
FLAC__metadata_object_delete( FLAC__metadata_object_delete(
tags); // If it were not for this, I would assign pointers instead of strdup(). tags); // If it were not for this, I would assign pointers instead of strdup().

View file

@ -1014,6 +1014,6 @@ int32_t MV_Shutdown(void)
void MV_SetPrintf(void (*function)(const char *, ...)) { MV_Printf = function; } void MV_SetPrintf(void (*function)(const char *, ...)) { MV_Printf = function; }
const char *loopStartTags[loopStartTagCount] = { "LOOP_START", "LOOPSTART" }; const char *loopStartTags[loopStartTagCount] = { "LOOP_START", "LOOPSTART", "LOOP" };
const char *loopEndTags[loopEndTagCount] = { "LOOP_END", "LOOPEND" }; const char *loopEndTags[loopEndTagCount] = { "LOOP_END", "LOOPEND" };
const char *loopLengthTags[loopLengthTagCount] = { "LOOP_LENGTH", "LOOPLENGTH" }; const char *loopLengthTags[loopLengthTagCount] = { "LOOP_LENGTH", "LOOPLENGTH" };

View file

@ -83,19 +83,28 @@ static void MV_GetVorbisCommentLoops(VoiceNode *voice, vorbis_comment *vc)
const size_t field = value - entry; const size_t field = value - entry;
value += 1; value += 1;
for (uint8_t loopTagCount = 0; loopTagCount < loopStartTagCount && vc_loopstart == NULL; ++loopTagCount) for (size_t t = 0; t < loopStartTagCount && vc_loopstart == NULL; ++t)
if (strncasecmp(entry, loopStartTags[loopTagCount], field) == 0) {
char const * const tag = loopStartTags[t];
if (field == strlen(tag) && strncasecmp(entry, tag, field) == 0)
vc_loopstart = value; vc_loopstart = value;
}
for (uint8_t loopTagCount = 0; loopTagCount < loopEndTagCount && vc_loopend == NULL; ++loopTagCount) for (size_t t = 0; t < loopEndTagCount && vc_loopend == NULL; ++t)
if (strncasecmp(entry, loopEndTags[loopTagCount], field) == 0) {
char const * const tag = loopEndTags[t];
if (field == strlen(tag) && strncasecmp(entry, tag, field) == 0)
vc_loopend = value; vc_loopend = value;
}
for (uint8_t loopTagCount = 0; loopTagCount < loopLengthTagCount && vc_looplength == NULL; ++loopTagCount) for (size_t t = 0; t < loopLengthTagCount && vc_looplength == NULL; ++t)
if (strncasecmp(entry, loopLengthTags[loopTagCount], field) == 0) {
char const * const tag = loopLengthTags[t];
if (field == strlen(tag) && strncasecmp(entry, tag, field) == 0)
vc_looplength = value; vc_looplength = value;
} }
} }
}
if (vc_loopstart != NULL) if (vc_loopstart != NULL)
{ {