Ver código fonte

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

dds
Matt Bradshaw 6 anos atrás
pai
commit
adc533f9ca
2 arquivos alterados com 13 adições e 9 exclusões
  1. +0
    -6
      extras/wav2sketch/.gitignore
  2. +13
    -3
      extras/wav2sketch/wav2sketch.js

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

AudioSampleKickULAW.cpp
AudioSampleKickULAW.h
AudioSampleKickPCM.cpp
AudioSampleKickPCM.h
AudioSampleKick.cpp
AudioSampleKick.h

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

/* /*
TODO TODO
multiple files
stereo
non-44100 sample rates non-44100 sample rates
u-law encoding
*/ */


var audioFileChooser = document.getElementById('audioFileChooser'); var audioFileChooser = document.getElementById('audioFileChooser');
function processFile(file, fileName) { function processFile(file, fileName) {
var context = new OfflineAudioContext(1,10*44100,44100); var context = new OfflineAudioContext(1,10*44100,44100);
context.decodeAudioData(file, function(buffer) { 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 = []; var outputData = [];
for(var i=0;i<monoData.length;i+=2) { for(var i=0;i<monoData.length;i+=2) {
var a = floatToUnsignedInt16(monoData[i]); var a = floatToUnsignedInt16(monoData[i]);

Carregando…
Cancelar
Salvar