How to disable Web-Audio analyzer filtering high frequencies

时间秒杀一切 提交于 2019-12-21 20:36:48

问题


I am studying the html5 audio API. I have noticed the analysis module has problems processing high frequencies. It is as if there is a build in filter in it. For example, if I emitting a 20Khz tone and plot the outcome of getFloatFrequencyData I see the following spectrum:

However, if I use Audacity, the same signal looks like this: (notice the peak @ 20khz)

Can I disable the built in filter of the analysis model? p.s. the sampling rate is high enough according to the context canvas so I would not suspect aliasing problems.


回答1:


@cwilso has it, the input is filtered by default, you need to pass a properly formed constraints object to getUserMedia. The format is a little fiddly but that's kind of unavoidable considering it's remit. The spec is not fully implemented by everyone yet either and each browser has it's own set of prefixed undocumented pre-processors. This is what I've been using to get the rawest audio available (Mid October 2016). This list is probably not complete either - I have only looked at FF and Ch so far. Anyone got any others?

let constraints = {
  audio: {
    optional: [
      {echoCancellation: false},
      {mozAutoGainControl: false},
      {mozNoiseSuppression: false},
      {googEchoCancellation: false},
      {googAutoGainControl: false},
      {googNoiseSuppression: false},
      {googHighpassFilter: false}
    ]
  }
};

let mediaInput = navigator.mediaDevices.getUserMedia( constraints );



回答2:


It sounds like you're using audio (e.g. microphone) input? If so, make sure you're turning off echo cancellation - pass a constraint object to getUserMedia with echo cancellation set to false, a la https://github.com/cwilso/Audio-Input-Effects/blob/master/js/effects.js#L52-L57 and https://github.com/cwilso/Audio-Input-Effects/blob/master/js/effects.js#L160-L163. Otherwise, built-in processing is going to strip some things, including high frequencies.




回答3:


2018 update: Chrome no longer needs the goog prefix, and highpassfilter is gone (I verified this with a soundcard that supports DC inputs):

let constraints = {
  audio: {
    echoCancellation: false,
    autoGainControl: false,
    noiseSuppression: false
  }
};

let mediaInput = navigator.mediaDevices.getUserMedia( constraints );


来源:https://stackoverflow.com/questions/31306309/how-to-disable-web-audio-analyzer-filtering-high-frequencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!