Browse Source

loading files and playing them using web audio api

dds
Matt Bradshaw 6 years ago
parent
commit
1bec7b51c3
3 changed files with 29 additions and 1 deletions
  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 View File

AudioSampleKick.cpp
AudioSampleKick.h

+ 4
- 0
extras/wav2sketch/wav2sketch.html View File

</head> </head>
<body> <body>
<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>
<form>
<input id="audioFileChooser" name="audioFileChooser" type="file" accept="audio/*">
</form>
<script type="text/javascript" src="wav2sketch.js"></script> <script type="text/javascript" src="wav2sketch.js"></script>
</body> </body>
</html> </html>

+ 23
- 1
extras/wav2sketch/wav2sketch.js View File

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);
});
}

Loading…
Cancel
Save