javascript - Tone.js Error: 'Start time must be strictly greater than previous start time' - Stack Overflow

I am having a hard time understanding why I am getting thrown this error:Debug.ts:8 Uncaught Error: Sta

I am having a hard time understanding why I am getting thrown this error:

Debug.ts:8 Uncaught Error: Start time must be strictly greater than previous start time

The weird part is that it only throws me this error about 4/5 times I refresh the page. There is a 1/5 chance roughly that it will work with no problem. Here is my code:

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');
}

I am having a hard time understanding why I am getting thrown this error:

Debug.ts:8 Uncaught Error: Start time must be strictly greater than previous start time

The weird part is that it only throws me this error about 4/5 times I refresh the page. There is a 1/5 chance roughly that it will work with no problem. Here is my code:

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');
}
Share Improve this question asked Sep 19, 2020 at 17:45 charlieyincharlieyin 4118 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

I also had the same issue. You have to add the time to it.

This worked for me:

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

and my data (melody) looks like that:

[{ 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 }]

I received this error due to multiple sounds/notes being queued with triggerAttackRelease() at the exact same time. For me, I found that using multiple Synth instances (one per each distinct sound/note) was the best approach. Be careful not to spawn too many Synth instances, however.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744919453a4601041.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信