javascript - Web audio API filter is not working -
so i'm creating synthesizer in browser , want add few filters it. created filter stuff , connect oscillator filter , fiter audio destination. when choose lowpass filter play, error in console , no effects being added:
the provided value '3' not valid enum value of type biquadfiltertype. snippet of code:
function init() { octavenumber = document.getelementbyid("octavenum"); audioctx = new (window.audiocontext || window.webkitaudiocontext); osc = audioctx.createoscillator(); volume = audioctx.creategain(); filter = audioctx.createbiquadfilter(); osc.connect(filter); volume.connect(audioctx.destination); booleanval = false; osc.frequency.value = freqslider.value osc.start(); gaindisplay.innerhtml = gainslider.value; } lowpass.addeventlistener("click", function(event) { filter.type = 3; // in case it's lowshelf filter filter.frequency.value = 440; filter.q.value = 0; filter.gain.value = 0; }) function start() { ui('start'); volume.gain.value = gainslider.value; filter.connect(volume); } what mean?
the error see pretty self explanatory. basically, filter.type = 3; isn't valid biquadfilternode type which, mdn lists, "is string (enum) value defining kind of filtering algorithm node implementing."
it's values strings: 'highpass', 'bandpass', 'lowshelf', 'highshelf', 'peaking', 'notch' , 'allpass'.
you can find meanings on mdn page.
Comments
Post a Comment