Browse Source

added support for multiple file uploads

dds
Matt Bradshaw 6 years ago
parent
commit
4fcb6c2923
2 changed files with 17 additions and 9 deletions
  1. +2
    -2
      extras/wav2sketch/wav2sketch.html
  2. +15
    -7
      extras/wav2sketch/wav2sketch.js

+ 2
- 2
extras/wav2sketch/wav2sketch.html View File

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

+ 15
- 7
extras/wav2sketch/wav2sketch.js View File

/*
TODO
multiple files
stereo
non-44100 sample rates
*/

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


audioFileChooser.addEventListener('change', readFile); audioFileChooser.addEventListener('change', readFile);


function 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) { function processFile(file, fileName) {
outputFileHolder.appendChild(downloadLink1); outputFileHolder.appendChild(downloadLink1);
outputFileHolder.appendChild(document.createElement('br')); outputFileHolder.appendChild(document.createElement('br'));
outputFileHolder.appendChild(downloadLink2); outputFileHolder.appendChild(downloadLink2);
outputFileHolder.appendChild(document.createElement('br'));
}); });
} }



Loading…
Cancel
Save