我喜欢在我的 (Meteor) 应用程序中使用 Howler.js。然而,播放速率功能导致了我不想要的音调变化(我只想延长时间,并保持音调)。因此,我的解决方案是对其进行音调变换以“纠正”音调。看起来很简单,这就是我选择使用的原因https://tonejs.github.io/ https://tonejs.github.io/
唯一的问题是,我一生都无法让它正常工作。经过几个小时的阅读 Web Audio API、Tone.js 文档以及在线讨论/故障排除论坛后,我得到的最接近潜在解决方案的东西是这样的(在我的应用程序的渲染期间调用,以防万一问题必须解决)提前加载):
Tone.setContext(Howler.ctx); //set tone's context to the Howler.js audiocontext
var pShift = new Tone.PitchShift(3); //create the PitchShift effect, +3 semi-tones transposition
pShift.context = Howler.ctx; //set the PitchShift's context to the Howler.js audiocontext
pShift.connect(Howler.ctx.destination); //connect the PitchShift's output to the Howler's destination
Howler.masterGain.connect(pShift); //connect the Howler's master GainNode output to the PitchShift effect
//For debugging purposes:
console.log(Howler.masterGain)
console.log(pShift);
当我运行此命令时,我收到此错误消息:
Tracker afterFlush 函数的异常:
meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:1059 TypeError: 无法在“AudioNode”上执行“connect”:重载解析失败。
我还注意到下面的 console.log() 命令甚至没有显示在控制台中,很奇怪。然而,当我删除最后一行(mastergain.connect 到 pShift)时,它们会这样做。
我尝试了一些其他技术,例如https://github.com/mmckegg/soundbank-pitch-shift/ https://github.com/mmckegg/soundbank-pitch-shift/(这有效,但无论我将其设置为何种设置,它都会播放音调变化的声音和非音调变化的声音),
或者简单地使用 AudioBufferSourceNode.detune (我不知道如何让它与 Howler.js 一起工作,因为 Howler 只有可以公开 GainNode 和 AudioContext 的函数,无法弄清楚如何从那里读取输出同时仍然使用咆哮)。
任何帮助/线索将不胜感激!
我认为您不需要代码片段中的第三行。由于您的第一行告诉 Tone.js 使用AudioContext
已经由 howler.js 创建。所以pShift.context
应该等于Howler.ctx
。但仔细检查可能是有意义的。
console.assert(pShift.context === Howler.ctx);
The masterGain
howler.js 公开的是一个原生音频节点。这意味着它无法直接连接到使用 Tone.js 创建的节点,因为这些节点不是本机音频节点。但 Tone.js 提供了一个帮助器来做到这一点。
Tone.connect(Howler.masterGain, pShift);
我想你还需要打电话disconnect()
on the masterGain
删除任何现有的连接。
下面的代码片段应该可以工作。
Tone.setContext(Howler.ctx);
const pShift = new Tone.PitchShift(3);
Howler.masterGain.disconnect();
Tone.connect(Howler.masterGain, pShift);
pShift.toDestination();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)