Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure the compression with web audio api?

I would like to create a HTML meter to display the reduction made by the compressor node.

I used this code but it does not change the metter

compressor = context.createDynamicsCompressor();
compressor.threshold = -50;
compressor.ratio = 12;
compressor.attack = 0.003;
compressor.reduction.onchange = function () {
  var gainReduction = pluginSlot1.reduction;
  document.getElementById("meter").value = gainReduction.value;
};

This is connected to this HTML

< meter id="meter" min="0" max="100">

What do I need to do in order for it to work?

like image 441
Oliver Drummond Avatar asked Jan 27 '26 23:01

Oliver Drummond


1 Answers

Here's a quick and dirty jsbin example: http://jsbin.com/ahocUt/1/edit

Unless there's something I'm missing in the spec, the reduction param doesn't fire any events. You just need to read it on-demand. In my example, that's just happening with a requestAnimationFrame loop.

The other thing you're missing is that you need to set the params with compressor.threshold.value, because compressor.threshold is actually an object.

Hope that helps.

like image 98
Kevin Ennis Avatar answered Jan 29 '26 11:01

Kevin Ennis