html - 网络音频 : how does timeConstant in setTargetAtTime work?

标签 html web-audio-api

我想快速淡出振荡器,以消除简单地停止振荡器时产生的爆裂声/嘶嘶声。 Chris Wilson 提出了 technique设置 setTargetAtTime在 yield 上。

现在我不太明白它的最后一个参数'timeConstant':

它的单位是什么?秒? 我必须在那里输入什么才能在 1 毫秒内达到目标值?

最佳答案

Chris Wilson 那个家伙,真麻烦。 :)

setTargetAtTime 是指数衰减。参数是一个时间常数:

“timeConstant 是一阶线性连续时不变系统在给定阶跃输入响应(从 0 值过渡到 1 值)的情况下达到值 1 - 1/e(约 63.2%)所需的时间。”

因此,对于每个“timeconstant”时间长度,电平将下降超过 2/3rds(假设增益为 1,并且您将目标设置为 0。在某些时候,衰减会变得如此接近于零,它低于噪声阈值,你不必担心这一点。它永远不会“达到目标值”——它会逐渐逼近它,当然在某些时候差异会低于您可以用 float 表示的精度。

我建议您进行一些实验,但这里有一个快速的猜测可以帮助您入门:

// only setting this up as a var to multiply it later - you can hardcode.
// initial value is 1 millisecond - experiment with this value if it's not fading
// quickly enough.
var timeConstant = 0.001; 

gain = ctx.createGain();
// connect up the node in place here
gain.gain.setTargetAtTime(0, ctx.currentTime, timeConstant);

// by my quick math, 8x TC should take you to around 2.5% of the original level 
// - more than enough to smooth the envelope off.
myBufferSourceNode.stop( ctx.currentTime + (8 * timeConstant) );

关于html - 网络音频 : how does timeConstant in setTargetAtTime work?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20588678/

相关文章:

html - 带有滚动内容的固定标题?和小的 css 问题

javascript - Onclick更改HTML5本地存储值

php - 全宽页脚 WordPress

javascript - 网络音频 5.1(6 声道)输出

javascript - 过滤网络音频

javascript - 我如何在 Web 中播放来自 Android 的原始样本 PCM_16 音频数据记录(使用 Web-Audio 或其他)?

html - 我怎样才能用css实现这样的阴影效果呢?

html - CSS :first-child with class selector picking up wrong elements to style?

safari - Safari 中的 OfflineAudioContext 和 FFT

ios - Web Audio API 不在设备上播放声音样本,但在浏览器中有效