Skip to content

Instantly share code, notes, and snippets.

@Mr-Kumar-Abhishek
Created January 22, 2023 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mr-Kumar-Abhishek/5fea0ca3ae5eb9794b7ac0e34716dd22 to your computer and use it in GitHub Desktop.
Save Mr-Kumar-Abhishek/5fea0ca3ae5eb9794b7ac0e34716dd22 to your computer and use it in GitHub Desktop.
isochronic-tone.js
// Create an audio context
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Create an oscillator node
const oscillator = audioCtx.createOscillator();
// Set the frequency of the oscillator
oscillator.frequency.value = 1000;
// Create a gain node
const gainNode = audioCtx.createGain();
// Connect the oscillator to the gain node
oscillator.connect(gainNode);
// Connect the gain node to the audio context's destination
gainNode.connect(audioCtx.destination);
// Start the oscillator
oscillator.start();
// Set the gain to 0
gainNode.gain.value = 0;
let flip = true
function toggleTone() {
if (flip) {
flip = false
gainNode.gain.value = 1
} else {
flip = true
gainNode.gain.value = 0.1
}
}
// Set the tone to turn on and off at specific intervals
setInterval(toggleTone, 500); // toggle tone every 500ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment