0

我有一个用 ToneJS 构建的简单合成器,我想在将来安排一个笔记。我的合成器有一个FrequencyEnvelope连接到一个Oscillator.

await Tone.start();

const fEnv = new Tone.FrequencyEnvelope({
  attack: 0.5, decay: 0.5, sustain: 0.5, release: 0.5,   
  baseFrequency: "a7",
    octaves: 1,});
const env = new Tone.Envelope({
  attack: 0.01, decay: 0.1, sustain: 0.2, release: 0.7});
const osc = new Tone.Oscillator({type: 'square'});
const gain = new Tone.Gain();

env.connect(gain.gain);
fEnv.connect(osc.frequency);
osc.connect(gain);
gain.toDestination();  

osc.start();

我可以通过设置频率包络的 baseFrequency 并触发攻击和释放来播放音符:

fEnv.baseFrequency = 'c2';
env.triggerAttackRelease('4n');
fEnv.triggerAttackRelease('4n');

这很好,但如果我想在未来改变音高以作为未来的触发器,我不知道该怎么做

const now = Tone.context.now();
fEnv.baseFrequency.setValueAtTime('e2', now+1);
env.triggerAttackRelease('4n', now+1);
fEnv.triggerAttackRelease('4n', now+1);

如何安排基本频率,以便在我想要的时候发生音高变化?

4

0 回答 0