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

Sample scaling is incorrect #3

Open
Barabas5532 opened this issue Apr 11, 2021 · 1 comment
Open

Sample scaling is incorrect #3

Barabas5532 opened this issue Apr 11, 2021 · 1 comment

Comments

@Barabas5532
Copy link

The code for unsigned to signed integer conversion is incorrect.

Paste this into console, and the result is wrong.

function scale(value, bitDepth)
{
    var range = 1 << bitDepth - 1;
    if (value >= range) {
        value |= ~(range - 1);
    }
    return value;
}

[0, 1, 2, 3].forEach(function(n) {console.log(n + ", " + scale(n, 2))})
Output:
0, 0
1, 1
2, -2
3, -1

Moreover, according to stack overflow, greater than 8 bits per sample is already signed, so there is no need to do this conversion.

@Barabas5532
Copy link
Author

Hmm, it seems this actually does sign extension on the data, so only the comment is wrong. 8-bits per sample (always unsigned) will be broken after sign extension though.

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

1 participant