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

Why doesn't convertPcm16ToFloat do source[i] / 32768.0f? #21

Closed
dturner opened this issue Dec 8, 2017 · 2 comments
Closed

Why doesn't convertPcm16ToFloat do source[i] / 32768.0f? #21

dturner opened this issue Dec 8, 2017 · 2 comments
Assignees

Comments

@dturner
Copy link
Collaborator

dturner commented Dec 8, 2017

This line of code (from https://github.com/google/oboe/blob/master/src/common/Utilities.cpp#L43)

destination[i] = source[i] * (1.0f / 32768.0f);

Why not just use:

source[i] / 32768.0f

@dturner
Copy link
Collaborator Author

dturner commented Dec 8, 2017

Originally asked by mnaganov

@philburk
Copy link
Collaborator

A multiply is generally much faster than a divide.
Some compilers will pre-calculate the 1/x at compile time and then compile a multiply for the first line. But they will compile a divide for the second line.

It might look better to define a const float kScaleI16ToFloat = (1.0f/32768.0f)
and then dest = source * kScaleI16ToFloat;

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

No branches or pull requests

2 participants