用 Tone.js 个音符创建音效?

Create sound effect with Tone.js notes?

如何使用 Tone.js 音符创建 these 音效之一

这可能吗?给出这些注释时: "C","C#","Db","D","D#","Eb","E","E#","Fb","F","F#","Gb","G ","G#","Ab","A","A#","Bb","B","B#","Cb"... 我现在能以某种方式使用 tone.js 来创建类似“Tada!”的音效吗?我认为它需要的不仅仅是notes/tones,它还需要某种方式的投球和时间操纵?

简单的 C 调播放 400 毫秒:

polySynth.triggerAttack("C");
setTimeout(x=>polySynth.triggerRelease("C"),400);

这里有一个工作 Jsfiddle with Tone.js 可以进行实验。

我的耳朵不是很有经验,但其中大部分对我来说听起来像是大和弦(低音、三度、五度),有些还增加了八度。例如,C4、E4、G4、C5:

const chord = ["C4", "E4", "G4", "C5"];
const duration = 0.5;
const delay = 0.05;
const now = Tone.now();
for (let i = 0; i < chord.length; i++) {
  const note = chord[i];
  polySynth.triggerAttackRelease(note, duration, now + i * delay);
}

如果您想随机化根音,直接使用频率而不是音符名称可能会很有用。中央 C 上方的 A 通常取为 440 Hz,高于该频率的每个连续半音高 Math.pow(2, 1/12) 倍:

const rootFrequency = 440;
const chordSemitones = [0, 4, 7, 12];
const duration = 0.5;
const delay = 0.1;
const now = Tone.now();
for (let i = 0; i < chordSemitones.length; i++) {
  const pitch = rootFrequency * Math.pow(2, chordSemitones[i] / 12);
  polySynth.triggerAttackRelease(pitch, duration, now + i * delay);
}