Skip to content

Instantly share code, notes, and snippets.

@vitaliy-bobrov
Created June 11, 2019 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitaliy-bobrov/6b62630ee54a1c299302c8ef8d891d4c to your computer and use it in GitHub Desktop.
Save vitaliy-bobrov/6b62630ee54a1c299302c8ef8d891d4c to your computer and use it in GitHub Desktop.
const control = document.querySelector('.gain-control');
control.addEventListener('change', (event) => {
const parsed = parseFloat(event.target.value);
const value = Number.isNaN(parsed) ? 1 : parsed;
const clamped = clamp(value);
gainNode.gain.setTargetAtTime(clamped, context.currentTime, 0.01);
});
function clamp(min, max, value) {
return Math.min(Math.max(value, min), max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment