[英]How to Correctly Clean Up timbre.js
I am running Timbre.js successfully on iOS 9.2 by coupling it with AudioContextMonkeyPatch, and I am trying to use a slightly modified version of code found here: http://mohayonao.github.io/timbre.js/interval.html . 我通过将它与AudioContextMonkeyPatch耦合而在iOS 9.2上成功运行了Timbre.js,并且我尝试使用在此处找到的经过稍微修改的代码版本: http : //mohayonao.github.io/timbre.js/interval.html 。 The code (to save lookup) is:
代码(以保存查找)为:
var freqs = T(function(count) {
return [220, 440, 660, 880][count % 4];
});
var osc = T("sin", {freq:freqs, mul:0.5});
var env = T("perc", {a:50, r:500}, osc).bang();
var interval = T("param", {value:500}).linTo(50, "30sec");
T("interval", {interval:interval}, freqs, env).start();
env.play();
What I am trying to figure out is how to start and then stop and then re-start the sound. 我要弄清楚的是如何开始然后停止然后重新开始声音。 I'm trying to see how the developer's example 'Pause' button works, but I can't seem to locate that code example.
我正在尝试查看开发人员的示例“暂停”按钮的工作方式,但是我似乎找不到该代码示例。 I do basic things tike "T().stop(); env.pause();"
我做一些基本的事情,例如“ T()。stop(); env.pause();” followed by "env.play();"
随后是“ env.play();” (in separate onClick events), and I end up with multiple signals on the second play event.
(在单独的onClick事件中),最后在第二个播放事件中出现多个信号。 Really frustrating.
真令人沮丧。 The documentation suggests a 'removeAll' will remove all items loaded into Timbre() (or T()?), but applying this in my stop function does not provide a satisfactory result either.
该文档建议'removeAll'将删除所有加载到Timbre()(或T()?)中的项目,但是在我的stop函数中应用此方法也不能提供令人满意的结果。 Anyone know the correct way to pause and restart this script snippet?
有人知道暂停和重新启动此脚本片段的正确方法吗?
In order to start and stop the sequence you need to assign the last T function to a variable. 为了开始和停止序列,您需要将最后一个T函数分配给变量。 You can then use .start() and .stop() as you like:
然后,您可以根据需要使用.start()和.stop():
code....
var interval = T("param", {value:500}).linTo(50, "30sec");
var audioSequence = T("interval", {interval:interval}, freqs, env);
env.play();
audioSequence.start(); // Start the Sequence
interval.stop(); // Stop the interval
audioSequence.stop(); // Stop the Sequence
interval.start(); // Restart the Interval
audioSequence.start(); // Restart the Sequence
Its a little confusing at first as play()/pause() is used for oscillators or drums for example and start()/stop() is used for intervals. 起初有些混乱,例如play()/ pause()用于振荡器或鼓,而start()/ stop()用于间隔。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.