Skip to content

Commit

Permalink
Take wav header into account, thanks @cspiel1
Browse files Browse the repository at this point in the history
Also observe max column length of 80.
  • Loading branch information
larsimmisch committed Sep 6, 2023
1 parent 6f203df commit f33ca06
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions rem/aufile/aufile.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,34 @@ size_t aufile_get_length(struct aufile *af, struct aufile_prm *prm)
*
* @return position in bytes or (size_t)-1 in case of an error.
*/
size_t aufile_set_position(struct aufile *af, struct aufile_prm *prm, size_t pos_ms)
size_t aufile_set_position(struct aufile *af, struct aufile_prm *prm,
size_t pos_ms)
{
size_t pos = prm->srate * aufmt_sample_size(prm->fmt) * prm->channels * pos_ms / 1000;
struct wav_fmt fmt;
int err;
size_t pos;

if (!af || !prm) {
return EINVAL;
}

// Seek to the beginning of the file
if (fseek(af->f, 0, SEEK_SET) < 0) {
return errno;
}
// this is only used for the side effect of moving the file ptr to the
// first data block.
err = wav_header_decode(&fmt, &pos, af->f);
if (err) {
return err;
}

return fseek(af->f, pos, SEEK_SET);
pos = prm->srate * aufmt_sample_size(prm->fmt)
* prm->channels * pos_ms / 1000;

if (fseek(af->f, pos, SEEK_CUR) < 0) {
return errno;
}

return 0;
}

0 comments on commit f33ca06

Please sign in to comment.