Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- URL = "Gesaffelstein%20&%20Jesper%20Kyd%20-%20In%20Pursuit%20for%20Ezio%27s%20Family.ogg"
- unless window.AudioContext
- alert "Nie znaleziono obsługi dla AudioContext!" unless window.webkitAudioContext
- window.AudioContext = window.webkitAudioContext
- context = new AudioContext()
- ctx = $("#music").get()[0].getContext("2d")
- gradient = ctx.createLinearGradient(0, 0, 0, 325)
- javascriptNode = 0
- sourceNode = 0
- gradient.addColorStop 1, "#FFFFFF"
- gradient.addColorStop 0.75, "#00FFFF"
- gradient.addColorStop 0.25, "#0000FF"
- gradient.addColorStop 0, "#000000"
- setupAudioNodes()
- setupAudioNodes = ->
- javascriptNode = context.createScriptProcessor(2048, 1, 1)
- javascriptNode.connect(context.destination)
- analyser = context.createAnalyser()
- analyser.smoothingTimeConstant = 0.75
- analyser.fftsize = 512
- sourceNode = context.createBufferSource()
- sourceNode.connect(analyser)
- analyser.connect(javascriptNode)
- sourceNode.connect(context.destination)
- return
- loadSound = (url) ->
- request = new XMLHttpRequest()
- request.open "GET", url, true
- request.responseType = "arraybuffer"
- request.onload = () ->
- context.decodeAudioData request.response, (buffer) ->
- playSound buffer
- return
- , onError
- return
- request.send()
- return
- playSound = (buffer) ->
- sourceNode.buffer = buffer
- sourceNode.start(0)
- return
- onError = (e) ->
- console.log(e)
- return
- javascriptNode.onaudioprocess = ->
- array = new Uint8Array(analyser.frequencyBinCount)
- analyser.getByteFrequencyData(array)
- ctx.clearRect 0, 0, 1024, 325
- ctx.fillStyle = gradient
- drawSpectrum array
- return
- drawSpectrum = (array) ->
- i = 0
- while i < (array.length)
- val = array[i]
- ctx.fillRect(i * 5, 325 - val, 3, 325)
- return
- $(document).ready ->
- $.ajax
- url: URL,
- success: ->
- $("#play_button").show()
- return
- return
- loadSound(URL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement