Pārlūkot izejas kodu

loading files and playing them using web audio api

dds
Matt Bradshaw pirms 6 gadiem
vecāks
revīzija
1bec7b51c3
3 mainītis faili ar 29 papildinājumiem un 1 dzēšanām
  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 Parādīt failu

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

+ 4
- 0
extras/wav2sketch/wav2sketch.html Parādīt failu

@@ -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 Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt