WaveShaperNode

WaveShaperNode 接口表示一个非线性的畸变器。 是一个使用曲线来将一个波形畸变应用到一个声音信号中的AudioNode 。 除了明显的失真效果之外, 它通常用来给信号添加一个暖调的感觉。

 一个WaveShaperNode 总是有一个确切的输入和输出。

输入数目 1
输出数目 1
信道计数模式 "max"
信道计数 2 (不在缺省的计数模式中使用)
信道解释 "speakers"

构造器

WaveShaperNode()
 创建一个新的WaveShaperNode 对象的实例。

属性

 包含了继承自父类AudioNode的属性

WaveShaperNode.curve
是一个Float32Array描述要应用的失真数值的数组。
WaveShaperNode.oversample
是一个描述是否必须使用过采样的枚举值。 过采样是一个用来在将失真效果应用到音频信号之前创建更多采样(上采样)的技术。

方法

没有特有的方法; 从父类 AudioNode继承了方法

示例

The following example shows basic usage of an AudioContext to create a wave shaper node. For applied examples/information, check out our Voice-change-O-matic demo (see app.js for relevant code).

Note: Sigmoid functions are commonly used for distortion curves because of their natural properties. Their S-shape, for instance, helps create a smoother sounding result. We found the below distortion curve code on Stack Overflow.

var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var distortion = audioCtx.createWaveShaper();

  ...

function makeDistortionCurve(amount) {
  var k = typeof amount === 'number' ? amount : 50,
    n_samples = 44100,
    curve = new Float32Array(n_samples),
    deg = Math.PI / 180,
    i = 0,
    x;
  for ( ; i < n_samples; ++i ) {
    x = i * 2 / n_samples - 1;
    curve[i] = ( 3 + k ) * x * 20 * deg / ( Math.PI + k * Math.abs(x) );
  }
  return curve;
};

  ...

distortion.curve = makeDistortionCurve(400);
distortion.oversample = '4x';

规范

Specification Status Comment
Web Audio API
WaveShaperNode
Working Draft  

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
WaveShaperNodeChrome Full support 14Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
WaveShaperNode() constructorChrome Full support 55
Notes
Full support 55
Notes
Notes Before Chrome 59, the default values were not supported.
Edge ? Firefox Full support 53IE No support NoOpera Full support 42Safari ? WebView Android Full support 55
Notes
Full support 55
Notes
Notes Before Chrome 59, the default values were not supported.
Chrome Android Full support 55
Notes
Full support 55
Notes
Notes Before Chrome 59, the default values were not supported.
Firefox Android Full support 53Opera Android Full support 42Safari iOS ? Samsung Internet Android Full support 6.0
curveChrome Full support 14Edge Full support 12Firefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
oversampleChrome Full support 14Edge Full support 12Firefox Full support 26IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

相关链接