Skip to content

Instantly share code, notes, and snippets.

@viking
Created June 19, 2014 22:06
Show Gist options
  • Save viking/bfed5b7cc003452d68cc to your computer and use it in GitHub Desktop.
Save viking/bfed5b7cc003452d68cc to your computer and use it in GitHub Desktop.
wavepot song
var pitches = {
'C4': 262,
'C#4': 278,
'D4': 294,
'D#4': 311,
'E4': 330,
'F4': 349,
'F#4': 370,
'G4': 392,
'G#4': 415,
'A4': 440,
'A#4': 466,
'B4': 494,
'C5': 523
}
function dsp(t) {
var beat = Math.floor(t * 4) % 8;
var tone;
switch(beat) {
case 0:
tone = pitches['C4'];
break;
case 1:
tone = pitches['D4'];
break;
case 2:
tone = pitches['E4'];
break;
case 3:
tone = pitches['F4'];
break;
case 4:
tone = pitches['G4'];
break;
case 5:
tone = pitches['A4'];
break;
case 6:
tone = pitches['B4'];
break;
case 7:
tone = pitches['C5'];
break;
}
return 0.1 * Math.sin(2 * Math.PI * t * tone);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment