Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid clicking. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions javascripts/identify-and-treat.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ function createToneMaker(toneGeneratorNodes) {
return toneGeneratorNodes.gainNode.gain.value;
},
set volume(v) {
toneGeneratorNodes.gainNode.gain.value = v;
toneGeneratorNodes.gainNode.gain.cancelScheduledValues(0);
toneGeneratorNodes.gainNode.gain.linearRampToValueAtTime(v, toneGeneratorNodes.audioContext.currentTime + 0.01);
},
get frequency() {
return toneGeneratorNodes.toneGenerator.frequency.value;
Expand Down Expand Up @@ -104,7 +105,8 @@ function createACRNTreatment(toneGeneratorNodes) {
var generatedTones = [];
// Queue five cycles worth of frequency and volume changes
// Three cycles of four random tones
toneGeneratorNodes.gainNode.gain.setValueAtTime(volume, tonesQueuedUntil);
toneGeneratorNodes.gainNode.gain.setValueAtTime(0, tonesQueuedUntil);
toneGeneratorNodes.gainNode.gain.linearRampToValueAtTime(volume, tonesQueuedUntil + 0.01);
for(var i = 0; i < 3; i++) {
var randomTones = shuffle(treatmentTones);
for(var j = 0; j < randomTones.length; j++) {
Expand All @@ -115,7 +117,8 @@ function createACRNTreatment(toneGeneratorNodes) {
console.log(generatedTones);

// Two cycles of silence
toneGeneratorNodes.gainNode.gain.setValueAtTime(0, tonesQueuedUntil + (3 * CYCLE_PERIOD));
toneGeneratorNodes.gainNode.gain.setValueAtTime(volume, tonesQueuedUntil + (3 * CYCLE_PERIOD));
toneGeneratorNodes.gainNode.gain.linearRampToValueAtTime(0, tonesQueuedUntil + (3 * CYCLE_PERIOD) + 0.01);

// Update tonesQueuedUntil
tonesQueuedUntil += 5 * CYCLE_PERIOD;
Expand All @@ -137,7 +140,7 @@ function createACRNTreatment(toneGeneratorNodes) {
function stopTreatment() {
if(active) {
toneGeneratorNodes.gainNode.gain.cancelScheduledValues(0);
toneGeneratorNodes.gainNode.gain.value = 0;
toneGeneratorNodes.gainNode.gain.linearRampToValueAtTime(0, toneGeneratorNodes.audioContext.currentTime + 0.01);
toneGeneratorNodes.toneGenerator.frequency.cancelScheduledValues(0);
clearTimeout(currentTimeout);
active = false;
Expand Down