Skip to content

Commit

Permalink
Implement aufile_set_position
Browse files Browse the repository at this point in the history
  • Loading branch information
larsimmisch committed Sep 5, 2023
1 parent 84208bc commit 6f203df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/rem_aufile.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ int aufile_read(struct aufile *af, uint8_t *p, size_t *sz);
int aufile_write(struct aufile *af, const uint8_t *p, size_t sz);
size_t aufile_get_size(struct aufile *af);
size_t aufile_get_length(struct aufile *af, struct aufile_prm *prm);
size_t aufile_set_position(struct aufile *af, struct aufile_prm *prm, size_t pos_ms);
15 changes: 15 additions & 0 deletions rem/aufile/aufile.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,18 @@ size_t aufile_get_length(struct aufile *af, struct aufile_prm *prm)

return 0;
}

/**
* Set initial playing position of a WAV file in ms
*
* @param af Audio-file
* @param prm Audio file parameters from aufile_open
*
* @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 pos = prm->srate * aufmt_sample_size(prm->fmt) * prm->channels * pos_ms / 1000;

return fseek(af->f, pos, SEEK_SET);
}

0 comments on commit 6f203df

Please sign in to comment.