BROKEN_beep = () ->
BROKEN_beep = () ->
http://stackoverflow.com/questions/14662131/generate-a-sound-of-specific-frequency https://github.com/stcode/javascript-array-to-audio
freq = 440
rate = 44100
data = []
for i in [0 .. 10000]
time = i / rate
data[i] = 128 + Math.round(127 * (Math.sin(2 * Math.PI * freq * time)))
snd = new Audio(data)
console.log "data", data
console.log "snd",snd
snd.play()
beep = () ->
note(300, .2)
note(150, .2)
note(75, .2)
song [ [440, 1] [220, 1] [110, 1] ]
note = (freq, duration) ->
if window.AudioContext?
context = new AudioContext()
oscillator = context.createOscillator()
oscillator.connect(context.destination)
oscillator.frequency.value = freq
oscillator.type = oscillator.SQUARE # TRIANGLE, SINE
oscillator.start(context.currentTime)
oscillator.stop(context.currentTime + duration)
BROKEN_song = (notes) ->
return
context = new webkitAudioContext()
oscillator = context.createOscillator()
oscillator.connect(context.destination)
start_time = context.currentTime
for note in notes
oscillator.frequency.value = note[0]
oscillator.start(start_time)
next_time = start_time + note[1]
oscillator.stop(next_time)
start_time = next_time
(exports ? this).beep = beep