audio-buffer-instrument
Version:
Simple webaudio module that creates instruments from audio-buffers
28 lines (22 loc) • 862 B
HTML
<!-- run npm update to test with this example -->
<script src="node_modules/tiny-sample-loader/dist/tiny-sample-loader.js"></script>
<script src="dist/audio-buffer-instrument.js"></script>
<script>
var ctx = new AudioContext();
var remoteUrl = 'https://oramics.github.io/sampled/DM/TR-909/SP/samples/hihat-open-2.wav';
var hihatPromise = tinySampleLoader(remoteUrl, ctx);
hihatPromise.then(function (value) {
var instrument = new audioBufferInstrument(ctx, value);
// Trigger
instrument.trigger(1);
var audioBuf = instrument.get();
audioBuf.connect(ctx.destination);
audioBuf.start(2);
// In this way you don't need to reload the buffer source
var audioBuf = instrument.get();
audioBuf.connect(ctx.destination);
audioBuf.start(3);
}).catch(function (value) {
console.log(value); // error message
})
</script>