javascript - Convert int16 array to float -


i have array of bytes audio file , want convert data can process filter audio signal. have array this: [239,246,96,247.....]; each element uint8 byte

each 2 bytes(16 bits) represent sample,so converted array int16 element array.

how can convert array signal values in range[-1,1]?

you have signed int16's have divide min , max int16 value respective sign.

let buffer = new int16array([0x0001, 0x7fff, 0x000, 0xffff, 0x8000]); // [1, 32767, 0, -1, -32768] let result = new float32array(buffer.length); for(let i=0; i<buffer.length; i++) result[i] = buffer[i] / (buffer[i] >= 0 ? 32767 : 32768); console.log(result[0], result[1], result[2], result[3], result[4]); // 0.000030518509447574615 1 0 -0.000030517578125 -1 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -