Bladeren bron

added support for multiple file uploads

dds
Matt Bradshaw 6 jaren geleden
bovenliggende
commit
4fcb6c2923
2 gewijzigde bestanden met toevoegingen van 17 en 9 verwijderingen
  1. +2
    -2
      extras/wav2sketch/wav2sketch.html
  2. +15
    -7
      extras/wav2sketch/wav2sketch.js

+ 2
- 2
extras/wav2sketch/wav2sketch.html Bestand weergeven

@@ -6,9 +6,9 @@
<h1>Teensy Audio Wav2Sketch Utility</h1>
<p>Upload an audio file to convert it into Teensy audio format.</p>
<form>
<input id="audioFileChooser" name="audioFileChooser" type="file" accept="audio/*">
<input id="audioFileChooser" name="audioFileChooser" type="file" accept="audio/*" multiple>
<div id="outputFileHolder"></div>
</form>
<script type="text/javascript" src="wav2sketch.js"></script>
</body>
</html>
</html>

+ 15
- 7
extras/wav2sketch/wav2sketch.js Bestand weergeven

@@ -1,15 +1,22 @@
/*
TODO
multiple files
stereo
non-44100 sample rates
*/

var audioFileChooser = document.getElementById('audioFileChooser');

audioFileChooser.addEventListener('change', readFile);

function readFile() {
// TODO: deal with multiple files
var fileReader = new FileReader();
fileReader.readAsArrayBuffer(audioFileChooser.files[0]);
window.testFile = audioFileChooser;
fileReader.addEventListener('load', function(ev) {
processFile(ev.target.result, audioFileChooser.files[0].name);
});
for(var i = 0; i < audioFileChooser.files.length; i++) {
var fileReader = new FileReader();
fileReader.readAsArrayBuffer(audioFileChooser.files[i]);
fileReader.addEventListener('load', function(fileName, ev) {
processFile(ev.target.result, fileName);
}.bind(null, audioFileChooser.files[i].name));
}
}

function processFile(file, fileName) {
@@ -50,6 +57,7 @@ function processFile(file, fileName) {
outputFileHolder.appendChild(downloadLink1);
outputFileHolder.appendChild(document.createElement('br'));
outputFileHolder.appendChild(downloadLink2);
outputFileHolder.appendChild(document.createElement('br'));
});
}


Laden…
Annuleren
Opslaan