AudioBufferSourceNode: thuộc tính detune
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
Thuộc tính detune của giao diện AudioBufferSourceNode là một AudioParam k-rate biểu diễn độ lệch tần của dao động tính theo cent.
Ví dụ, các giá trị +100 và -100 sẽ tăng hoặc giảm độ lệch tần của nguồn đi một nửa cung, trong khi +1200 và -1200 sẽ tăng hoặc giảm đi một quãng tám.
Giá trị
Một AudioParam k-rate mà giá trị của nó cho biết độ lệch tần của dao động tính theo cent.
Note:
Mặc dù AudioParam được trả về là chỉ đọc, giá trị mà nó biểu diễn thì không phải.
Ví dụ
js
const audioCtx = new AudioContext();
const channelCount = 2;
const frameCount = audioCtx.sampleRate * 2.0; // 2 seconds
const myArrayBuffer = audioCtx.createBuffer(
channelCount,
frameCount,
audioCtx.sampleRate,
);
for (let channel = 0; channel < channelCount; channel++) {
const nowBuffering = myArrayBuffer.getChannelData(channel);
for (let i = 0; i < frameCount; i++) {
nowBuffering[i] = Math.random() * 2 - 1;
}
}
const source = audioCtx.createBufferSource();
source.buffer = myArrayBuffer;
source.connect(audioCtx.destination);
source.detune.value = 100; // value in cents
source.start();
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Web Audio API> # dom-audiobuffersourcenode-detune> |