浏览代码

loading files and playing them using web audio api

dds
Matt Bradshaw 6 年前
父节点
当前提交
1bec7b51c3
共有 3 个文件被更改,包括 29 次插入1 次删除
  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 查看文件

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

+ 4
- 0
extras/wav2sketch/wav2sketch.html 查看文件

@@ -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 查看文件

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

正在加载...
取消
保存