【问题标题】:Tone.PitchShift and Howler.js issuesTone.PitchShift 和 Howler.js 问题
【发布时间】:2021-12-05 20:03:44
【问题描述】:

我喜欢在我的 (Meteor) 应用程序中使用 Howler.js。但是,播放速率功能会导致我不想要的音高偏移(我只想要时间拉伸,并保持音高)。因此,我的解决方案是对其实施音高转换以“纠正”音高。看起来很简单,所以我选择使用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: Failed to execute 'connect' on 'AudioNode': 重载解析失败。

我还注意到,这些命令下方的 console.log() 命令甚至没有出现在控制台中,这很奇怪。但是,当我删除最后一行(mastergain.connect 到 pShift)时,它们会这样做。

我尝试了一些其他技术,例如https://github.com/mmckegg/soundbank-pitch-shift/(它有效,但无论我设置什么设置,它都会播放音高变化的声音和非音高变化的声音), 或者只是使用 AudioBufferSourceNode.detune(我不知道如何让它与 Howler.js 一起工作,因为 Howler 只有可以公开 GainNode 和 AudioContext 的函数,无法弄清楚如何从那里读取输出同时仍在使用咆哮)。

任何帮助/线索将不胜感激!

【问题讨论】:

    标签: javascript web-audio-api howler.js tone.js pitch-shifting


    【解决方案1】:

    我认为您的 sn-p 中不需要第三行。由于您的第一行是告诉 Tone.js 使用已经由 howler.js 创建的AudioContext。因此pShift.context 应该等于Howler.ctx。但仔细检查可能是有意义的。

    console.assert(pShift.context === Howler.ctx);
    

    howler.js 暴露的masterGain 是一个原生音频节点。这意味着它不能直接连接到使用 Tone.js 创建的节点,因为这些不是本机音频节点。但是 Tone.js 提供了一个帮助器来做到这一点。

    Tone.connect(Howler.masterGain, pShift);
    

    我认为您还需要在masterGain 上调用disconnect() 以删除任何现有连接。

    下面的 sn-p 应该可以工作。

    Tone.setContext(Howler.ctx);
    
    const pShift = new Tone.PitchShift(3);
    
    Howler.masterGain.disconnect();
    
    Tone.connect(Howler.masterGain, pShift);
    pShift.toDestination();
    

    【讨论】:

    • 谢谢你,你是救命稻草!!是否可以使某些声音不受音高变化的影响?当我尝试在播放之前快速移动我不想移动的声音,然后在播放它们之后恢复时,它会留下这种“双重声音”,其中一个声音落后于一小部分一秒。
    • 我不确定我是否理解你的问题。 Tone.PitchShift 会造成一点延迟。也许这就是你正在经历的。还有一个选项可以使用wet 参数绕过效果。但我想最好把它变成一个新问题,这样这里的每个人都可以回答。
    • 公平。那我再问一个问题,谢谢你的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    相关资源
    最近更新 更多