BiquadFilterNode: Q 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

BiquadFilterNode 介面的 Q 屬性是一個 a-rateAudioParam,它是一個雙精度浮點數,代表 Q 值,或稱品質因數

一個 AudioParam。它的 defaultValue1,其 minValuemaxValue 為 ±(2128 - 2104),或約 ±3.403e38。這是單精度浮點數的範圍。

其實際值範圍取決於濾波器的 type

  • 對於 lowpasshighpassQ 值被解釋為 dB。對於這些濾波器,值範圍是 [-Q, Q],其中 Q 是 10Q/20 不會溢位上述邊界的最大值。這約等於 770.63678。
  • 對於 bandpassnotchallpasspeakingQ 值與濾波器的頻寬相關,且應為正數,但沒有比上述更嚴格的最大值。
  • 它不用於 lowshelfhighshelf 濾波器。

注意:雖然返回的 AudioParam 是隻讀的,但它所代表的值並非如此。

示例

以下示例展示了使用 AudioContext 建立 Biquad 濾波器節點的基​​本用法。有關更完整和實際的應用示例/資訊,請檢視我們的 Voice-change-O-matic 演示(相關程式碼請參見 app.js 的 108-193 行)。

js
const audioCtx = new AudioContext();

// Set up the different audio nodes we will use for the app
const analyser = audioCtx.createAnalyser();
const distortion = audioCtx.createWaveShaper();
const gainNode = audioCtx.createGain();
const biquadFilter = audioCtx.createBiquadFilter();
const convolver = audioCtx.createConvolver();

// Connect the nodes together

source = audioCtx.createMediaStreamSource(stream);
source.connect(analyser);
analyser.connect(distortion);
distortion.connect(biquadFilter);
biquadFilter.connect(convolver);
convolver.connect(gainNode);
gainNode.connect(audioCtx.destination);

// Manipulate the Biquad filter

biquadFilter.type = "lowshelf";
biquadFilter.frequency.value = 1000;
biquadFilter.gain.value = 25;

biquadFilter.type = "peaking";
biquadFilter.frequency.value = 1000;
biquadFilter.Q.value = 100;
biquadFilter.gain.value = 25;

規範

規範
Web Audio API
# dom-biquadfilternode-q

瀏覽器相容性

另見