Unverified Commit edf4096e authored by Jake Stine's avatar Jake Stine Committed by GitHub
Browse files

audio: avoid redundant calls to fseek (#185)

The overhead of fseek internally is unchecked and non-trivial.
parent 92d94da8
......@@ -244,6 +244,15 @@ bool decWav_seek(dec_WavData *data, intmax_t samplepos)
}
intmax_t bytepos = samplepos * bps;
// spurious calls to fseek have overhead, so early out if the internal managed
// seek pos matches
if (data->pos == bytepos)
{
assert(ftell(data->fp) == WAV_HEADER_SIZE + bytepos);
return 1;
}
if (fseek(data->fp, WAV_HEADER_SIZE + bytepos, SEEK_SET))
{
// logging here could be unnecessarily spammy. If we add a log it should be gated by
......@@ -251,7 +260,7 @@ bool decWav_seek(dec_WavData *data, intmax_t samplepos)
//fprintf(stderr, "WAV decoder seek failed: %s\n", strerror(errno));
return 0;
}
data->pos = samplepos * bps;
data->pos = bytepos;
return 1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment