Nik*_*kov 7 javascript web-audio-api
我无法通过GainNode的exponentialRampToValueAtTime获得音量的滑动变化.
这是一个例子:
var context = new AudioContext(),
osc = context.createOscillator(),
gain = context.createGain();
osc.frequency.value = 440; // A note
osc.start( 0 );
osc.connect( gain );
gain.gain.value = 0;
gain.connect( context.destination );
gain.gain.cancelScheduledValues( 0 );
gain.gain.setValueAtTime( 0, context.currentTime );
gain.gain.exponentialRampToValueAtTime( 1, context.currentTime + 2 );
Run Code Online (Sandbox Code Playgroud)
根据我的理解,这应该逐渐增加音量,直到达到1(100%),整个过程应该花费2秒.这个假设是否正确?
如果是,为什么保持0为2秒,然后突然切换到满音量?
提前感谢您的时间和精力.
看来这个函数不喜欢0值.FF抛出"SyntaxError:指定了无效或非法字符串".下面的代码将正确斜坡.见Plnkr.
var context = new AudioContext(),
osc = context.createOscillator(),
gain = context.createGain();
osc.frequency.value = 440.0; // A note
osc.start( 0 );
osc.connect( gain );
gain.connect( context.destination );
gain.gain.setValueAtTime(0.0001, context.currentTime); // <-- line of interest
gain.gain.exponentialRampToValueAtTime(1, context.currentTime + 10 );
Run Code Online (Sandbox Code Playgroud)
更新: "根据Web Audio规范,如果此值小于或等于0,或者如果上一个事件的值小于或等于0",则必须抛出NotSupportedError异常.正如@cwilso所说(见评论).
| 归档时间: |
|
| 查看次数: |
1320 次 |
| 最近记录: |