UNPKG

chromaprint-fixed

Version:

A JavaScript implementation of AcoustID Chromaprint

36 lines (30 loc) 1.23 kB
// Generated by CoffeeScript 2.2.3 (function() { var silenceRemover; if (this.chromaprint == null) { this.chromaprint = {}; } // Gets a function for removing silence from a buffer. It can be configured with // a silence threshold. The window is also configurable (see the filter function // below), but defaults to 55, which, I am told, is 5ms at 11025 Hz. silenceRemover = function(threshold, window = 55) { var filter; // The filter returns a function that returns true if the average ever passes // above the threshold. The window is the starting point when summing up the // bytes for the average. filter = function(window) { var finished; finished = false; return function(byte, index) { return finished || (finished = ((window += byte) / (index + 1)) > threshold); }; }; // This function returns what it's given only if the average has s // The returned function takes an array of bytes, only returns those that occur // after the average has surpassed the silence threshold. return function(input) { return input.filter(filter(window)); }; }; this.chromaprint.silenceRemover = silenceRemover; }).call(this);