chromaprint-fixed
Version:
A JavaScript implementation of AcoustID Chromaprint
135 lines (92 loc) • 4.63 kB
HTML
<html>
<head>
<title>silenceRemover.coffee</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="../docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="algorithms.html">
src/algorithms.coffee
</a>
<a class="source" href="calculator.html">
src/calculator.coffee
</a>
<a class="source" href="chroma.html">
src/chroma.coffee
</a>
<a class="source" href="fpcalc.html">
src/fpcalc.coffee
</a>
<a class="source" href="silenceRemover.html">
src/silenceRemover.coffee
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>silenceRemover.coffee</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
</div>
<div class="content"><div class='highlight'><pre>@chromaprint ?= {}</pre></div></div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<p>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.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">silenceRemover</span> = <span class="hljs-params">(threshold, <span class="hljs-built_in">window</span> = <span class="hljs-number">55</span>)</span> -></span></pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<p>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.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"> <span class="hljs-title">filter</span> = <span class="hljs-params">(<span class="hljs-built_in">window</span>)</span> -></span>
finished = <span class="hljs-literal">false</span>
(byte, index) ->
finished <span class="hljs-keyword">or</span>= ((<span class="hljs-built_in">window</span> += byte) / (index + <span class="hljs-number">1</span>)) > threshold</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<p>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.</p>
</div>
<div class="content"><div class='highlight'><pre> (input) -> input.filter filter(<span class="hljs-built_in">window</span>)
@chromaprint.silenceRemover = silenceRemover</pre></div></div>
</li>
</ul>
</div>
</body>
</html>