var c=String.fromCharCode,e=document,g={},h={};function k(a,b){a=parseInt(a);var d="",f;for(f=0;f<b;f++){d+=c(a&255);a>>=8}return d}_n=e.createElement("div");_b=function(a,b){a.map||(a=[a]);var d="";for(i in a)for(var f=2*Math.PI*a[i]/11025,j=0;j<5512.5;j++)d+=k(Math.sin(f*j)*32768,2);d=k(16,4)+k(1,2)+k(1,2)+k(11025,4)+k(22050,4)+k(2,2)+k(16,2)+"data"+k(d.length,4)+d;return"data:"+(b||"audio")+"/x-wav;base64,"+btoa("RIFF"+k(d.length,4)+"WAVEfmt "+d)}; function l(a,b){el=e.createElement("a");el.textContent=a;e.body.appendChild(el);el.addEventListener("click",function(){eval(b)},false)}e.body.appendChild(_n);l("Download ","location = _b(_n.a,'application')");l("| Play","new Audio(_b(_n.a)).play()"); e.addEventListener("keydown",function(a,b){b=(new Date).getTime();a=a.which;if(!(g[a]&&g[a]+350>b)){g[a]=b;b="AWSEDFTGYHUJ".indexOf(c(a));if(b>-1){b=440*Math.pow(1.0594630943,+b+41-49);h[b]||(h[b]=new Audio(_b(b)));a=_n.a||[];a.push(b);a.length>10&&a.shift();_n.textContent=a.join(",");_n.a=a;h[b].play()}}},false);
/**
* copyright Ryan Day 2010
* http://ryanday.org/
*
* mit/gpl dual licensed
*
* use it modify it have a ball even make money off of it!
*
*
* */
var sfc = String.fromCharCode,
d = document,
ce = function(nn){return d.createElement(nn)},
bits=16,
pack = function(point,bytes){
point = parseInt(point);
var s = '',i;
for(i=0;i<bytes;i++){
s+=sfc(point & 255);
point = point >> 8;
}
return s;
},downtime = {};
_n=ce('div'),
_b=function(frequency,m){
if(!frequency.map) frequency=[frequency];
var c3,c2,num_channels = 1,samples = "",sample_rate=11025;
//frequency.forEach(function(f){
for(i in frequency){
var f=frequency[i],
k = 2* Math.PI * f / sample_rate,
total = sample_rate*0.5,
max = 65536,
halfMax=(max/2);
for (var sample=0; sample<total; sample++) {
samples += pack((Math.sin(k * sample)*halfMax),2);
}
}
// 16 offset pcm num channels
c2 = pack(16,4)+pack(1,2)+pack(num_channels,2)+pack(11025,4)+pack((sample_rate * num_channels * bits)/8,4)+pack((num_channels * bits)/8,2)+pack(bits,2)+"data"+pack(samples.length,4)+samples;;
return "data:"+(m||"audio")+"/x-wav;base64,"+btoa("RIFF"+pack(c2.length,4)+"WAVEfmt "+c2)
}
var generated = {},
generateSound = function(key){
key = 440*Math.pow(1.0594630943,((+key)+41)-49)
if(!generated[key]){
generated[key] = new Audio(_b(key));
}
//---- add note
var a=[];
if(_n.a) a=_n.a;
a.push(key);
if(a.length > 10)a.shift();
_n.textContent = a.join(',');
_n.a=a;
generated[key].play();
},
doel = function(txt,fnstr){
el = ce('a');
el.textContent=txt;
d.body.appendChild(el);
el.addEventListener('click',function(){
eval(fnstr)
},false);
}
d.body.appendChild(_n);
doel('Download ',"location=_b(_n.a,'application')");
doel('| Play',"new Audio(_b(_n.a)).play()");
d.addEventListener('keydown',function(ev){
var t = new Date().getTime(),w=ev.which;
if(downtime[w] && downtime[w]+350 > t){
return;
}
downtime[w] = t;
var c = sfc(w),k ='AWSEDFTGYHUJ'.indexOf(c);
if(k >-1){
generateSound(k);
}
},false);