简体   繁体   English

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

[英]Tone.js : Getting unexpected results when tweaking synth parameters live (ex. detune, modulation index, attack etc.)

I've been working on a Tone.js synthesizer project for some time now.我从事 Tone.js 合成器项目已有一段时间了。

For the record I will include the links: Repo Deployment (it is still under development as I am stuck with this issue)作为记录,我将包括链接: Repo Deployment (它仍在开发中,因为我遇到了这个问题)

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.我将 PolySynth 与 FMSynth 一起使用,但我尝试过的所有其他合成器类型都遇到了同样的问题。

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).最初,我使用 NexusUI 组件,但为此我将使用常规 HTML slider(以证明 NexusUI 不是问题所在)。 It can be found in the deployment website I provided and in the repo.它可以在我提供的部署网站和 repo 中找到。 This is my code:这是我的代码:

In the main JavaScript file, I create the synth and send it to destination:在主 JavaScript 文件中,我创建了合成器并将其发送到目的地:

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

In the HTML file I create a simple slider:在 HTML 文件中,我创建了一个简单的 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.我在 Ubuntu 上使用 Tone.js 14.8.37 使用 CDN,Chrome 98-99。

Thanks a lot to anyone who might ofer some help:-)非常感谢任何可能提供帮助的人:-)

PS I have also opened an issue upon this matter, that can be found here PS 我也已经就此事提出了一个问题,可以在这里找到

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

With the Tone.js instruments, use the .set method for changing properties.对于 Tone.js 工具,使用.set方法更改属性。 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 .volume的情况下,它是一个参数,所以它可以通过volume.value直接改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM