Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
36
Task/Musical-scale/JavaScript/musical-scale.js
Normal file
36
Task/Musical-scale/JavaScript/musical-scale.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Sample Page</title>
|
||||
<script>
|
||||
function musicalScale(freqArr){
|
||||
// create web audio api context
|
||||
var AudioContext = window.AudioContext || window.webkitAudioContext;
|
||||
var audioCtx = new AudioContext();
|
||||
|
||||
// create oscillator and gain node
|
||||
var oscillator = audioCtx.createOscillator();
|
||||
var gainNode = audioCtx.createGain();
|
||||
|
||||
// connect oscillator to gain node to speakers
|
||||
oscillator.connect(gainNode);
|
||||
gainNode.connect(audioCtx.destination);
|
||||
|
||||
// set frequencies to play
|
||||
duration = 0.5 // seconds
|
||||
freqArr.forEach(function (freq, i){
|
||||
oscillator.frequency.setValueAtTime(freq, audioCtx.currentTime + i * duration);
|
||||
});
|
||||
|
||||
// start playing!
|
||||
oscillator.start();
|
||||
// stop playing!
|
||||
oscillator.stop(audioCtx.currentTime + freqArr.length * duration);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="musicalScale([261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25]);">Play scale</button>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue