How to connect a JQuery UI slider & a Web Audio API gainNode
-
11-12-2019 - |
Question
I am trying to connect a JQuery slider to a gain node of an oscillator using the Web Audio API.
The oscillator works, there is a working gain slider and there is a JQuery slider. I want the JQuery slider to control the gain like the other slider does.
Here is the code thus far
Solution
Here you go: http://jsfiddle.net/JCTJj/19/
$(function() {
var webSlider = document.getElementById('volume');
var output = $('#gain');
var sliderParams = {
'orientation': "vertical",
'range': "min",
'min': 0,
'max': 1,
'animate': false,
'step': 0.01,
'slide': function(event, ui) {
window.gainNode.gain.value = ui.value;
output.val(window.gainNode.gain.value);
},
'stop': function(event, ui) {
console.log(window.gainNode.gain.value);
}
};
$('#sliderOne').slider(sliderParams);
webSlider.addEventListener('change', function () {
window.gainNode.gain.value = this.value;
output.val(window.gainNode.gain.value);
});
});
OTHER TIPS
your gain function should recieve a value like
function gain(value) {
gainNode.gain.value = value;
}
Then in jQuery slider do something like
slide: function( event, ui ) {
gain(ui.value);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow