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

71
Vistas
Problems controlling the volume of the Web Audio API

I found a script on this forum at this link for looping an audio clip using the Web Audio API, and it works well, however I’m having problems working out how to control the volume of it. Apparently the key is to use “createGain”, but I’ve been having difficulties getting that to work. (I also tried the “Loopify” suggestion on that page, but Loopify doesn’t let you control the volume.)

See in the script where the comment says “START TRYING TO SET THE VOLUME”. I’m think I’m close with it, but it’s just not working. The sample is trying to reduce the volume to half.

// initialize the audio
var actx = new (AudioContext || webkitAudioContext)(), src="lo-fi-dub-beat_70bpm.wav", audioData, srcNode;  

// load the audio
fetch(src, {mode: "cors"}).then(function(resp) {return resp.arrayBuffer()}).then(decode);

// START TRYING TO SET THE VOLUME

var loopAudioGainNode = actx.createGain();
loopAudioGainNode.connect(actx.destination); // <- Perhaps this is needed?
loopAudioGainNode.gain.value = .5;  

// END TRYING TO SET THE VOLUME

// decode the audio and start it playing
function decode (buffer) { actx.decodeAudioData(buffer, playLoop); }

// set a new source node as needed after the audio was stopped
function playLoop (abuffer) {

    if (!audioData) audioData = abuffer;  // create a reference for control buttons

    srcNode = actx.createBufferSource();  // create audio source
    srcNode.buffer = abuffer;             // use decoded buffer
    srcNode.connect(actx.destination);    // create output
    srcNode.loop = true;                  // takes care of perfect looping
    srcNode.start();                      // play...
        
}

Thanks for your help.

about 4 years ago · Juan Pablo Isaza
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