getFrequencyResponse() 方法在 BiquadFilterNode interface takes the current filtering algorithm's settings and calculates the frequency response for frequencies specified in a specified array of frequencies.

The two output arrays, magResponseOutput and phaseResponseOutput , must be created before calling this method; they must be the same size as the array of input frequency values ( frequencyArray ).

句法

BiquadFilterNode.getFrequencyResponse(frequencyArray, magResponseOutput, phaseResponseOutput);
					

参数

frequencyArray
Float32Array containing an array of frequencies, specified in Hertz, which you want to filter.
magResponseOutput
Float32Array to receive the computed magnitudes of the freqency response for each frequency value in the frequencyArray . For any frequency in frequencyArray whose value is outside the range 0.0 to sampleRate /2 (where sampleRate is the sample rate of the AudioContext ), the corresponding value in this array is NaN . These are unitless values.
phaseResponseOutput
Float32Array to receive the computed phase response values in radians for each frequency value in the input frequencyArray . For any frequency in frequencyArray whose value is outside the range 0.0 to sampleRate /2 (where sampleRate is the sample rate of the AudioContext ), the corresponding value in this array is NaN .

返回值

undefined

异常

InvalidAccessError

The three arrays provided are not all of the same length.

范例

In the following example we are using a biquad filter on a media stream (for the full demo, see our stream-source-buffer demo live, or read the source .) As part of this demo, we get the frequency responses for this biquad filter, for five sample frequencies. We first create the Float32Array s we need, one containing the input frequencies, and two to receive the output magnitude and phase values:

var myFrequencyArray = new Float32Array(5);
myFrequencyArray[0] = 1000;
myFrequencyArray[1] = 2000;
myFrequencyArray[2] = 3000;
myFrequencyArray[3] = 4000;
myFrequencyArray[4] = 5000;
var magResponseOutput = new Float32Array(5);
var phaseResponseOutput = new Float32Array(5);
					

Next we create a <ul> element in our HTML to contain our results, and grab a reference to it in our JavaScript:

<p>Biquad filter frequency response for: </p>
<ul class="freq-response-output">
</ul>
					
var freqResponseOutput = document.querySelector('.freq-response-output');
					

Finally, after creating our biquad filter, we use getFrequencyResponse() to generate the response data and put it in our arrays, then loop through each data set and output  them in a human-readable list at the bottom of the page:

var biquadFilter = audioCtx.createBiquadFilter();
biquadFilter.type = "lowshelf";
biquadFilter.frequency.value = 1000;
biquadFilter.gain.value = range.value;
  ...
function calcFrequencyResponse() {
  biquadFilter.getFrequencyResponse(myFrequencyArray,magResponseOutput,phaseResponseOutput);
  for(i = 0; i <= myFrequencyArray.length-1;i++){
    var listItem = document.createElement('li');
    listItem.innerHTML = '<strong>' + myFrequencyArray[i] + 'Hz</strong>: Magnitude ' + magResponseOutput[i] + ', Phase ' + phaseResponseOutput[i] + ' radians.';
    freqResponseOutput.appendChild(listItem);
  }
}
calcFrequencyResponse();
					

规范

规范 状态 注释
Web 音频 API
The definition of 'getFrequencyResponse()' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getFrequencyResponse Chrome 14 Edge 12 Firefox 25 IE 不支持 No Opera 15 Safari 6 WebView Android Yes Chrome Android 18 Firefox Android 26 Opera Android 14 Safari iOS Yes Samsung Internet Android 1.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: