0

我正在尝试使用tone.js在Angular 9中实现一个简单的节拍器,但似乎在执行过程中发生了某种类型的心律失常......我不知道我是否在实现中遗漏了一些东西。

这是我的代码:

    playMetronome(): void {
        Tone.Transport.bpm.value = 120;

        Tone.Transport.scheduleRepeat(() => {
          const player = new Tone.Player("./../../assets/sounds/tick.mp3").toMaster();
          player.autostart = true;
        }, "4n");

        Tone.Transport.start();
    }

有人能帮我吗?

4

1 回答 1

1

您应该使用 Tones Transport 机制的“时间”参数,否则时间会不稳定。例如:

// instantiate the player
const play1 = new Tone.Player(<url>).toDestination();
// schedule the events
Tone.Transport.schedule(time => play1.start(time), 0);
Tone.Transport.schedule(time => play1.start(time), '0:2');
// set tempo
Tone.Transport.bpm.value = 220;
// set loop & repeat
Tone.Transport.loopEnd = '1m';
Tone.Transport.loop = true;
// start transport
Tone.Transport.start();

在此处查找 stackblitz 示例: https ://stackblitz.com/edit/angular-metronome-mki

于 2020-06-07T22:38:18.280 回答