<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://sound.bai-hua.org/index.php?action=history&amp;feed=atom&amp;title=Inverted-waveform-cancellation.js</id>
		<title>Inverted-waveform-cancellation.js - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://sound.bai-hua.org/index.php?action=history&amp;feed=atom&amp;title=Inverted-waveform-cancellation.js"/>
		<link rel="alternate" type="text/html" href="https://sound.bai-hua.org/index.php?title=Inverted-waveform-cancellation.js&amp;action=history"/>
		<updated>2026-10-01T15:48:11Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>https://sound.bai-hua.org/index.php?title=Inverted-waveform-cancellation.js&amp;diff=153&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;&lt;pre&gt; /*   Inverted Waveform Cancellation   Using the Mozilla Audio Data API   by F1LT3R @ http://Bocoup.com */  // This example is illustrative and not enhanced for performance ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://sound.bai-hua.org/index.php?title=Inverted-waveform-cancellation.js&amp;diff=153&amp;oldid=prev"/>
				<updated>2011-02-08T06:42:31Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt; ‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Inverted Waveform Cancellation   Using the Mozilla Audio Data API   by F1LT3R @ http://Bocoup.com: &lt;/span&gt;  // This example is illustrative and not enhanced for performance ...&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
  Inverted Waveform Cancellation&lt;br /&gt;
  Using the Mozilla Audio Data API&lt;br /&gt;
  by F1LT3R @ http://Bocoup.com&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// This example is illustrative and not enhanced for performance&lt;br /&gt;
 &lt;br /&gt;
// Define event in global/&amp;quot;window&amp;quot; scope&lt;br /&gt;
var audioAvailable;&lt;br /&gt;
 &lt;br /&gt;
// When the DOM has loaded...&lt;br /&gt;
function init(){&lt;br /&gt;
  &lt;br /&gt;
  // Variable declarations&lt;br /&gt;
  var inputSamples, outputSamples, chan1, chan2, i, len,&lt;br /&gt;
      output = document.createElement(&amp;#039;audio&amp;#039;),   &lt;br /&gt;
      debug = document.getElementById(&amp;#039;debug&amp;#039;),&lt;br /&gt;
      inverted = 1;&lt;br /&gt;
         &lt;br /&gt;
  // Toggle inversion on Channel 2&lt;br /&gt;
  document.getElementById(&amp;#039;invertCheckbox&amp;#039;).addEventListener(&amp;#039;click&amp;#039;, function(){ inverted*=-1; },false);&lt;br /&gt;
  &lt;br /&gt;
  // Initiate the &lt;br /&gt;
  output.mozSetup(2, 44100, 1);&lt;br /&gt;
  &lt;br /&gt;
  // WHEN SOUND HAPPENS.........&amp;gt;&lt;br /&gt;
  audioAvailable = function audioAvailable(event){&lt;br /&gt;
  &lt;br /&gt;
    // Alias buffer samples to a more conveinient name&lt;br /&gt;
    inputSamples = event.frameBuffer;&lt;br /&gt;
        &lt;br /&gt;
    // Set new length and clear channel data&lt;br /&gt;
    var len = inputSamples.length, chan1 = [], chan2 = [], outputSamples = [];&lt;br /&gt;
       &lt;br /&gt;
    // Copy Audio-Data from &amp;lt;audio&amp;gt; input to Channel 1 into a Native JS Array&lt;br /&gt;
    for(i=0;i &amp;lt; len; i++){&lt;br /&gt;
      chan1[i]= inputSamples[i];&lt;br /&gt;
    }  &lt;br /&gt;
 &lt;br /&gt;
    // Copy inverted Audio-Data from &amp;lt;audio&amp;gt; input to Channel 2 into a Native JS Array&lt;br /&gt;
    for(i=0;i &amp;lt; len; i++){&lt;br /&gt;
      chan2[i] = inputSamples[i]*-inverted;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    // Mix down Channel 1 and Channel 2&lt;br /&gt;
    for(i=0;i &amp;lt; len; i++){&lt;br /&gt;
      outputSamples[i] = (chan1[i] + chan2[i]) / 2;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // Display 5 samples from each buffer-written-(event at C level)&lt;br /&gt;
    debug.innerHTML = &amp;quot;&amp;quot;;&lt;br /&gt;
    for(i=0;i&amp;lt;5;i++){&lt;br /&gt;
      debug.innerHTML += &amp;quot;&amp;lt;b&amp;gt;&amp;quot;+event.time.toFixed(2) + &amp;quot;:&amp;lt;/b&amp;gt; &amp;amp;nbsp;&amp;quot;+ outputSamples[i]+&amp;quot;&amp;lt;br&amp;gt;&amp;quot;;&lt;br /&gt;
    }     &lt;br /&gt;
    &lt;br /&gt;
    // Output mixed samples to &amp;lt;audio&amp;gt; element&lt;br /&gt;
    output.mozWriteAudio(outputSamples);&lt;br /&gt;
   &lt;br /&gt;
  };    &lt;br /&gt;
      &lt;br /&gt;
  var input = document.getElementById(&amp;#039;input&amp;#039;);&lt;br /&gt;
  input.volume = 0;&lt;br /&gt;
  input.addEventListener(&amp;quot;MozAudioAvailable&amp;quot;, audioAvailable, false);&lt;br /&gt;
&lt;br /&gt;
  //.addEventListener(&amp;#039;mozAudioAvailable&amp;#039;, function(){ mozAudioAvailable(event) }, false);&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
// Call ready event when DOM is loaded&lt;br /&gt;
addEventListener(&amp;#039;DOMContentLoaded&amp;#039;, function(){init();}, false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>