Skip to content

Instantly share code, notes, and snippets.

@Mr-Kumar-Abhishek
Last active December 8, 2022 22:03
Show Gist options
  • Save Mr-Kumar-Abhishek/822cb666fdd229a1b29d7fa23b4214d6 to your computer and use it in GitHub Desktop.
Save Mr-Kumar-Abhishek/822cb666fdd229a1b29d7fa23b4214d6 to your computer and use it in GitHub Desktop.
Isochronic tone with js from chatGPT
// Set the initial frequency of the oscillator
oscillator.frequency.value = 10;
// Create a setInterval that will update the oscillator's frequency
// every 100 milliseconds
const interval = setInterval(() => {
// Set the oscillator's frequency to a random value between 8 and 12 Hz
oscillator.frequency.value = 8 + Math.random() * 4;
}, 100);
// Stop the oscillator and clear the interval after 10 seconds
setTimeout(() => {
oscillator.stop();
clearInterval(interval);
}, 10000);
// create audio context
const audioCtx = new AudioContext();
// set frequency and duration of isochronic tone
const frequency = 10;
const duration = 5;
// create oscillator
const oscillator = audioCtx.createOscillator();
oscillator.type = "sine";
oscillator.frequency.setValueAtTime(frequency, audioCtx.currentTime);
// create envelope
const envelope = audioCtx.createGain();
envelope.gain.setValueAtTime(0, audioCtx.currentTime);
envelope.gain.linearRampToValueAtTime(1, audioCtx.currentTime + 0.1);
envelope.gain.linearRampToValueAtTime(0, audioCtx.currentTime + duration);
// connect oscillator to envelope
oscillator.connect(envelope);
// connect envelope to output
envelope.connect(audioCtx.destination);
// start oscillator
oscillator.start();
// stop oscillator after duration
oscillator.stop(audioCtx.currentTime + duration);
// Create an AudioContext
const audioContext = new AudioContext();
// Create an OscillatorNode to generate a sine wave
const oscillator = audioContext.createOscillator();
oscillator.type = 'sine';
// Set the frequency of the oscillator to the desired isochronic frequency
const isochronicFrequency = 10; // Hz
oscillator.frequency.value = isochronicFrequency;
// Connect the oscillator to the audio context's destination
oscillator.connect(audioContext.destination);
// Start the oscillator
oscillator.start();
// Set the duration of each pulse in milliseconds
const pulseDuration = 1000; // 1 second
// Create a function that turns the oscillator on and off at regular intervals
const pulseOscillator = () => {
oscillator.stop();
setTimeout(() => {
oscillator.start();
}, pulseDuration);
};
// Call the pulseOscillator function at regular intervals
setInterval(pulseOscillator, pulseDuration * 2);
// Set the frequency and duration of the isochronic tone
var frequency = 10;
var duration = 5;
// Create an oscillator and gain node
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
// Set the frequency and type of the oscillator
oscillator.frequency.value = frequency;
oscillator.type = 'sine';
// Set the gain to 0
gainNode.gain.value = 0;
// Connect the oscillator and gain node to the audio context
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
// Start the oscillator
oscillator.start();
// Fade in the isochronic tone over a duration of 1 second
gainNode.gain.linearRampToValueAtTime(1, audioCtx.currentTime + 1);
// Fade out the isochronic tone over a duration of 1 second
gainNode.gain.linearRampToValueAtTime(0, audioCtx.currentTime + duration - 1);
// create audio context
const audioCtx = new AudioContext();
// Set the frequency and duration of the isochronic tone
var frequency = 555;
var duration = 5;
// Create a function to generate the isochronic tone
function generateIsochronicTone() {
// Create an oscillator and gain node
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
// Set the frequency and type of the oscillator
oscillator.frequency.value = frequency;
oscillator.type = 'sine';
// Set the gain to 0
gainNode.gain.value = 0;
// Connect the oscillator and gain node to the audio context
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
// Start the oscillator
oscillator.start();
// Fade in the isochronic tone over a duration of 1 second
gainNode.gain.linearRampToValueAtTime(1, audioCtx.currentTime + 1);
// Fade out the isochronic tone over a duration of 1 second
gainNode.gain.linearRampToValueAtTime(0, audioCtx.currentTime + duration - 1);
}
// Create a setInterval() function to continuously play the isochronic tone
var interval = setInterval(function() {
generateIsochronicTone();
}, duration * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment