【发布时间】:2015-07-14 00:27:43
【问题描述】:
是否可以为缓冲区声音的播放速率值添加一个 lfo,类似于您为振荡器的频率添加的方法?
我尝试创建一个振荡器节点,将频率值设置为 2,将其连接到增益节点,将增益值设置为 1000,然后将增益节点连接到缓冲声音的播放速率,但没有效果。
我的代码:
function Sound(path) {
var that = this;
that.buffer = null;
that.path = path
var request = new XMLHttpRequest();
request.open('GET', that.path, true);
request.responseType = 'arraybuffer';
request.onload = function() {
ac.decodeAudioData(request.response, function(buffer) {
that.buffer = buffer;
});
}
request.send();
}
Sound.prototype.play = function(a,b) {
var lfo = ac.createOscillator();
lfo.frequency.value = 0.5
var lfoAmp = ac.createGain();
lfoAmp.gain.value = 1000
var gain = ac.createGain();
gain.gain.value = a;
var playSound = ac.createBufferSource();
playSound.playbackRate.value = b;
lfo.connect(lfoAmp);
lfoAmp.connect(playSound.playbackRate);
playSound.buffer = this.buffer;
playSound.loop = true;
playSound.connect(gain);
gain.connect(ac.destination);
lfo.start(0);
playSound.start(0);
}
【问题讨论】:
标签: javascript audio web-audio-api