Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Generated by CoffeeScript 1.8.0
- (function() {
- var URL, context, ctx, drawSpectrum, gradient, javascriptNode, loadSound, onError, playSound, setupAudioNodes, sourceNode;
- URL = "Gesaffelstein%20&%20Jesper%20Kyd%20-%20In%20Pursuit%20for%20Ezio%27s%20Family.ogg";
- if (!window.AudioContext) {
- if (!window.webkitAudioContext) {
- alert("Nie znaleziono obsługi dla AudioContext!");
- }
- 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 = function() {
- var analyser;
- 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);
- };
- loadSound = function(url) {
- var request;
- request = new XMLHttpRequest();
- request.open("GET", url, true);
- request.responseType = "arraybuffer";
- request.onload = function() {
- context.decodeAudioData(request.response, function(buffer) {
- playSound(buffer);
- }, onError);
- };
- request.send();
- };
- playSound = function(buffer) {
- sourceNode.buffer = buffer;
- sourceNode.start(0);
- };
- onError = function(e) {
- console.log(e);
- };
- javascriptNode.onaudioprocess = function() {
- var array;
- array = new Uint8Array(analyser.frequencyBinCount);
- analyser.getByteFrequencyData(array);
- ctx.clearRect(0, 0, 1024, 325);
- ctx.fillStyle = gradient;
- drawSpectrum(array);
- };
- drawSpectrum = function(array) {
- var i, val;
- i = 0;
- while (i < array.length) {
- val = array[i];
- ctx.fillRect(i * 5, 325 - val, 3, 325);
- }
- };
- $(document).ready(function() {
- $.ajax({
- url: URL,
- success: function() {
- $("#play_button").show();
- }
- });
- });
- loadSound(URL);
- }).call(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement