-
Notifications
You must be signed in to change notification settings - Fork 0
/
sonido.js
41 lines (33 loc) · 981 Bytes
/
sonido.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
console.log('veamos si funciona');
const button1 = document.querySelector('.js-button1');
const button2 = document.querySelector('.js-button2');
const button3 = document.querySelector('.js-button3');
const button4 = document.querySelector('.js-button4');
var context = new AudioContext();
function jsNota(frecuencia){
var o = context.createOscillator();
const g = context.createGain();
o.connect(g);
o.type = "sawtooth";
o.frequency.value = frecuencia;
g.connect(context.destination);
o.start(0);
g.gain.exponentialRampToValueAtTime(0.00001,context.currentTime +1);
}
const jsNota1 = function(){
jsNota(174.614);
}
const jsNota2 = function(){
jsNota(195.998);
}
const jsNota3 = function(){
jsNota(220.000);
}
const jsNota4 = function(){
jsNota(246.942);
}
button1.addEventListener('click', jsNota1);
button2.addEventListener('click', jsNota2);
button3.addEventListener('click', jsNota3);
button4.addEventListener('click', jsNota4);