Jes*_*gan 19 javascript audio html5 web-audio-api
我正在研究一个基于网络的音序器/跟踪器,我注意到在我的示例播放例程中,音频上下文似乎只存在于样本的持续时间内,并且Web Audio API似乎不一样我调整样本时调整播放持续时间.例如,如果我将音符向下移动一个八度音程,则例程仅在切断之前播放声音的前半部分.更强烈的音高降档导致更少的声音播放,虽然我不确定我能否证实这一点,但我怀疑加速音频会在声音退出缓冲区之前产生相对长时间的静音.
这是我目前的音频播放程序.到目前为止,还有很多工作要确保其他函数向此发送正确的数据,而不是扩展此例程的功能.
function playSound(buffer, pitch, dspEffect, dspValue, volume) {
var source = audioEngine.createBufferSource();
source.buffer = buffer;
source.playbackRate.value = pitch;
// Volume adjustment is handled before other DSP effects are added.
var volumeAdjustment = audioEngine.createGain();
source.connect(volumeAdjustment);
// Very basic error trapping in case of bad volume input.
if(volume >= 0 && volume <= 1) {
volumeAdjustment.gain.value = volume;
} else {
volumeAdjustment.gain.value = 0.6;
}
switch(dspEffect){
case 'lowpass':
var createLowPass = audioEngine.createBiquadFilter();
volumeAdjustment.connect(createLowPass);
createLowPass.connect(audioEngine.destination);
createLowPass.type = 'lowpass';
createLowPass.frequency.value = dspValue;
break;
// There are a couple of other optional DSP effects,
// but so far they all operate in about the same fashion.
}
source.start();
}
Run Code Online (Sandbox Code Playgroud)
无论应用多少音高变换,我的目的都是让样本完全播放,并在必要时限制音高变换量.我发现在这个问题上附加几秒钟的静音可以解决这个问题,但由于我需要处理大量的声音,这很麻烦,我更喜欢基于代码的解决方案.
编辑:在我可以测试的浏览器中,这似乎只是谷歌Chrome中的一个问题.样本在Firefox中完全播放,Internet Explorer尚不支持Web Audio API,我也无法访问Safari或Opera.这肯定会改变我正在寻找的帮助的性质.
| 归档时间: |
|
| 查看次数: |
898 次 |
| 最近记录: |