Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reader.on('end', function(){
- raw = Buffer.concat(raw) // concat all buffers into one
- data = [] // this will hold the processed data
- for (var i=0; i < raw.length; i += format.blockAlign){
- str = ""
- // Note that here I am taking only the first channel
- for(var j=0; j<format.blockAlign/format.channels; j++)
- if(format.endianness == "LE") //decide how to combine using endianess
- str = raw[i+j].toString(16) + str
- else
- str += raw[i+j].toString(16)
- data.push(hexToInt(str))
- }
- /*
- Now do whatever you want with "data"
- */
- });
- // This function handles negative numbers as well
- function hexToInt (hex) {
- if (hex.length % 2 != 0) {
- hex = "0" + hex;
- }
- var num = parseInt(hex, 16);
- var maxVal = Math.pow(2, hex.length / 2 * 8);
- if (num > maxVal / 2 - 1) {
- num = num - maxVal
- }
- return num;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement