[javascript] Sound effects in JavaScript / HTML5

_x000D_
_x000D_
var AudioContextFunc = window.AudioContext || window.webkitAudioContext;_x000D_
var audioContext = new AudioContextFunc();_x000D_
var player=new WebAudioFontPlayer();_x000D_
var instrumVox,instrumApplause;_x000D_
var drumClap,drumLowTom,drumHighTom,drumSnare,drumKick,drumCrash;_x000D_
loadDrum(21,function(s){drumClap=s;});_x000D_
loadDrum(30,function(s){drumLowTom=s;});_x000D_
loadDrum(50,function(s){drumHighTom=s;});_x000D_
loadDrum(15,function(s){drumSnare=s;});_x000D_
loadDrum(5,function(s){drumKick=s;});_x000D_
loadDrum(70,function(s){drumCrash=s;});_x000D_
loadInstrument(594,function(s){instrumVox=s;});_x000D_
loadInstrument(1367,function(s){instrumApplause=s;});_x000D_
function loadDrum(n,callback){_x000D_
  var info=player.loader.drumInfo(n);_x000D_
  player.loader.startLoad(audioContext, info.url, info.variable);_x000D_
  player.loader.waitLoad(function () {callback(window[info.variable])});_x000D_
}_x000D_
function loadInstrument(n,callback){_x000D_
  var info=player.loader.instrumentInfo(n);_x000D_
  player.loader.startLoad(audioContext, info.url, info.variable);_x000D_
  player.loader.waitLoad(function () {callback(window[info.variable])});_x000D_
}_x000D_
function uhoh(){_x000D_
  var when=audioContext.currentTime;_x000D_
  var b=0.1;_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, instrumVox, when+b*0, 60, b*1);_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, instrumVox, when+b*3, 56, b*4);_x000D_
}_x000D_
function applause(){_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, instrumApplause, audioContext.currentTime, 54, 3);_x000D_
}_x000D_
function badumtss(){_x000D_
  var when=audioContext.currentTime;_x000D_
  var b=0.11;_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, drumSnare, when+b*0, drumSnare.zones[0].keyRangeLow, 3.5);_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, drumLowTom, when+b*0, drumLowTom.zones[0].keyRangeLow, 3.5);_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, drumSnare, when+b*1, drumSnare.zones[0].keyRangeLow, 3.5);_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, drumHighTom, when+b*1, drumHighTom.zones[0].keyRangeLow, 3.5);_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, drumSnare, when+b*3, drumSnare.zones[0].keyRangeLow, 3.5);_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, drumKick, when+b*3, drumKick.zones[0].keyRangeLow, 3.5);_x000D_
  player.queueWaveTable(audioContext, audioContext.destination, drumCrash, when+b*3, drumCrash.zones[0].keyRangeLow, 3.5);_x000D_
}
_x000D_
<script src='https://surikov.github.io/webaudiofont/npm/dist/WebAudioFontPlayer.js'></script>_x000D_
<button onclick='badumtss();'>badumtss</button>_x000D_
<button onclick='uhoh();'>uhoh</button>_x000D_
<button onclick='applause();'>applause</button>_x000D_
<br/><a href='https://github.com/surikov/webaudiofont'>More sounds</a>
_x000D_
_x000D_
_x000D_

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to html5-audio

How to make audio autoplay on chrome HTML5 record audio to file HTML5 Audio stop function change <audio> src with javascript How to play a notification sound on websites? How to play audio? html 5 audio tag width Custom CSS for <audio> tag? HTML5 Audio Looping Sound effects in JavaScript / HTML5