GainNode

这篇翻译不完整。请帮忙从英语翻译这篇文章

GainNode 接口表示音量变更。它是一个 AudioNode 音频处理模块,在输出前使用给定 增益 应用到输入。一个 GainNode 总是只有一个输入和一个输出,都通过同样数量的声道。

增益是一个无单位量,会对所有输入声道的音频进行相应的增加。当对 GainNode 进行修改时,新的增益会通过 de-zippering 算法进行应用,以防止出现“咔嗒”的奇怪声响。

 

The GainNode is increasing the gain of the output.

Number of inputs 1
Number of outputs 1
Channel count mode "max"
Channel count 2 (not used in the default count mode)
Channel interpretation "speakers"

Properties

Inherits properties from its parent, AudioNode.

GainNode.gain 只读
Is an a-rate AudioParam representing the amount of gain to apply.

Methods

No specific method; inherits methods from its parent, AudioNode.

Example

The following example shows basic usage of an AudioContext to create a GainNode, which is then used to mute and unmute the audio when a Mute button is clicked by changing the gain property value.

The below snippet wouldn't work as is — for a complete working example, check out our Voice-change-O-matic demo (view source.)

<div>
  <a class="mute">Mute button</a>
</div>
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var gainNode = audioCtx.createGain();
var mute = document.querySelector('.mute');
var source;

if (navigator.getUserMedia) {
 navigator.getUserMedia (
   // constraints - only audio needed for this app
   {
     audio: true
   },

   // Success callback
   function(stream) {
     source = audioCtx.createMediaStreamSource(stream);

   },

   // Error callback
   function(err) {
     console.log('The following gUM error occured: ' + err);
   }
  );
} else {
   console.log('getUserMedia not supported on your browser!');
}

source.connect(gainNode);
gainNode.connect(audioCtx.destination);

  ...

mute.onclick = voiceMute;

function voiceMute() {
  if(mute.id == "") {
    gainNode.gain.value = 0;
    mute.id = "activated";
    mute.innerHTML = "Unmute";
  } else {
    gainNode.gain.value = 1;
    mute.id = "";
    mute.innerHTML = "Mute";
  }
}

Specifications

Specification Status Comment
Web Audio API
GainNode
Working Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 10.0webkit 25.0 (25.0)  未实现 15.0webkit
22
6.0webkit
Feature Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? 26.0 1.2 ? ? ? 33.0

See also

文档标签和贡献者

 此页面的贡献者: SoAanyip
 最后编辑者: SoAanyip,