AudioContext.createConvolver()
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.
io error: No such file or directory (os error 2) (/home/runner/work/yari/yari/mdn/translated-content/files/zh-cn/web/api/baseaudiocontext/index.md)
AudioContext
的方法 createConvolver()
能创建一个 ConvolverNode
,通常用来对你的音频应用混响效果。在 Convolution 规范定义 中查看更多信息。
语法
js
var audioCtx = new AudioContext();
var convolver = audioCtx.createConvolver();
返回值
例子
下面的例子展示了一个 AudioContext 创建一个 混响器节点 的基本使用方法。基本前提是你创建一个包含声音样本的 AudioBuffer 用作混响环境 (称之为脉冲响应,) 和在混响器中应用。下面的例子使用了一个简短的示例音乐厅人群效果,所以混响效果应用深度和回声。
更多完整例子请查看 Voice-change-O-matic demo (中 app.js 的代码)。
js
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var convolver = audioCtx.createConvolver();
...
// grab audio track via XHR for convolver node
var soundSource, concertHallBuffer;
ajaxRequest = new XMLHttpRequest();
ajaxRequest.open('GET', 'concert-crowd.ogg', true);
ajaxRequest.responseType = 'arraybuffer';
ajaxRequest.onload = function() {
var audioData = ajaxRequest.response;
audioCtx.decodeAudioData(audioData, function(buffer) {
concertHallBuffer = buffer;
soundSource = audioCtx.createBufferSource();
soundSource.buffer = concertHallBuffer;
}, function(e){"Error with decoding audio data" + e.err});
}
ajaxRequest.send();
...
convolver.buffer = concertHallBuffer;
规范
Specification |
---|
Web Audio API # dom-baseaudiocontext-createconvolver |
浏览器兼容性
BCD tables only load in the browser