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

Implement aufile_set_position #943

Merged
merged 10 commits into from
Sep 17, 2023

Conversation

larsimmisch
Copy link
Contributor

This PR implements aufile_set_position, which sets the position in milliseconds.

*
* @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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Normally in re all functions except getter return an error code if there are errors possible.

API functions should contain NULL pointer checks.

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

*/
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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only an approximation, right? Is it a good approximation for all WAV files?

Shouldn't the WAV header size be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks & yes. The wav header needs to be taken into account.

@sreimers sreimers added this to the v3.6.0 milestone Sep 6, 2023
return EINVAL;
}

// Seek to the beginning of the file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be removed. It's obvious.

return errno;
}
// this is only used for the side effect of moving the file ptr to the
// first data block.
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Use C comments!
  • Please shorter: `/* skip wav header */

*
* @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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • return int as error code
  • correct @return doxygen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

int instead of size_t

*
* @return 0 if success, otherwise errorcode
*/
int aufile_set_position(struct aufile *af, struct aufile_prm *prm,
Copy link
Contributor

Choose a reason for hiding this comment

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

is prm modified by the function ? can it be const ?


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

Choose a reason for hiding this comment

The 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

struct wav_fmt fmt;
int err;
off_t pos;
size_t datasize;
Copy link
Contributor

Choose a reason for hiding this comment

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

please use C99 style declare+assign if possible ...

@@ -26,3 +26,5 @@ 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);
int aufile_set_position(struct aufile *af, struct aufile_prm *prm,
off_t pos_ms);
Copy link
Contributor

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 of off_t here ...

Copy link
Contributor Author

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 using size_t breaks the Windows build.

@alfredh
Copy link
Contributor

alfredh commented Sep 13, 2023

my idea was to use size_t in the api and off_t in the implementation.

@larsimmisch
Copy link
Contributor Author

Done. The cast to off_t was in the implementation anyway.

@alfredh
Copy link
Contributor

alfredh commented Sep 13, 2023

LGTM

@alfredh alfredh merged commit e60207a into baresip:main Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants