-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement aufile_set_position #943
Changes from 7 commits
6f203df
f33ca06
7222970
1d6ac3c
4fc79d0
10b23f6
afb618d
790d9d3
96c2156
41eb5c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,3 +278,43 @@ 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 0 if success, otherwise errorcode | ||
*/ | ||
size_t aufile_set_position(struct aufile *af, struct aufile_prm *prm, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
off_t pos_ms) | ||
{ | ||
struct wav_fmt fmt; | ||
int err; | ||
off_t pos; | ||
size_t datasize; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use C99 style declare+assign if possible ... |
||
|
||
if (!af || !prm) { | ||
return EINVAL; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove curly braces that is not needed here ... same for the rest of the function |
||
|
||
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, &datasize, af->f); | ||
if (err) { | ||
return err; | ||
} | ||
|
||
pos = (off_t)(prm->srate * aufmt_sample_size(prm->fmt) | ||
* prm->channels * pos_ms / 1000); | ||
|
||
if (fseek(af->f, pos, SEEK_CUR) < 0) { | ||
return errno; | ||
} | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is probably better to use
size_t
instead ofoff_t
here ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that first, but it's
fseek(FILE *, long, int);
and usingsize_t
breaks the Windows build.