Tone.js:实时调整合成器参数时获得意想不到的结果(例如失谐、调制指数、起音等)

发布于 2025-01-11 14:31:03 字数 1736 浏览 1 评论 0原文

我从事 Tone.js 合成器项目已经有一段时间了。

为了记录,我将包含以下链接: 仓库 部署 (它仍在开发中,因为我遇到了这个问题)

我遇到了一个无法解决的严重问题。我将 PolySynth 与 FMSynth 一起使用,但我尝试过的所有其他合成器类型都遇到了同样的问题。

每当我尝试调整合成器现场的参数(例如失谐、调制指数、幅度包络等)时,我都会得到意想不到的行为:

大多数时候,当我更改参数的值时,它会立即起作用,因此声音会根据我所做的更改进行修改,但即使我不断更改参数的值,声音也会坚持第一个修改的值。

有时,每当我在合成器上演奏一个音符时,我就会得到修改过的声音。一次我得到修改后的声音,然后下次得到没有任何修改的原始声音,然后再次得到修改后的声音,依此类推。

有时它有效,但我仍然停留在第一次修改上。

有时,在先演奏一些音符后,它会随机工作。

有时它会立即起作用,但随后一些特定的音符会产生未经修改的原始声音,无论我如何修改(并且合成器仍然停止响应任何进一步的参数更改)。

除了音量之外的每个参数都会发生这种情况:音量每次都按预期工作。

让我们使用调制指数作为示例(失谐、谐波和起音也会发生同样的情况 - 这些是我暂时实现的参数)。最初,我使用 NexusUI 组件,但为此我将使用常规 HTML 滑块(以证明 NexusUI 不是问题)。它可以在我提供的部署网站和存储库中找到。这是我的代码:

在主 JavaScript 文件中,我创建合成器并将其发送到目的地:

const synth = new Tone.PolySynth(Tone.FMSynth).toDestination();

在 HTML 文件中,我创建一个简单的滑块:

<input type="range" min="0" max="300" value="0" class="slider" id="mod-index">

每次拨盘移动时,我都会相应地更改调制指数值:

let modulationIndexSlider = document.getElementById("mod-index");
modulationIndexSlider.oninput = function() { 
    synth.options.modulationIndex = this.value 
}

如您所见,我是使用以下方法设置新的调制指数值:

synth.options.modulationIndex = this.value

我对其他参数遵循完全相同的方法,例如。

synth.options.harmonicity = this.value
synth.options.envelope.attack = this.value 

等等。

我在 Ubuntu 上使用 CDN、Chrome 98-99 的 Tone.js 14.8.37。

非常感谢任何可能提供帮助的人:-)

PS 我还就此事提出了一个问题,可以在这里找到

I've been working on a Tone.js synthesizer project for some time now.

For the record I will include the links:
Repo
Deployment
(it is still under development as I am stuck with this issue)

I have encountered a serious issue that I couldn't manage to solve. I use the PolySynth with an FMSynth, but I've had the same issue with all the other synth types that I tried.

Whenever I am trying to tweak the parameters of the synth live (ex. detune, modulation index, amplitude envelope etc.) I get unexpected behaviour:

Most of the times, when I change the value of a parameter, it works at once, thus the sound gets modifidied according to the change I made, but the sound is then stuck to the first modified value, even if I keep changing the value of the parameter.

Then sometimes I get the modified sound every second time I play a note on the synth. One time I get the modified sound and then next time the original sound without any modification, then the modified sound again and so on.

Somestimes it works, but I am still stuck on the first modification.

Sometimes it works randomly, after playing some notes first.

Sometimes it works at once, but then some specific notes produce the unmodified original sound, regardless of my modification (and still the synth stops responding to any further parameter changes).

This is happening with every parameter but volume: volume works as intended every time.

Let's use Modulation index as an example (the same happens with detune, harmonicity and attack - those are the parameters I've implemented for the time being). Originally, I use NexusUI components, but for this I wil be using a regular HTML slider (to prove that NexusUI is not the problem). It can be found in the deployment website I provided and in the repo. This is my code:

In the main JavaScript file, I create the synth and send it to destination:

const synth = new Tone.PolySynth(Tone.FMSynth).toDestination();

In the HTML file I create a simple slider:

<input type="range" min="0" max="300" value="0" class="slider" id="mod-index">

And everytime the dial moves I change the modulation index value accordingly:

let modulationIndexSlider = document.getElementById("mod-index");
modulationIndexSlider.oninput = function() { 
    synth.options.modulationIndex = this.value 
}

As you can see I am setting the new modulation index value using:

synth.options.modulationIndex = this.value

I follow the exact same approach for the other parameters,ex.

synth.options.harmonicity = this.value
synth.options.envelope.attack = this.value 

and so on.

I am using Tone.js 14.8.37 using CDN, Chrome 98-99 on Ubuntu.

Thanks a lot to anyone who might ofer some help :-)

P.S. I have also opened an issue upon this matter, that can be found here

https://github.com/Tonejs/Tone.js/issues/1045

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一袭白衣梦中忆 2025-01-18 14:31:03

对于 Tone.js 乐器,使用 .set 方法更改属性。您可以同时更改多个属性,如下所示:

synth.set({
  harmonicity: 10,
  envelope: {
    attack: 0.001,
  },
});

对于 volume 来说,它是一个 Param,因此可以直接通过 volume.value 更改它。

With the Tone.js instruments, use the .set method for changing properties. You can change multiple properties at the same time, like this:

synth.set({
  harmonicity: 10,
  envelope: {
    attack: 0.001,
  },
});

In the case of volume, it is a Param, so it can be changed directly via volume.value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文