mardi 27 janvier 2015

Filtering and Web Audio

I'm trying to implement some filters using Web Audio.


I have the below set-up and only the lowpass filter works, but even then I can't seem to get it to stop.



//Creating filters, setting their types and setting up booleans for later use.
//Lowpass Filter Setup
lowpass = context.createBiquadFilter();
lp_bool=false;
lowpass.type="lowpass";
lowpass.type=LOWPASS;

//Highpass Filter Setup
highpass = context.createBiquadFilter();
highpass.type="highpass";
highpass.type=HIGHPASS;
hp_bool=false;

//Bandpass Filter Setup
bandpass = context.createBiquadFilter();
bandpass.type="bandpass";
bandpass.type=BANDPASS;
bp_bool=false;

//Lowshelf Filter Setup
lowshelf = context.createBiquadFilter();
lowshelf.type="lowshelf";
lowshelf.type=LOWSHELF;
ls_bool=false;
/*
lowshelf.frequency.value = 440;
lowshelf.gain.value = 0;*/

//Highshelf Filter Setup
highshelf = context.createBiquadFilter();
highshelf.type="highshelf";
highshelf.type=HIGHSHELF;
hs_bool=false;/*
highshelf.frequency.value = 440;
highshelf.gain.value = 0;*/

//Peaking Filter Setup
peaking = context.createBiquadFilter();
peaking.type="peaking";
peaking.type=PEAKING;
pk_bool=false;/*
peaking.frequency.value = 440;
peaking.Q.value = 0;
peaking.gain.value = 0;*/

//Notch Filter Setup
notch = context.createBiquadFilter();
notch.type="notch";
notch.type=NOTCH;
nh_bool=false;/*
notch.frequency.value = 440;
notch.Q.value = 0;*/

//Allpass Filter Setup
allpass = context.createBiquadFilter();
allpass.type="allpass";
allpass.type=ALLPASS;
ap_bool=false;/*
allpass.frequency.value = 440;
allpass.Q.value = 0;*/
};


Toggle Function:



function toggle_filter(filter_name,filter_bool) {
masterVolume.disconnect(0);
// Check if we want to enable the filter.
if (filter_bool==false) {
// Connect through the filter.
masterVolume.connect(filter_name);
filter_name.connect(context.destination);
filter_bool=true;
} else if(filter_bool==true){
filter_name.disconnect(0);
// Otherwise, connect directly.
masterVolume.connect(context.destination);
filter_bool=false;
}
};


Called from buttons:



<div id="filter-container">
<a onclick="toggle_filter(lowpass,lp_bool);" id="filter-button">Lowpass</a>
<a onclick="toggle_filter(highpass,hp_bool);" id="filter-button">Highpass</a>
<a onclick="toggle_filter(bandpass,bp_bool);" id="filter-button">Bandpass</a>
<a onclick="toggle_filter(lowshelf,ls_bool);" id="filter-button">Lowshelf</a>
<a onclick="toggle_filter(highshelf,hs_bool);" id="filter-button">Highshelf</a>
<a onclick="toggle_filter(peaking,pk_bool);" id="filter-button">Peaking</a>
<a onclick="toggle_filter(notch,nh_bool);" id="filter-button">Notch</a>
<a onclick="toggle_filter(allpass,ap_bool);" id="filter-button">Allpass</a>
<div>


Can anyone point me in the direction of where I'm going wrong?


Aucun commentaire:

Enregistrer un commentaire