0

我想在 javascript 中对音频缓冲区进行下采样。我正在使用 OfflineAudioContext,但输出音频质量明显低于原始音频(44100Hz)。在javascript中是否有比这更高质量的音频重采样的解决方案:

var sampleRate = 44100;
var outSampleRate = 16000;
var durationInSamples = audioBuffer441k.length;
var o = new OfflineAudioContext(1, durationInSamples*outSampleRate/sampleRate, outSampleRate);
var b = o.createBuffer(1, durationInSamples, sampleRate);

var buf = b.getChannelData(0);
for (var i = 0; i < durationInSamples; i++) {
   buf[i] = audioBuffer441k[i];
}

var source = o.createBufferSource();
source.buffer = b;
source.connect(o.destination);
source.start(0);
o.startRendering();
o.oncomplete = function(audiobuffer16k) {
  console.log("done resampling!!");
  console.log(audiobuffer16k.renderedBuffer);
  //do something with resampled audio
}
4

1 回答 1

1

直接插值算法不足以实现合格/无损转换。线性插值几乎杀死了波形。这就像向下投射一个对象。您需要一个支持正弦/余弦曲线非线性插值的重采样器,但现在很难找到一个js 解决方案,除非有人实施强大的解决方案并分享。

尝试以您想要的频率捕获数据。重新采样总是会降低质量(尤其是在纯 javascript 代码中)

看看 XAudioJS 中基于线性权重的插值重采样: https ://stackoverflow.com/a/30032095/5896342

于 2017-11-13T07:26:02.847 回答