Created
January 22, 2023 05:29
-
-
Save Mr-Kumar-Abhishek/5fea0ca3ae5eb9794b7ac0e34716dd22 to your computer and use it in GitHub Desktop.
Revisions
-
Mr-Kumar-Abhishek created this gist
Jan 22, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ // 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