Browse Source

added u-law encoding but needs to be properly implemented

dds
Matt Bradshaw 6 years ago
parent
commit
893392bd7f
2 changed files with 33 additions and 1 deletions
  1. +0
    -1
      extras/wav2sketch/wav2sketch.c
  2. +33
    -0
      extras/wav2sketch/wav2sketch.js

+ 0
- 1
extras/wav2sketch/wav2sketch.c View File

fprintf(stderr, "\n"); fprintf(stderr, "\n");
exit(1); exit(1);
} }


+ 33
- 0
extras/wav2sketch/wav2sketch.js View File

sampleRateCode = '3'; sampleRateCode = '3';
} }


var ulawOut = [];
for(var i = 0; i < monoData.length; i ++) {
ulawOut.push(ulaw_encode(toInteger(monoData[i]*0x7fff)).toString(16));
}
window.ulawOut = ulawOut;
var outputData = createWords(monoData, padLength); var outputData = createWords(monoData, padLength);


var statusInt = (monoData.length).toString(16); var statusInt = (monoData.length).toString(16);
}); });
} }


function ulaw_encode(audio)
{
var mag, neg; // both uint32

// http://en.wikipedia.org/wiki/G.711
if (audio >= 0) {
mag = audio;
neg = 0;
} else {
mag = audio * -1;
neg = 0x80;
}
mag += 128;
if (mag > 0x7FFF) mag = 0x7FFF;
if (mag >= 0x4000) return neg | 0x70 | ((mag >> 10) & 0x0F); // 01wx yz00 0000 0000
if (mag >= 0x2000) return neg | 0x60 | ((mag >> 9) & 0x0F); // 001w xyz0 0000 0000
if (mag >= 0x1000) return neg | 0x50 | ((mag >> 8) & 0x0F); // 0001 wxyz 0000 0000
if (mag >= 0x0800) return neg | 0x40 | ((mag >> 7) & 0x0F); // 0000 1wxy z000 0000
if (mag >= 0x0400) return neg | 0x30 | ((mag >> 6) & 0x0F); // 0000 01wx yz00 0000
if (mag >= 0x0200) return neg | 0x20 | ((mag >> 5) & 0x0F); // 0000 001w xyz0 0000
if (mag >= 0x0100) return neg | 0x10 | ((mag >> 4) & 0x0F); // 0000 0001 wxyz 0000
return neg | 0x00 | ((mag >> 3) & 0x0F); // 0000 0000 1wxy z000
}

function createWords(audioData, padLength) { function createWords(audioData, padLength) {
var totalLength = audioData.length + padLength; var totalLength = audioData.length + padLength;
var outputData = []; var outputData = [];
return modulo(toInteger(x), Math.pow(2, 16)); return modulo(toInteger(x), Math.pow(2, 16));
} }


function toUint8(x) {
return modulo(toInteger(x), Math.pow(2, 8));
}

// compute the extra padding needed // compute the extra padding needed
function padding(sampleLength, block) { function padding(sampleLength, block) {
var extra = sampleLength % block; var extra = sampleLength % block;

Loading…
Cancel
Save