Explorar el Código

added stereo support (well, still mono output but accepts stereo files)

dds
Matt Bradshaw hace 6 años
padre
commit
adc533f9ca
Se han modificado 2 ficheros con 13 adiciones y 9 borrados
  1. +0
    -6
      extras/wav2sketch/.gitignore
  2. +13
    -3
      extras/wav2sketch/wav2sketch.js

+ 0
- 6
extras/wav2sketch/.gitignore Ver fichero

@@ -1,6 +0,0 @@
AudioSampleKickULAW.cpp
AudioSampleKickULAW.h
AudioSampleKickPCM.cpp
AudioSampleKickPCM.h
AudioSampleKick.cpp
AudioSampleKick.h

+ 13
- 3
extras/wav2sketch/wav2sketch.js Ver fichero

@@ -1,8 +1,7 @@
/*
TODO
multiple files
stereo
non-44100 sample rates
u-law encoding
*/

var audioFileChooser = document.getElementById('audioFileChooser');
@@ -22,7 +21,18 @@ function readFile() {
function processFile(file, fileName) {
var context = new OfflineAudioContext(1,10*44100,44100);
context.decodeAudioData(file, function(buffer) {
var monoData = buffer.getChannelData(0); // start with mono, do stereo later
var monoData = [];
if(buffer.numberOfChannels == 1) {
monoData = buffer.getChannelData(1);
} else if(buffer.numberOfChannels == 2) {
var leftData = buffer.getChannelData(0);
var rightData = buffer.getChannelData(1);
for(var i=0;i<buffer.length;i++) {
monoData[i] = (leftData[i] + rightData[i]) / 2;
}
} else {
alert("ONLY MONO AND STEREO FILES ARE SUPPORTED");
}
var outputData = [];
for(var i=0;i<monoData.length;i+=2) {
var a = floatToUnsignedInt16(monoData[i]);

Cargando…
Cancelar
Guardar