(function(){
  'use strict';

  var targetChannel = null;
  var userChannel = null;
  var accuracy = 0.05;

  var euclideanDistance = function(a,b){
    if(a.length != b.length){
      throw new Error('vectors differently sized');
    }
    var x = 0;
    for(var i = 0; i < a.length; i++){
      x+=Math.pow(a[i]-b[i],2);
    }
    return Math.sqrt(x);
  };

  var randomNormalisedVec3 = function(){
    return [Math.random(),Math.random(),Math.random()];
  };

  var normalisationVector = [1/360,1/360,1/180];
  var normalisationOffsetVector = [0,0.5,0.5];

  var normaliseOrientation = function(o){
    return [
      o[0]*normalisationVector[0]+normalisationOffsetVector[0],
      o[1]*normalisationVector[1]+normalisationOffsetVector[1],
      o[2]*normalisationVector[2]+normalisationOffsetVector[2],
    ];
  };

  var ac = new AudioContext();

  var ChannelSynth = function(pan){
    this.osc = ac.createOscillator();
    this.lfo = ac.createOscillator();
    this.fil = ac.createBiquadFilter();
    this.pan = ac.createStereoPanner();
    this.lfo.connect(this.osc.frequency);
    this.osc.connect(this.fil);
    this.fil.connect(this.pan);
    this.pan.connect(ac.destination);

    this.osc.type = 'square';
    this.lfo.type = 'sine';
    this.fil.Q.value = 30;

    this.lfo.start(0);
    this.osc.start(0);

    this.applyNormalisedParameterVector = function(vec){
      // DEBUGGING
      var log = false;
      for(var i = 0; i < vec.length; i++){
        if(!isFinite(vec[i])){
          log = true;
        }
      }
      if(log){
        console.log(vec);
      }
      // /DEBUGGING
      this.osc.frequency.value = 100+vec[0]*900;
      this.lfo.frequency.value = 10*vec[1];
      this.fil.frequency.value = 50+vec[2]*2000;
    };

    this.stop = function(){
      this.osc.stop();
    };

    this.pan.pan.value = pan==="left"?-0.999:0.999;
  };

  document.addEventListener('DOMContentLoaded',function(){
    console.log('documentReady');
    var resetTargetChannelParametersButton = document.createElement('button');
    resetTargetChannelParametersButton.appendChild(document.createTextNode('Reset'));
    var startSoundButton = document.createElement('button');
    startSoundButton.appendChild(document.createTextNode('Start'));
    var targetSound = [0,0,0];
    resetTargetChannelParametersButton.addEventListener("click",resetTargetChannel);
    startSoundButton.addEventListener("click",function(){
      if(targetChannel){
        targetChannel.stop();
        targetChannel = null;
      }
      if(userChannel){
        userChannel.stop();
        userChannel = null;
      }
      targetChannel = new ChannelSynth("right");
      userChannel = new ChannelSynth("left");
      resetTargetChannel();

      var displayRanges = {
        alpha:document.getElementById('alpha'),
        beta:document.getElementById('beta'),
        gamma:document.getElementById('gamma')
      };

      if (window.DeviceOrientationEvent) {
        window.addEventListener("deviceorientation", function () {
          var npv = normaliseOrientation([event.alpha,event.beta, event.gamma]);
          console.log(npv);
          if(npv[0] > targetSound[0]-accuracy && npv[0] < targetSound[0]+accuracy)
          userChannel.applyNormalisedParameterVector(npv);
          displayRanges.alpha.value = event.alpha;
          displayRanges.beta.value = event.beta;
          displayRanges.gamma.value = event.gamma;
        }, true);
      }
    });
    document.body.appendChild(resetTargetChannelParametersButton);
    document.body.appendChild(startSoundButton);
    var resetTargetChannel = function(){
      targetSound = randomNormalisedVec3();
      targetChannel.applyNormalisedParameterVector(targetSound);
    }
  });
})();

@@ -96,16 +96,18 @@
 acy = 0.
+00
 05;%0A%0A  v
@@ -2348,16 +2348,27 @@
 %22click%22,
+function()%7B
 resetTar
@@ -2377,16 +2377,20 @@
 tChannel
+();%7D
 );%0A    s
@@ -3161,17 +3161,24 @@
  if(
+Math.abs(
 npv%5B0%5D
- %3E 
+-
 targ
@@ -3191,17 +3191,20 @@
 d%5B0%5D
--
+) %3C 
 accuracy
  && 
@@ -3203,45 +3203,56 @@
 racy
- && npv%5B0%5D %3C targetSound%5B0%5D+accuracy)
+)%7B%0A            resetTargetChannel();%0A          %7D
 %0A   
@@ -3763,16 +3763,17 @@
 );%0A    %7D
+;
 %0A  %7D);%0A%7D

Add old changes, not sure what they do