Ver código fonte

loading files and playing them using web audio api

dds
Matt Bradshaw 6 anos atrás
pai
commit
1bec7b51c3
3 arquivos alterados com 29 adições e 1 exclusões
  1. +2
    -0
      extras/wav2sketch/.gitignore
  2. +4
    -0
      extras/wav2sketch/wav2sketch.html
  3. +23
    -1
      extras/wav2sketch/wav2sketch.js

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

@@ -0,0 +1,2 @@
AudioSampleKick.cpp
AudioSampleKick.h

+ 4
- 0
extras/wav2sketch/wav2sketch.html Ver arquivo

@@ -4,6 +4,10 @@
</head>
<body>
<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/*">
</form>
<script type="text/javascript" src="wav2sketch.js"></script>
</body>
</html>

+ 23
- 1
extras/wav2sketch/wav2sketch.js Ver arquivo

@@ -1 +1,23 @@
alert("Hello!");
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]);
fileReader.addEventListener('load', function(ev) {
processFile(ev.target.result);
});
}

function processFile(file) {
var context = new window.AudioContext();
context.decodeAudioData(file, function(buffer) {
var source = context.createBufferSource();
source.buffer = buffer;
source.loop = false;
source.connect(context.destination);
source.start(0);
});
}

Carregando…
Cancelar
Salvar