[英]How do you activate fadeOut effect using Tone.JS?
I am able to successfully play oscillating tone of type square-wave with 100hz frequency.我能够成功播放频率为 100hz 的方波类型的振荡音。
However, the tone does not "gracefully" stop.然而,语气并没有“优雅地”停止。 Moreover, your speakers will make a "thud" sound when the tone stops, and the "thud" is worse when your speaker volume is too high.
此外,当音调停止时,您的扬声器会发出“砰”的声音,而当您的扬声器音量过高时,“砰”的声音会更糟。 To fix that, I would like to add a fadeOut effect.
为了解决这个问题,我想添加一个淡出效果。 ToneJS library supports this: here .
ToneJS库支持这一点:这里. However, I am not able to set the fadeOut property or activate it.
但是,我无法设置淡出属性或激活它。
What am I doing wrong?我究竟做错了什么?
$( "#btnPlay" ).click(function(e) { var player = new Tone.Oscillator(100, "square").toDestination(); player.fadeOut = 5; // set fadeOut time value player.start(); player.stop(1); // stop playing after 1 second });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.5/Tone.js"></script> <input id = "btnPlay" type="submit" value="Play!"/>
Your fadeOut
value is too long so you won't hear it.您的
fadeOut
值太长,因此您听不到。 The value is in seconds, so try providing 0.05
(ie 50ms
) instead.该值以秒为单位,因此请尝试提供
0.05
(即50ms
)。
player.fadeOut = 0.05; // value is in seconds
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.