Skip to content

Sample scaling is incorrect #3

@Barabas5532

Description

@Barabas5532

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions