ConvolverNode.buffer - Web APIs 编辑
The buffer
property of the ConvolverNode
interface represents a mono, stereo, or 4-channel AudioBuffer
containing the (possibly multichannel) impulse response used by the ConvolverNode
to create the reverb effect.
This is normally a simple recording of as-close-to-an-impulse as can be found in the space you want to model. For example, if you want to model the reverb in your bathroom, you might set up a microphone near the door to record the sound of a balloon pop or synthesized impulse from the sink. That audio recording could then be used as the buffer.
This AudioBuffer
must have the same sample-rate as the AudioContext
or an exception will be thrown. At the time when this attribute is set, the buffer and the state of the attribute will be used to configure the ConvolverNode
with this impulse response having the given normalization. The initial value of this attribute is null
.
Syntax
var audioCtx = new AudioContext();
var convolver = audioCtx.createConvolver();
convolver.buffer = myAudioBuffer;
Value
An AudioBuffer
.
Example
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;
Specifications
Specification | Status | Comment |
---|---|---|
Web Audio API The definition of 'buffer' in that specification. | Working Draft |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论