【问题标题】:Tone.js Error: 'Start time must be strictly greater than previous start time'Tone.js 错误:“开始时间必须严格大于以前的开始时间”
【发布时间】:2021-01-06 08:01:08
【问题描述】:

我很难理解为什么会出现这个错误:

Debug.ts:8 未捕获的错误:开始时间必须严格大于 上次开始时间

奇怪的是,它只在我刷新页面的 4/5 次左右时向我抛出此错误。大约有 1/5 的机会可以正常工作。这是我的代码:

let synth = new Tone.MetalSynth({
  portamento: 0,
  volume: -15,
  envelope: {
    attack: 0.001,
    decay: 1.4,
    release: 1,
  },
  harmonicity: 18.1,
  modulationIndex: 12,
  resonance: 1000,
  octaves: 1.5,
});

synth.chain(Tone.Destination);

let notes = ['A2', 'B2', 'C3', 'D3', 'E3', 'F3', 'G#3'];
let html = '';
for (let i = 0; i < notes.length; i++) {
  html += `<div class="whitenote" onmouseover="noteDown(this)" data-note="${notes[i]}"></div>`;
}

document.querySelector('.container-4').innerHTML = html;

function noteDown(el) {
  let note = el.dataset.note;
  synth.triggerAttackRelease(note, '16n');
}

【问题讨论】:

    标签: javascript web-audio-api tone.js


    【解决方案1】:

    由于多个声音/音符同时与triggerAttackRelease() 一起排队,我收到了这个错误。对我来说,我发现使用多个 Synth 实例(每个不同的声音/音符一个)是最好的方法。但是请注意不要生成太多 Synth 实例。

    【讨论】:

      【解决方案2】:

      我也有同样的问题。您必须添加时间。

      这对我有用:

      const synth = new Tone.Synth().toDestination();
              
      melody.forEach(tune => {
            const now = Tone.now()
            synth.triggerAttackRelease(tune.note, tune.duration, now + tune.timing)
      })
      

      我的数据(旋律)看起来像这样:

      [{ note: "E5", duration: "8n", timing: 0 },
      { note: "D#5", duration: "8n", timing: 0.25 },
      { note: "E5", duration: "8n", timing: 0.5 },
      { note: "D#5", duration: "8n", timing: 0.75 },
      { note: "E5", duration: "8n", timing: 1 },
      { note: "B4", duration: "8n", timing: 1.25 }]
      

      【讨论】:

        猜你喜欢
        • 2021-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多