mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 12:32:34 +00:00
- added loop tag reading for Ogg and Flac sound effects. Due to lack of test material this is currently untested.
- removed unaligned memory access in FindLoopTags.
This commit is contained in:
parent
1852079142
commit
b3f3500ce5
2 changed files with 27 additions and 4 deletions
|
@ -120,15 +120,15 @@ void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end
|
|||
continue;
|
||||
}
|
||||
c -= 3;
|
||||
int len = LittleLong(*(int*)c);
|
||||
if (len > 1000000 || len <= (eqp - c + 1))
|
||||
int len = c[0] + 256*c[1] + 65536*c[2];
|
||||
if (c[3] || len > 1000000 || len <= (eqp - c + 1))
|
||||
{
|
||||
// length looks fishy so retry with the next '='
|
||||
continue;
|
||||
}
|
||||
c -= 4;
|
||||
count = LittleLong(*(int*)c);
|
||||
if (count <= 0 || count > 1000)
|
||||
count = c[0] + 256 * c[1];
|
||||
if (c[2] || c[3] || count <= 0 || count > 1000)
|
||||
{
|
||||
// very unlikely to have 1000 tags
|
||||
continue;
|
||||
|
|
|
@ -1195,6 +1195,8 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata,
|
|||
return std::make_pair(retval, channels==1);
|
||||
}
|
||||
|
||||
void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass);
|
||||
|
||||
std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, bool monoize)
|
||||
{
|
||||
SoundHandle retval = { NULL };
|
||||
|
@ -1203,6 +1205,14 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
|
|||
ChannelConfig chans;
|
||||
SampleType type;
|
||||
int srate;
|
||||
uint32_t loop_start = 0, loop_end = ~0u;
|
||||
bool startass = false, endass = false;
|
||||
|
||||
if (!memcmp(sfxdata, "OggS", 4) || !memcmp(sfxdata, "FLAC", 4))
|
||||
{
|
||||
MemoryReader mr((char*)sfxdata, length);
|
||||
FindLoopTags(&mr, &loop_start, &startass, &loop_end, &endass);
|
||||
}
|
||||
|
||||
std::unique_ptr<SoundDecoder> decoder(CreateDecoder(&reader));
|
||||
if(!decoder) return std::make_pair(retval, true);
|
||||
|
@ -1269,6 +1279,19 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
|
|||
return std::make_pair(retval, true);
|
||||
}
|
||||
|
||||
if (!startass) loop_start = Scale(loop_start, srate, 1000);
|
||||
if (!endass) loop_end = Scale(loop_end, srate, 1000);
|
||||
if (loop_start < 0) loop_start = 0;
|
||||
|
||||
if ((loop_start > 0 || loop_end > 0) && loop_end > loop_start && AL.SOFT_loop_points)
|
||||
{
|
||||
ALint loops[2] = { loop_start, loop_end };
|
||||
DPrintf(DMSG_NOTIFY, "Setting loop points %d -> %d\n", loops[0], loops[1]);
|
||||
alBufferiv(buffer, AL_LOOP_POINTS_SOFT, loops);
|
||||
getALError();
|
||||
}
|
||||
|
||||
|
||||
retval.data = MAKE_PTRID(buffer);
|
||||
return std::make_pair(retval, (chans == ChannelConfig_Mono || monoize));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue