Skip to content

Commit

Permalink
Improve sound duration calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
rickgaiser authored and KrahJohlito committed Jul 5, 2020
1 parent 8b252bf commit 2f5030d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ static int sfxLoad(struct sfxEffect *sfxData, audsrv_adpcm_t *sfx)
{
int ret;

sfxData->duration_ms = sfxCalculateSoundDuration(sfxData->size);
// Calculate duration based on decompressed size
sfxData->duration_ms = sfxCalculateSoundDuration(((u32 *)sfxData->buffer)[3]);
// Estimate duration based on filesize, is the ADPCM header was 0
if (sfxData->duration_ms == 0)
sfxData->duration_ms = sfxData->size / 47;

ret = audsrv_load_adpcm(sfx, sfxData->buffer, sfxData->size);
if (sfxData->builtin == 0) {
free(sfxData->buffer);
Expand Down

0 comments on commit 2f5030d

Please sign in to comment.