Created
December 19, 2014 23:55
-
-
Save Frijol/b4d6d647ef1b5b4a3c4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('tesselate') ({ | |
modules: { | |
A: ['ambient-attx4', 'ambientL'], | |
C: ['ambient-attx4', 'ambientR'] | |
}, | |
}, function(tessel, modules) { | |
var left = modules.ambientL; | |
var right = modules.ambientR; | |
console.log('For left module calibration:'); | |
sample(left, function (leftData) { | |
console.log('For right module calibration:'); | |
sample(right, function (rightData) { | |
console.log('Left:', leftData, 'avg:', average(leftData)); | |
console.log('Right:', rightData, 'avg:', average(rightData)); | |
console.log('Set left trigger to', average(leftData)); | |
console.log('Set right trigger to', average(rightData)); | |
process.exit(); | |
}); | |
}); | |
}); | |
function sample (module, callback) { | |
console.log('Position noisemaker (snapping fingers, clapper, etc.) at the distance from the module that you want to trigger from.'); | |
console.log('Make the noise four times.'); | |
var collector = []; | |
module.setSoundTrigger(0.025); | |
module.on('sound-trigger', function(data) { | |
module.clearSoundTrigger(); | |
if (collector.length < 3) { | |
console.log('Sample collected.'); | |
collector.push(data); | |
setTimeout(function () { | |
module.setSoundTrigger(0.1); | |
}, 250); | |
} else { | |
console.log('Sampling complete.'); | |
callback(collector); | |
} | |
}); | |
} | |
function average (arr) { | |
var sum = 0; | |
for (var i in arr) { | |
sum += arr[i]; | |
} | |
return sum / arr.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment