Audio Visualiser
How do I make an audio visualiser?
Messing around with AudioContext. You can also drop your own music.. What is a audio visualiser? How do you make a audio visualiser? This script and codes were developed by Thepheer on 13 September 2022, Tuesday.
Audio Visualiser - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Audio Visualiser</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='js/gmkfa.js'></script> <script src="js/index.js"></script>
</body>
</html>
Audio Visualiser - Script Codes CSS Codes
html { background: #000; overflow: hidden;
}
audio { position: absolute; bottom: 1em; left: 50%; width: 500px; margin: 0 -250px;
}
canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%;
}
Audio Visualiser - Script Codes JS Codes
(function () { 'use strict'; window.addEventListener('load', function () { var Analyser = this.Analyser = function (context, fft, smoothing) { var AudioContext = window.AudioContext || window.webkitAudioContext; this.context = context || new AudioContext(); this.analyser = this.context.createAnalyser(); this.analyser.fftSize = fft || 2048; this.analyser.smoothingTimeConstant = smoothing || 0; this.analyser.connect(this.context.destination); this.wave = new Uint8Array(this.analyser.frequencyBinCount * 2); this.freq = new Uint8Array(this.analyser.frequencyBinCount); } Analyser.prototype.audio = function (audio) { if(this.source) this.source.disconnect(); this._audio = audio || new Audio(); this.source = this.context.createMediaElementSource(this._audio); this.source.connect(this.analyser); return this; }; Analyser.prototype.stream = function (stream) { if(this.source) this.source.disconnect(); this._stream = stream; this.source = this.context.createMediaStreamSource(this._stream); this.source.connect(this.analyser); return this; }; Analyser.prototype.update = function () { this.analyser.getByteFrequencyData(this.freq); this.analyser.getByteTimeDomainData(this.wave); return this; }; Analyser.prototype.amplitude = function (hz) { var l = hz/this.context.sampleRate * this.freq.length | 0; for(var sum = 0, i = 0; i < l;) sum += this.freq[i++]; return sum / l / 255; }; var C = util.tag('canvas', null, document.body); var $ = C.getContext('2d'), W, H; (window.onresize = function () { W = C.width = C.clientWidth; H = C.height = C.clientHeight; })(); var audio = util.tag('audio', { crossOrigin: true, controls: true, autoplay: true, loop: true, src: location.hash ? location.hash.slice(1) : 'https://dl.dropboxusercontent.com/u/3116587/audio/01%20-%20Introduction.ogg' }, document.body); var analyser = new Analyser(null, 2048, 0.5).audio(audio); var colors = [[ [0/1, [0.2, 0.5, 1.0]], [1/1, [1.0, 0.2, 1.0]] ], [ [0/4, [0.0, 0.0, 0.0]], [1/4, [0.0, 0.0, 1.0]], [2/4, [1.0, 0.0, 0.0]], [3/4, [1.0, 1.0, 0.0]], [4/4, [1.0, 1.0, 1.0]] ]]; util.loop(function (f, t, dt) { analyser.update(); var amp = analyser._audio.duration ? Math.min(1, Math.pow(1.25 * analyser.amplitude(10e3), 2)) : 0.5 - 0.25 * Math.cos(t / 1000); var s = 1.01 + 0.09 * amp; $.setTransform(s, 0, 0, s, W/2, H/2); $.drawImage(C, -W/2, -H/2); $.fillStyle = util.color.rgba(0, 0, 0, 0.05); $.fillRect(-W/2, -H/2, W, H); $.setTransform(1, 0, 0, 1, W/2, H/2); $.beginPath(); for(var a, r, i = 0, j = analyser.wave.length; i < j; i++) { a = i/j * 2 * Math.PI; r = amp * 256 * (0.5 + analyser.wave[i]/255); $.lineTo(r * Math.sin(a), r * Math.cos(a)); } var c = util.gradient(colors[0], amp); $.fillStyle = util.color.rgba(c[0], c[1], c[2], amp / 2); $.strokeStyle = util.color.rgba(c[0], c[1], c[2], amp); $.lineWidth = 4 * amp; $.fill(); $.stroke(); }); window.addEventListener('dragover', function (e) { e.preventDefault(); e.stopPropagation(); }); window.addEventListener('drop', function (e) { e.preventDefault(); e.stopPropagation(); var file = e.dataTransfer.files[0]; if(file) { URL.revokeObjectURL(analyser._audio.src); analyser._audio.src = URL.createObjectURL(file); } }); }, false);
}).call(this);
Developer | Thepheer |
Username | thepheer |
Uploaded | September 13, 2022 |
Rating | 3.5 |
Size | 6,237 Kb |
Views | 40,480 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Cylinder | 4,658 Kb |
WebGL shader video processing | 9,532 Kb |
Magnetic Field | 7,703 Kb |
Fluid Cube | 4,316 Kb |
Emoji Clock | 2,336 Kb |
Braille | 5,670 Kb |
100 000 particles | 4,379 Kb |
Flight Control | 5,989 Kb |
SVG Animation | 4,793 Kb |
Color Wheel | 3,070 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
A Pen by Tosh | Panev | 2,586 Kb |
Velocity.js custom stagger | Tommiehansen | 4,805 Kb |
Sinclair Research Computers | MattCowley | 3,068 Kb |
RollOver Effect 2 | Lmack90 | 2,162 Kb |
Ionic Infinite outside ion-content with ion-pane | Felquis | 3,117 Kb |
TestTube CSS | EZPK | 2,710 Kb |
Minimal Menu | Achudars | 3,430 Kb |
CSS Bot Confusion | Jpod | 3,456 Kb |
Whyutils | LeYvan | 3,752 Kb |
Flat design iframe | Damienpm | 1,819 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!