8000 Potential underflow / overflow when converting from float to int16 · Issue #209 · xiph/rnnoise · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Potential underflow / overflow when converting from float to int16 #209

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

Open
Meoo opened this issue Aug 10, 2022 · 2 comments
Open

Potential underflow / overflow when converting from float to int16 #209

Meoo opened this issue Aug 10, 2022 · 2 comments

Comments

@Meoo
Copy link
Meoo commented Aug 10, 2022

In the example code "rnnoise_demo", the float output is converted to a short with a simple cast

I found by experimentation that the output can be outside of int16 range, so the output should be clamped to prevent clicky noises when the input has values near the int16's min or max

@lufengjie051523
Copy link

Hi,did you solved the problem?

@lguarda
Copy link
lguarda commented May 1, 2025

Hello indeed clicky noise seems to be prevented by using something like this

void conversion(int16_t *data, float *buffer) {
    for(int j = 0; j < 480; j++) {

        if (buffer[j] > INT16_MAX) {
            data[j] = INT16_MAX;

        } else if (buffer[j] < INT16_MIN) {
            data[j] = INT16_MIN;

        } else {
            data[j] = buffer[j];
        }
    }
}

But i'm afraid that it's could prevent some compiler optimization,
(Actually using compiler explorer it seems that there's still some intrinsic instruction used so it should be fine)
It still doesn't seems right to do
if someone have a better solution, it could be nice (also i'm not even sure this is always the best thing to do for any cases)

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

3 participants
0