Skip to content
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

rem/aufile: fix aufile_get_length calculations #1008

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rem_aufile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ int aufile_open(struct aufile **afp, struct aufile_prm *prm,
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_get_length(struct aufile *af, const struct aufile_prm *prm);
int aufile_set_position(struct aufile *af, const struct aufile_prm *prm,
size_t pos_ms);
20 changes: 10 additions & 10 deletions rem/aufile/aufile.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,26 +252,26 @@ size_t aufile_get_size(struct aufile *af)
*
* @return length in ms if success, otherwise 0.
*/
size_t aufile_get_length(struct aufile *af, struct aufile_prm *prm)
size_t aufile_get_length(struct aufile *af, const struct aufile_prm *prm)
{
if (!af)
if (!af || !prm)
return 0;

switch (prm->fmt) {
case AUFMT_PCMA:
case AUFMT_PCMU:
return af->datasize * prm->channels * prm->srate
/ 1000;
return af->datasize / prm->channels * 1000
/ prm->srate;
Copy link
Collaborator

@cspiel1 cspiel1 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe readable better and only one division:

return af->datasize * 1000 / (prm->channels * prm->srate);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also take the WAV header size into account?
See function aufile_set_position()!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

af->datasize is already the size of the data chunk without the header

case AUFMT_S16LE:
return af->datasize * 2 * prm->channels * prm->srate
/ 1000;
return af->datasize / 2 / prm->channels * 1000
/ prm->srate;
case AUFMT_S24_3LE:
return af->datasize * 3 * prm->channels * prm->srate
/ 1000;
return af->datasize / 3 / prm->channels * 1000
/ prm->srate;
case AUFMT_S32LE:
case AUFMT_FLOAT:
return af->datasize * 4 * prm->channels * prm->srate
/ 1000;
return af->datasize / 4 / prm->channels * 1000
/ prm->srate;
default:
return 0;
}
Expand Down
Loading