我可以在使用tone.js播放音频时更改音调间隔吗?

问题描述

我会向你展示我的代码

audio_music = new Audio();
var track = audioContext.createMediaElementSource(audio_music);

//Import music files from other sources into base64 form.
audio_music.src = "data:audio/ogg;base64,"+ data.music;

var splitter = audioContext.createChannelSplitter(6);
var merger = audioContext.createChannelMerger(2);
track.connect(splitter);

//omitted in addition to 0 and 1 due to repetition of the similar content
gainNode0 = audioContext.createGain(); gainNode0.gain.setValueAtTime((musicvolume*0.1),audioContext.currentTime);
gainNode1 = audioContext.createGain(); gainNode1.gain.setValueAtTime((musicvolume*0.1),audioContext.currentTime);

splitter.connect(gainNode0,0);
splitter.connect(gainNode1,1);

var pitchshift0 = new Tone.PitchShift(pitch);
var pitchshift1 = new Tone.PitchShift(pitch);

Tone.connect(gainNode0,pitchshift0);
Tone.connect(gainNode1,pitchshift1);

Tone.connect(pitchshift0,merger,0);
Tone.connect(pitchshift1,1);

Tone.connect(merger,audioContext.destination);

我对audioContext和tone.js的使用不熟悉,所以不知道我理解对不对,但我的意图是将输入源分成六个通道,按照增益调整,音高的顺序进行处理分别是 shift 和 marge。

这将完成其他所有操作,但您无法在播放过程中更改音高偏移的值。

我想要一种类似于在音高变换中 GainNode 中使用的 setValueAtTime 起作用的方法

我该怎么办?

解决方法

您可以通过设置音高参数来改变音高:

pitchshift0.pitch = -12 // Semitone to shift the pitch to.

如果您想在播放期间的特定时间设置此项,您可以使用 Transport 类来安排:

Tone.Transport.schedule(() => pitchshift0.pitch = -12,time /* The transport time you want to schedule it at */);