A very simple synthesizer playing "The Drunken Sailor". This is not so much a demo as it is a component for other demos. It is not minified, except at the most basic levels and the notes notation isn'…
C=String.fromCharCode;function Z(C,N,O,i){O="";for(i=0;i<N;i++) O+=C;return O;}function G(T,N,F,P,H,W,E,R){N/=12,F=N*N*440,S=44100,T=T*S|0,L=S/F/2|0;P=Z("!",L);H=Z("}",L);E=Z(C(0),100);for(W="";W.length<T-100;W+=P+H);return W.substr(0,T-101)+E;}M=[[.4,24],[.2,24],[.2,24],[.4,24],[.2,24],[.2,24],[.4,24],[.4,17],[.4,20],[.4,24],[.4,22],[.2,22],[.2,22],[.4,22],[.2,22],[.2,22],[.4,22],[.4,15],[.4,19],[.4,22],[.4,24],[.2,24],[.2,24],[.4,24],[.2,24],[.2,24],[.4,24],[.4,26],[.4,27],[.4,29],[.4,27],[.4,24],[.4,22],[.4,19],[.8,17],[.8,17],[.8,24],[.6,24],[.2,24],[.4,24],[.4,17],[.4,20],[.4,24],[.8,22],[.6,22],[.2,22],[.4,22],[.4,15],[.4,19],[.4,22] ,[.8,24],[.6,24],[.2,24],[.4,24],[.4,26],[.4,27],[.4,29],[.4,27],[.4,24],[.4,22],[.4,19],[.8,17],[.8,17]];Y={};X="";for(var j=0;j<M.length;j++){V=M[j];if(!Y[V])Y[V]=G.apply(0,V);X+=Y[V];}T=X.length;Audio("data:audio/wav;base64,UklGRmisAABXQVZFZm10IBAAAAABAAEARKwAAESsAAABAAgAZGF0"+btoa("a"+C(T&0xff)+C(T>>8&0xff)+C(T>>16&0xff)+C(T>>24&0xff)+X)).play();
Qz1TdHJpbmcuZnJvbUNoYXJDb2RlO2Z1bmN0aW9uIFooQyxOLE8saSl7Tz0iIjtmb3IoaT0wO2k8TjtpKyspIE8rPUM7cmV0dXJuIE87fWZ1bmN0aW9uIEcoVCxOLEYsUCxILFcsRSxSKXtOLz0xMixGPU4qTio0NDAsUz00NDEwMCxUPVQqU3wwLEw9Uy9GLzJ8MDtQPVooIiEiLEwpO0g9WigifSIsTC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YmMHhmZikrQyhUPj4yNCYweGZmKStYKSkucGxheSgpOw==
function repeatChar(character,length){
var output="";
for(i=0;i<length;i++)
output+=character;
return output;
}
function generateSound(lengthSeconds,halfToneFromA,F,P,H,W,E,R){
var octave=halfToneFromA/12;
var frequency=octave*octave*440;
var lengthSamples=lengthSeconds*44100|0;
var samplePortionLength=44100/frequency/2|0;
var lowSamplePortion=repeatChar("!",samplePortionLength);
var highSamplePortion=repeatChar("}",samplePortionLength);
var spacerSample=repeatChar(String.fromCharCode(0),100);
for(var output="";output.length<lengthSamples-100;output+=lowSamplePortion+highSamplePortion);
return output.substr(0,lengthSamples-101)+E;
}
var notes=[[.4,24],[.2,24],[.2,24],[.4,24],[.2,24],[.2,24],[.4,24],[.4,17],[.4,20],[.4,24],[.4,22],[.2,22],[.2,22],[.4,22],[.2,22],[.2,22],[.4,22],[.4,15],[.4,19],[.4,22],[.4,24],[.2,24],[.2,24],[.4,24],[.2,24],[.2,24],[.4,24],[.4,26],[.4,27],[.4,29],[.4,27],[.4,24],[.4,22],[.4,19],[.8,17],[.8,17],[.8,24],[.6,24],[.2,24],[.4,24],[.4,17],[.4,20],[.4,24],[.8,22],[.6,22],[.2,22],[.4,22],[.4,15],[.4,19],[.4,22] ,[.8,24],[.6,24],[.2,24],[.4,24],[.4,26],[.4,27],[.4,29],[.4,27],[.4,24],[.4,22],[.4,19],[.8,17],[.8,17]];
sampleCache={};
rawData="";
for(var j=0;j<notes.length;j++){
if(!sampleCache[notes[j]])
sampleCache[notes[j]]=generateSound.apply(0,notes[j]);
rawData+=sampleCache[notes[j]];
}
Audio(
"data:audio/wav;base64,UklGRmisAABXQVZFZm10IBAAAAABAAEARKwAAESsAAABAAgAZGF0"
+btoa(
"a"
+String.fromCharCode(rawData.length&0xff)+String.fromCharCode(rawData.length>>8&0xff)+String.fromCharCode(rawData.length>>16&0xff)+String.fromCharCode(rawData.length>>24&0xff)
+rawData
)
).play();