Web Audio API,设置高音和低音

Web Audio API, setting treble and bass

我正在努力学习如何正确使用网络音频 api,但我 运行 有点困惑。

在我的项目中,我试图复制旧 1982 Harman/Kardon receiver 的功能。 (点击link看照片)

此接收器具有单独的高音和低音控制旋钮。我将只处理这个问题中的高音。一旦我指向正确的方向,我确信我可以计算出低音等效值。

在初始化函数中,我创建了上下文和过滤器节点。

window.AudioContext = window.AudioContext || window.webkitAudioContext;
    context = new AudioContext();
    source = context.createMediaElementSource(document.getElementById('audio'));
    gainNode = context.createGain();

//filter nodes
bassTurnoverFilter = context.createBiquadFilter();
trebleTurnoverFilter = context.createBiquadFilter();
loudnessTrebFilter = context.createBiquadFilter();
loudnessBassFilter = context.createBiquadFilter();
trebleLevelFilter = context.createBiquadFilter();
bassLevelFilter = context.createBiquadFilter();

我目前正在使用 jogDial plugin 来控制转盘。刻度盘确实有效,当刻度盘从 0% 变为 100% 时,我可以获得 0 到 1 之间的 "treble" 变量范围。

这是我当前用于高音拨号的 mousemove 函数:

.on("mousemove", function(event){

var treble = (event.target.rotation + 140) / 280;

    if(trebleLevelFilter !== undefined){
        trebleLevelFilter.disconnect();
    }
    source.connect(trebleLevelFilter); 
    trebleLevelFilter.type = "highshelf"; 
    trebleLevelFilter.frequency.value = 200; 
    trebleLevelFilter.gain.value = treble; 
    trebleLevelFilter.connect(context.destination);
});

我的问题或多部分问题是... 我应该使用 6 种 类型 中的哪一种? ("lowpass","highpass","bandpass","lowshelf","highshelf","peaking","notch", "allpass") 我猜是highpass或者highself.

我应该设置什么频率?

gain.value表盘转动时应该是动态的吗?

我是不是走错方向了?

我已将 gain.value 设置为高音变量值,似乎它在转到 100% 时稍微增加了音量...但我认为这不是正确的功能我正在努力完成。

下面显示了一些关于选择用于各种目的的过滤器类型的建议:

Web Audio API

从该页面粘贴:

There are many kinds of filters that can be used to achieve certain kinds of effects:

Low-pass filter Makes sounds more muffled

High-pass filter Makes sounds more tinny

Band-pass filter Cuts off lows and highs (e.g., telephone filter)

Low-shelf filter Affects the amount of bass in a sound (like the bass knob on a stereo)

High-shelf filter Affects the amount of treble in a sound (like the treble knob on a stereo)

Peaking filter Affects the amount of midrange in a sound (like the mid knob on a stereo)

Notch filter Removes unwanted sounds in a narrow frequency range

All-pass filter Creates phaser effects

我不确定你为什么要创建六种不同的滤波器 - 你应该只需要两个,一个用于高音,一个用于低音。

认为 您正在查看的 HK 放大器没有中音控制 - 这有点奇怪,但没关系。低音滤波器可能是低架,高音是高架;这些按钮控制每个按钮的截止频率。请记住,搁架滤波器在零增益时是平坦的响应 - 您可以在 http://googlechrome.github.io/web-audio-samples/samples/audio/frequency-response.html 处试用滤波器,看看它们会是什么样子。 Select低架子,freq=~200,然后玩增益。

因此,例如您接近高音滤波器,除了 "treble" 和 "bass" 增益值不应为 [0,1] - 它应介于 [-maxgain] 之间,+最大增益]。 "maxgain"大概是2-3?您必须尝试使用​​它并选择一个好的范围 - 我在 HK 手册中找不到它 (http://www.manualslib.com/manual/279084/Harman-Kardon-Hk590i.html)。串联滤波器也很重要,不要并联(否则会出现相位问题)。

// if treble=0 and bass=0 you'll have a flat response
bassFilter = context.createBiquadFilter();
bassFilter.type = "lowshelf"; 
bassFilter.frequency.value = 200;  // switches to 400 in UI
bassFilter.gain.value = bass;  // you'll need to hook this to UI too

trebleFilter = context.createBiquadFilter();
trebleFilter.type = "highshelf"; 
trebleFilter.frequency.value = 2000;  // switches to 6000 in UI
trebleFilter.gain.value = treble;  // you'll need to hook this to UI too

source.connect(bassFilter); 
bassFilter.connect(trebleFilter); 
trebleFilter.connect(context.destination);

此外,没有理由断开过滤器并重新连接它 - 您可以在连接时对 .gain.value 进行实时更改。