WebAudioFont is a set of resources and associated technology that uses sample-based synthesis to play musical instruments in the browser. You can choose from thousands of instrument, see Catalog.
see LICENSE.md. Contact me if you need different license.
Hire me if you need advanced help (sss1024@gmail.com).
Add a link to WebAudioFontPlayer.js and the instrument file. Invoke queueWaveTable.
Minimal HTML page
<html>
<head>
<script src='https://surikov.github.io/webaudiofont/npm/dist/WebAudioFontPlayer.js'></script>
<script src='https://surikov.github.io/webaudiofontdata/sound/0250_SoundBlasterOld_sf2.js'></script>
<script>
var AudioContextFunc = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContextFunc();
var player=new WebAudioFontPlayer();
player.loader.decodeAfterLoading(audioContext, '_tone_0250_SoundBlasterOld_sf2');
function play(){
player.queueWaveTable(audioContext, audioContext.destination
, _tone_0250_SoundBlasterOld_sf2, 0, 12*4+7, 2);
return false;
}
</script>
</head>
<body>
<p><a href='javascript:play();'>Hello, world!</a></p>
</body>
</html>
See live example.
Use queueWaveTable to play single note. Use queueChord, queueSnap, queueStrumDown, queueStrumUp to play chords. See live example for strumming.
Use time for notes to define sequence. See live example of sequencer.
Use the startLoad and waitLoad functions.
var instr=null;
var AudioContextFunc = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContextFunc();
var player=new WebAudioFontPlayer();
function changeInstrument(path,name){
player.loader.startLoad(audioContext, path, name);
player.loader.waitLoad(function () {
instr=window[name];
});
}
changeInstrument('https://surikov.github.io/webaudiofontdata/sound/0290_Aspirin_sf2_file.js','_tone_0290_Aspirin_sf2_file');
All loaded instruments are cached in memory.
See live example
Use WebAudioFontChannel to create a chain of 10-band equalizers. Use WebAudioFontReverberator to add echo.
See live example
See tutorial
WebAudioFont doesn't require installation. It hosts all code and instruments at GitHub Pages.
var webaudiofont = require('webaudiofont');
var player = new WebAudioFontPlayer();
...
"devDependencies": {
"webaudiofont":"^2.5.0"
...
WebAudioFont uses Web Audio API to play instruments. Synthesizer uses wavetables to play sound. Instruments came from free soundfonts:
Use drumInfo and instrumentInfo in realtime. See live example.
WebAudioFontPlayer has the function queueWaveTable(audioContext, target, preset, when, pitch, duration, volume, slides)
Parameters:
The function queueWaveTable returns an envelope object. You can use this object to cancel a sound or to access AudioBufferSourceNode.
Use queueChord, queueStrumUp, queueStrumDown, queueSnap for chords. See live example.
Feel free to ask for any kind of help at project issues.
See TypeScript implementation.
The catalog consists of a full set of MIDI standards. Each instrument has 5-10 sound variations from different soundfonts.
Generated using TypeDoc