Web Audio Api HardLimiter

Size
2,697 Kb
Views
20,240

How do I make an web audio api hardlimiter?

Hacking a hard-limiter with the web audio api.Far away from perfect (still clips), but around 6db noticeable louder.. What is a web audio api hardlimiter? How do you make a web audio api hardlimiter? This script and codes were developed by André Michelle on 18 October 2022, Tuesday.

Web Audio Api HardLimiter Previews

Web Audio Api HardLimiter - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Web Audio Api HardLimiter</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Web Audio HardLimiter</h1>
<div class="controls"> <span>Maximize</span> <input type="range" value="0" step="1" min="0" max="12" oninput="maximize(this.value);"> <span class="value" id="maximize-db">6</span> <span class="unit">dB</span> <div id="reduction"></div>
</div>
<div> <h3><a href="http://www.audiotool.com/track/never-ending_passion/" target="audiotool">Never-ending Passion</a> by The Three Pauls</h3> <audio id="audio" crossorigin controls> <source src="http://api.audiotool.com/track/never-ending_passion/play.ogg" type="audio/ogg"> <source src="http://api.audiotool.com/track/never-ending_passion/play.mp3" type="audio/mpeg"> Your browser does not support the audio tag. </audio>
</div>
<p>Does not work in Safari.</p> <script src="js/index.js"></script>
</body>
</html>

Web Audio Api HardLimiter - Script Codes CSS Codes

html, body { font-size: 12px; font-family: "Open Sans"; background: white;
}
.controls { padding: 6px 16px; border-radius: 5px; background: #424242; color: #f0f0f0; display: inline-block; width: 288px; white-space: nowrap;
}
.controls input { width: 200px;
}
.controls span, .controls input { vertical-align: middle; padding: 0; margin: 0;
}
#reduction { margin-top: 4px; margin-bottom: 2px; width: 288px; height: 2px; background: green;
}
a { text-decoration: none; color: #666;
}
p { color: #CCC;
}
audio { width: 320px;
}

Web Audio Api HardLimiter - Script Codes JS Codes

var context = new (webkitAudioContext||AudioContext)();
var audio = document.getElementById('audio');
var label = document.getElementById('maximize-db');
var reduction = document.getElementById('reduction');
var source = context.createMediaElementSource(audio);
var preGain = context.createGain();
var limiter = context.createDynamicsCompressor();
limiter.threshold.value = 0.0; // this is the pitfall, leave some headroom
limiter.knee.value = 0.0; // brute force
limiter.ratio.value = 20.0; // max compression
limiter.attack.value = 0.005; // 5ms attack
limiter.release.value = 0.050; // 50ms release
source.connect(preGain);
preGain.connect(limiter);
limiter.connect(context.destination);
var dbToGain = function(db) { return Math.exp(db*Math.log(10.0)/20.0);
}
var maximize = (function(db) { preGain.gain.value = dbToGain(db); label.textContent = db; return arguments.callee;
})(0);
var showReduction = (function() { reduction.style.width = (dbToGain(limiter.reduction.value)*288)+"px";	window.requestAnimationFrame(arguments.callee);
})();
Web Audio Api HardLimiter - Script Codes
Web Audio Api HardLimiter - Script Codes
Home Page Home
Developer André Michelle
Username andremichelle
Uploaded October 18, 2022
Rating 3
Size 2,697 Kb
Views 20,240
Do you need developer help for Web Audio Api HardLimiter?

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!

André Michelle (andremichelle) Script Codes
Create amazing captions with AI!

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!