Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
Web audio API oscillator onstarted event

The Web Audio API oscillator allows a script to be alerted when the oscillator stops with onended.

How can the script be alerted when it starts?

const ac = new AudioContext()

const osc = ac.createOscillator()
osc.type = 'sawtooth'
osc.connect(ac.destination)

osc.onstarted = () => console.log('ended!') // This doesn't work :'(
osc.onended = () => console.log('ended!') // :)

osc.start(5)
osc.stop(7)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The ended event is the only event that an OscillatorNode emits. I guess this is because this event is inherited from the AudioScheduledSourceNode interface.

Another node which inherits that interface is the AudioBufferSourceNode. And for an AudioBufferSourceNode it's often not so easy to tell when it actually ends which is why I think the event exists. This could also be the reason why there is no started event.

Anyway you can re-build that functionality by using another AudioScheduledSourceNode. I would recommend to use a ConstantSourceNode since it is the one which is the most lightweight.

const constantSourceNode = new ConstantSourceNode(ac);

constantSourceNode.onended = () => {
    console.log('osc started');
};
constantSourceNode.start();
constantSourceNode.stop(5);

Please note that the ended events are not very accurate. They get triggered on the audio thread and need to travel back to the main thread where they finally get fired when there is some time to do so.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda