【发布时间】:2016-12-08 15:01:07
【问题描述】:
我正在尝试设置一个速度值,该值位于要增益的 MIDI 信号中。速度范围从 0 到 127。
web audio api 上的文档虽然做得很好,但并没有真正说明这一点。
目前我有这个可以播放声音:
play(key, startTime) {
this.audioContext.decodeAudioData(this.soundContainer[key], (buffer) => {
let source = this.audioContext.createBufferSource();
source.buffer = buffer;
source.connect(this.audioContext.destination);
source.start(startTime);
});
}
我没有找到任何可以使用范围从 0 到 127 的速度值。但是我发现 gain node 应用了增益。
所以我现在的功能是这样的:
play(key:string, startTime, velocity) {
this.audioContext.decodeAudioData(this.soundContainer[key], (buffer) => {
let source = this.audioContext.createBufferSource();
source.buffer = buffer;
source.connect(this.gainNode);
this.gainNode.connect(this.audioContext.destination);
this.gainNode.gain.value = velocity;
source.start(startTime);
});
}
Eehhh...如果我将 midi 速度值应用于增益,我显然会听到非常响亮的声音。所以我想知道这两个问题中的任何一个:
- 我可以直接使用速度值吗?
- 如何将速度值转换为增益?
【问题讨论】:
标签: javascript audio midi web-audio-api