I am trying to set volume over 1 on an audio element, following this article.
https://cwestblog.com/2017/08/17/html5-getting-more-volume-from-the-web-audio-api/
I need to be able to set it more than once, so i've set a global array to store the different results in so that I can adjust based on participants.
This does not seem to be working though, to me I can't tell any difference when the gain is set, am I doing something wrong?
window.audioGainParticipants = [];
function amplifyMedia(participant_id, mediaElem, multiplier) {
const exists = window.audioGainParticipants.find(
(x) => x.participant_id === participant_id
);
let result = null;
if (exists) {
result = exists.result;
} else {
var context = new (window.AudioContext || window.webkitAudioContext)();
result = {
context: context,
source: context.createMediaElementSource(mediaElem),
gain: context.createGain(),
media: mediaElem,
amplify: function (multiplier) {
result.gain.gain.value = multiplier;
},
getAmpLevel: function () {
return result.gain.gain.value;
},
};
result.source.connect(result.gain);
result.gain.connect(context.destination);
window.audioGainParticipants.push({ participant_id, result });
}
result.amplify(multiplier);
}
I call this like this...
const audioElement = document.getElementById(
`audio-${participantId}`
);
amplifyMedia(
`audio-${participantId}`,
audioElement,
volume // number between 0-2
);