what is the format of this .wav file?

Viewed 26

.wav file in question
i got it from here, the upright piano best quality wav sound bank

i made this script to load it into to a FileReader:

const file = document.getElementById("file");
const fr = new FileReader();
file.onchange = function(e) {
    fr.readAsArrayBuffer(file.files[0]);
}
fr.onload = function() {
    const bytes = new Uint8Array(fr.result);
    function byteString(a, b) {
        let c = "";
        for(let i = b; i >= a; i -= 1) {
            const byte = bytes[i].toString(2), shift = new Array(8 - byte.length + 1).join("0");
            c += shift + byte;
        }
        return parseInt(c, 2);
    }
    const channels = byteString(22, 23);
    const sampleRate = byteString(24, 27);
    const bitsPerSample = byteString(34, 35);
    const length = byteString(40, 43);
    // console.log(bytes); // running this line with that file on stackoverflow crashed my browser
    console.log(channels, sampleRate, bitsPerSample, length);
}
<!DOCTYPE html>
<html oncontextmenu="return false">
    <head>
        <meta charset="utf-8">
        <title>visualizer</title>
    </head>
    <body>
        <label for="wav">wav file: </label>
        <input type="file" id="file" name="wav">
    </body>
</html>
it logs accurate data for other .wav files but is only correct on channels and sampleRate for this
it seems this file doesn't follow the specification, but audio software and stuff are still able to play it

how do i find the bits per sample and the number of bytes in the signal data?
also, how do i find the signal data? i want to make a waveform visualizer

0 Answers
Related