123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id = "test"></div>
            
          
!
            
              button {
  display: inline-block;
  width: 4em;
  height: 4em;
  margin: 2px;
  text-align: center;
}
#test {
  width: 673px;
  border: 1px solid #d9d9d9;
  margin: 1em auto;
}

            
          
!
            
              const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
//el array de las frecuencias utilizadas: 
const frecuencias = [4186.01, 3951.07, 3729.31, 3520.00, 3322.44, 3135.96, 2959.96, 2793.83, 2637.02, 2489.02, 2349.32, 2217.46, 2093.00, 1975.53, 1864.66, 1760.00, 1661.22, 1567.98, 1479.98, 1396.91, 1318.51, 1244.51, 1174.66, 1108.73, 1046.50, 987.767, 932.328, 880.000, 830.609, 783.991, 739.989, 698.456, 659.255, 622.254, 587.330, 554.365, 523.251, 493.883, 466.164, 440.000, 415.305, 391.995, 369.994, 349.228, 329.628, 311.127, 293.665, 277.183, 261.626, 246.942, 233.082, 220.000, 207.652, 195.998, 184.997, 174.614, 164.814, 155.563, 146.832, 138.591, 130.813, 123.471, 116.541, 110.000, 103.826, 97.9989, 92.4986, 87.3071, 82.4069, 77.7817, 73.4162, 69.2957, 65.4064, 61.7354, 58.2705, 55.0000, 51.9130, 48.9995, 46.2493, 43.6536, 41.2035, 38.8909, 36.7081, 34.6479];
//el array de los sonidos
let sonidosRy = [];
// una clase que construie los sonidos y los botones (teclas)
class Sonido{
  constructor(frec,waveform){
    this.frequency = frec;// la frecuencia
    this.waveform = waveform;// la forma de onda
    this.duracion = .75;// la duración en segundos
    this.nuevoBoton();
  }
  
  nuevoBoton(){// crea in nuevo boton y lo agrega al DOM
    this.button = document.createElement("button");
    this.button.textContent = Math.round(this.frequency);
    test.appendChild(this.button);
  }
  
  reproducir(){
   // crea un nuevo oscilador
   this.oscilador = audioCtx.createOscillator();
   // crea un nuevo nodo de ganancia 
   this.gain = audioCtx.createGain();
   // establece el valor inicial del volumen del sonido 
   this.gain.gain.value = .25;
   // establece el tipo de oscilador  
   this.oscilador.type = this.waveform;
   // y el valor de la frecuencia 
   this.oscilador.frequency.value = this.frequency;
   // el volumen del sonido baja exponencialmente     
   this.gain.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + this.duracion);
   // conecta el oscilador con el nodo de ganancia 
   this.oscilador.connect(this.gain);
   // y la ganancia con el dispositivo de destino
   this.gain.connect(audioCtx.destination);
   // inicia el oscilador 
   this.oscilador.start(audioCtx.currentTime);
   // para el oscilador después de un tiempo (this.duracion) 
   this.oscilador.stop(audioCtx.currentTime + this.duracion); 
  }  
}


// crea los sonidos y los guarda en el array de los sonidos: sonidosRy
frecuencias.map((f) => {
  let sonido = new Sonido(f,"triangle");
  sonidosRy.push(sonido); 
});
// al pasar con el ratón por encima de los botones, se reproduce el sonido correspondiente
sonidosRy.map((s) =>{
  s.button.addEventListener("mouseover",function(){s.reproducir()},false)
});
  


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console