You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constcontext=newAudioContext();constkeys=document.querySelectorAll('.key');keys.forEach(key=>{key.addEventListener('mousedown',()=>{constnote=key.id;constoscillator=context.createOscillator();oscillator.type='sine';// you can try different oscillator types hereoscillator.frequency.value=getFrequency(note);oscillator.connect(context.destination);oscillator.start();key.classList.add('active');});key.addEventListener('mouseup',()=>{constoscillator=context.createOscillator();oscillator.type='sine';// you can try different oscillator types hereoscillator.frequency.value=getFrequency(note);oscillator.connect(context.destination);oscillator.stop();oscillator.disconnect();key.classList.remove('active');});});functiongetFrequency(note){constfrequencies={'c': 261.63,'c-sharp': 277.18,'d': 293.66,'d-sharp': 311.13,'e': 329.63,'f': 349.23,'f-sharp': 369.99,'g': 392.00,'g-sharp': 415.30,'a': 440.00,'a-sharp': 466.16,'b': 493.88};returnfrequencies[note];}