Last active
December 23, 2016 11:21
-
-
Save khrlimam/84494e64b3295b7e1fa83a2848655965 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
var omTeloletOm = { | |
lowBoundFreq: 300, //initial frequency value | |
upperBoundFreq: 800, | |
freqState: this.lowBoundFreq, | |
init: function() { | |
context = new(window.AudioContext || window.webkitAudioContext)(); | |
oscilator = context.createOscillator(); | |
oscilator.type = 'sawtooth'; | |
oscilator.frequency.value = this.lowBoundFreq; | |
gain = context.createGain(); | |
gain.gain.value = .7; | |
oscilator.connect(gain); //connect the node | |
oscilator.start(0); | |
}, | |
start: function() { | |
gain.connect(context.destination); | |
}, | |
stop: function() { | |
gain.disconnect(context.destination); | |
}, | |
addFreq: function(frequency) { | |
newFrequency = oscilator.frequency.value+frequency; | |
oscilator.frequency.value = newFrequency; | |
this.freqState = newFrequency; | |
console.log('frequency state = '+ this.freqState); | |
}, | |
subFreq: function(frequency) { | |
newFrequency = oscilator.frequency.value-frequency; | |
oscilator.frequency.value = newFrequency; | |
this.freqState = newFrequency; | |
console.log('frequency state = '+ this.freqState); | |
} | |
}; | |
function increase() { | |
time = Math.floor(100+(Math.random()*50)); | |
setTimeout(function() { | |
omTeloletOm.addFreq(100); | |
if (omTeloletOm.freqState >= omTeloletOm.upperBoundFreq) { | |
return decrease(); | |
} | |
increase(); | |
}, time); | |
} | |
function decrease() { | |
time = Math.floor(100+(Math.random()*50)); | |
setTimeout(function() { | |
omTeloletOm.subFreq(100); | |
if (omTeloletOm.freqState <= omTeloletOm.lowBoundFreq) { | |
return increase(); | |
} | |
decrease(); | |
}, time); | |
} | |
omTeloletOm.init(); | |
omTeloletOm.start(); | |
increase(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment