<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Kas, Graham!<DIV><BR class="khtml-block-placeholder"></DIV><DIV>Ya gotta love the way you think out of the box.  Break the rules to make better ones!  Thanks for the comments, code and inspiration.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Jim</DIV><DIV>---"I dream of cheese, It's toasted, mostly"  Ben Gunn, Treasure Island.</DIV><DIV><BR><DIV><DIV>On Sep 24, 2006, at 8:55 09PM, Graham Coleman &lt;<A href="mailto:gc@gehennom.net">gc@gehennom.net</A>&gt; wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 37px; text-indent: -37px; font: normal normal normal 12px/normal Helvetica; color: rgb(0, 0, 0); min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 37px; text-indent: -37px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>From: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">Graham Coleman &lt;<A href="mailto:gc@gehennom.net">gc@gehennom.net</A>&gt;</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 34px; text-indent: -34px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>Date: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">September 24, 2006 9:50:44 AM HST</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 21px; text-indent: -21px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>To: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">ChucK Users Mailing List &lt;<A href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</A>&gt;</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 23px; text-indent: -23px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>Cc: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><A href="mailto:jahbin@romatictrances.com">jahbin@romatictrances.com</A></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 50px; text-indent: -50px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>Subject: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><B>Re: [chuck-users] How can I filter silence?</B></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 58px; text-indent: -58px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>Reply-To: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">ChucK Users Mailing List &lt;<A href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</A>&gt;</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I came up with some cheesy code to implement the idea.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">It speeds up the tape when it hits silence. You'll need to</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">tune the time constants and the threshold for best results:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">sndbuf buf =&gt; dac;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">buf.read("speak/wave.wav");</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">buf.pos( 0 );</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">0.05 =&gt; float tresh;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">0.01 =&gt; float rt; //release const</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">0.4 =&gt; float at; //attack const</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">float xd;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">while(true) {</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>math.fabs( buf.last() )-xd =&gt; float a; //amp diff</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>if ( a &lt; 0 ) 0=&gt;a; //non-negative</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>xd*(1-rt)+at*a =&gt; xd; //the attack/release exponential filter</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>if ( xd&lt;tresh ) {</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">    </SPAN>buf.pos( buf.pos()+6 ); //skip ahead</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>}</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>1::samp=&gt;now;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">}</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">To compute the time constants, use this formula:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">//AT = 1 - e ^ (-2.2T/t&lt;AT)</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">or this if t is in samples:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">time const = 1.0 - exp( -2.2 / t );</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">best,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Graham</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">On Sun, 24 Sep 2006, Graham Coleman wrote:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I'm not sure if there's anything in chuck that will currently do this,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">but I think you could write something like a noise gate, that tracks the</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">amplitude of samples coming from a SndBuf and skips ahead until the level</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">rises above a threshold.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Not sure how well this would run in real time.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Better, would be something that preprocesses the file with in/out points</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">so the skips are quick.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Graham</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">On Sun, 24 Sep 2006, Jim Hinds wrote:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I want to scan some audio for dropped out sections.<SPAN class="Apple-converted-space">  </SPAN>It's long and</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">talky with 'significant' pauses between question and answers.<SPAN class="Apple-converted-space">  </SPAN>These</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">sections are filled with background noise, and often several seconds</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">long.<SPAN class="Apple-converted-space">  </SPAN>I'd like to shorten these empty sections (there are a lot of</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">them).</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I'd like to keep the files more or less intact (not sliced up into a</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">zillion intermediate files)</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Is there a unit in chuck that will be able to delete samples as they</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">pass through?</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Jim</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">chuck-users mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">chuck-users mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 37px; text-indent: -37px; font: normal normal normal 12px/normal Helvetica; color: rgb(0, 0, 0); min-height: 14px; "><B></B><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 37px; text-indent: -37px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>From: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">Kassen &lt;<A href="mailto:signal.automatique@gmail.com">signal.automatique@gmail.com</A>&gt;</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 34px; text-indent: -34px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>Date: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">September 24, 2006 10:23:58 AM HST</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 21px; text-indent: -21px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>To: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">"ChucK Users Mailing List" &lt;<A href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</A>&gt;</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 50px; text-indent: -50px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>Subject: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><B>Re: [chuck-users] How can I filter silence?</B></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 58px; text-indent: -58px; "><FONT face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><B>Reply-To: </B></FONT><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">ChucK Users Mailing List &lt;<A href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</A>&gt;</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BR><BR><DIV><SPAN class="gmail_quote">On 9/24/06, <B class="gmail_sendername">Graham Coleman</B> &lt;<A href="mailto:gc@gehennom.net">gc@gehennom.net</A>&gt; wrote:</SPAN><BLOCKQUOTE class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> I'm not sure if there's anything in chuck that will currently do this,<BR>but I think you could write something like a noise gate, that tracks the<BR>amplitude of samples coming from a SndBuf and skips ahead until the level <BR>rises above a threshold.<BR><BR>Not sure how well this would run in real time.<BR><BR>Better, would be something that preprocesses the file with in/out points<BR>so the skips are quick.</BLOCKQUOTE><DIV><BR><BR>But.... It doesn't look like it needs to be realtime. <BR><BR>I'd think about playing the file once and storing the sample locations where the volume drops below a treshold (as well as the ones where it comes back) in a array, then playing it a second time and skipping those sections while writing the results to a new file. in "silent" mode this should be doable faster then realtime. <BR><BR>You could also make a array of the length of the file (in samples) and only write buf.last() =&gt; array[sample++] as long as it's over the treshold. Once the buffer reaches it's end you'd playback the array again and record that, taking care to stop after the highest value that "sample" got to in the first pass. This would be CPU intesive but it's quite clean as a method, I think. <BR><BR>It all stands or falls with the quality of the envelope follower.<BR><BR>I've been thinking about doing something similar to the first option and pre-scanning wavefiles for positive zero-crossings and storing those in a array. This would take extra time when loading a file but from then on you could do very clean loops, for example to loop just a few cycles. I wonder how samplers that have a "snap to zero crossings" setting do this. It might still be quite tricky because not all samplers that do this do it all that well.... <BR><BR>Hope that's of some use.<BR>Kas.<BR></DIV></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 37px; text-indent: -37px; font: normal normal normal 12px/normal Helvetica; color: rgb(0, 0, 0); min-height: 14px; "></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><BR class="khtml-block-placeholder"></DIV> </BLOCKQUOTE></DIV><BR></DIV></BODY></HTML>