JSFiddle - React, Tailwind, and code Playground
HTML
<!doctype html>
<head>
<meta charset="utf-8">
<title>jsfxr demo</title>
<script>
var url = window.URL || window.webkitURL;
function playSound(params) {
try {
var soundURL = jsfxr(params);
var player = new Audio();
player.addEventListener('error', function(e) {
console.log("Error: " + player.error.code);
}, false);
player.src = soundURL;
player.play();
if (url.revokeObjectURL)
player.addEventListener('ended', function(e) {
url.revokeObjectURL(soundURL);
}, false);
} catch(e) {
console.log(e.message);
}
}
</script>
</head>
<body>
<form>
<button onclick="playSound('3,,0.3708,0.5822,0.3851,0.0584,,-0.0268,,,,-0.0749,0.7624,,,,,,1,,,,,0.5');return false">Play Explosion</button>
<button onclick="playSound('1,,0.3201,,0.4743,0.3202,,0.0833,,0.4207,0.4278,,,,,,,,1,,,,,0.5');return false">Play Powerup</button>
<button onclick="playSound('0,,0.1812,,0.1349,0.4524,,0.2365,,,,,,0.0819,,,,,1,,,,,0.5');return false">Play Jump</button>
<br/>
<label for="soundsettings">Paste <a href="http://www.superflashbros.net/as3sfxr/">as3fxr</a> settings string here:</label>
<input type="text" id="soundsettings" size="100">
<button onclick="playSound(document.getElementById('soundsettings').value);return false">Play Custom Sound</button>
</form>
</body>
</html>
JavaScript
/*
* RIFFWAVE.js v0.02 - Audio encoder for HTML5 <audio> elements.
* Copyright (C) 2011 Pedro Ladaria <pedro.ladaria at Gmail dot com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
* The full license is available at http://www.gnu.org/licenses/gpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* Changelog:
*
* 0.01 - First release
* 0.02 - New faster base64 encoding
*
*/
var FastBase64 = {
chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encLookup: [],
Init: function() {
for (var i=0; i<4096; i++) {
FastBase64.encLookup[i] = FastBase64.chars[i >> 6] + FastBase64.chars[i & 0x3F];
}
},
Encode: function(src) {
var len = src.length;
var dst = '';
var i = 0;
while (len > 2) {
n = (src[i] << 16) | (src[i+1]<<8) | src[i+2];
dst+= FastBase64.encLookup[n >> 12] + FastBase64.encLookup[n & 0xFFF];
len-= 3;
i+= 3;
}
if (len > 0) {
var n1= (src[i] & 0xFC) >> 2;
var n2= (src[i] & 0x03) << 4;
if (len > 1) n2 |= (src[++i] & 0xF0) >> 4;
dst+= FastBase64.chars[n1];
dst+= FastBase64.chars[n2];
if (len == 2) {
var n3= (src[i++] & 0x0F) << 2;
n3 |= (src[i] & 0xC0) >> 6;
dst+= FastBase64.chars[n3];
}
if (len == 1) dst+= '=';
dst+= '=';
}
return dst;
} // end Encode
}
FastBase64.Init();
/**
* SfxrParams
*
* Copyright 2010 Thomas Vian
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* ...