AudioBuffer.copyFromChannel()

Promise 风格 调用:不支持

小程序插件:不支持

从AudioBuffer的指定频道复制到数组终端。

示例代码

示例代码


const audioCtx = wx.createWebAudioContext
const audioBuffer = audioCtx.createFromAudioFile({
  filePath:'/pages/res/bgm.mp3', // 静态资源
  mixToMono:true,
  sampleRate:44100
});
const channels = audioBuffer.numberOfChannels
const anotherArray = new Float32Array(frameCount);
const rate = audioBuffer.sampleRate
const startOffSet = 0
const endOffset = rate * 3;
const newAudioBuffer = audioCtx.createBuffer(channels,endOffset - startOffset,rate)
const offset = 0

for (let channel = 0; channel < channels; channel++) {
  audioBuffer.copyFromChannel(anotherArray, channel, startOffset);
  newAudioBuffer.copyToChannel(anotherArray, channel, offset);
}