samples/video_conferencing/js/video/soundmeter.js
function SoundMeter(context) {
  this.context = context;
  this.instant = 0.0;
  this.slow = 0.0;
  this.clip = 0.0;
  this.script = context.createScriptProcessor(2048, 1, 1);
  var that = this;
  this.script.onaudioprocess = function(event) {
    var input = event.inputBuffer.getChannelData(0);
    var i;
    var sum = 0.0;
    var clipcount = 0;
    for (i = 0; i < input.length; ++i) {
      sum += input[i] * input[i];
      if (Math.abs(input[i]) > 0.99) {
        clipcount += 1;
      }
    }
    that.instant = Math.sqrt(sum / input.length);
    that.slow = 0.95 * that.slow + 0.05 * that.instant;
    that.clip = clipcount / input.length;
  };
}
function SoundMeter(context) {
  this.context = context;
  this.instant = 0.0;
  this.slow = 0.0;
  this.clip = 0.0;
  this.script = context.createScriptProcessor(2048, 1, 1);
  var that = this;
  this.script.onaudioprocess = function(event) {
    var input = event.inputBuffer.getChannelData(0);
    var i;
    var sum = 0.0;
    var clipcount = 0;
    for (i = 0; i < input.length; ++i) {
      sum += input[i] * input[i];
      if (Math.abs(input[i]) > 0.99) {
        clipcount += 1;
      }
    }
    that.instant = Math.sqrt(sum / input.length);
    that.slow = 0.95 * that.slow + 0.05 * that.instant;
    that.clip = clipcount / input.length;
  };
}
function SoundMeter ( context ) { this . context = context ; this . instant = 0.0 ; this . slow = 0.0 ; this . clip = 0.0 ; this . script = context . createScriptProcessor ( 2048 , 1 , 1 ) ; var that = this ; this . script . onaudioprocess = function ( event ) { var input = event . inputBuffer . getChannelData ( 0 ) ; var i ; var sum = 0.0 ; var clipcount = 0 ; for ( i = 0 ; i < input . length ; ++ i ) { sum += input [ i ] * input [ i ] ; if ( Math . abs ( input [ i ] ) > 0.99 ) { clipcount += 1 ; } } that . instant = Math . sqrt ( sum / input . length ) ; that . slow = 0.95 * that . slow + 0.05 * that . instant ; that . clip = clipcount / input . length ; } ; }
Meter class that generates a number correlated to audio volume. The meter class itself displays nothing, but it makes the instantaneous and time-decaying volumes available for inspection. It also reports on the fraction of samples that were at or near the top of the measurement range.
Meter class that generates a number correlated to audio volume . The meter class itself displays nothing but it makes the instantaneous and time - decaying volumes available for inspection . It also reports on the fraction of samples that were at or near the top of the measurement range .