createPeriodicWave() 方法在 BaseAudioContext Interface is used to create a PeriodicWave , which is used to define a periodic waveform that can be used to shape the output of an OscillatorNode .

句法

var wave = AudioContext.createPeriodicWave(real, imag[, constraints]);
					

返回

A PeriodicWave .

参数

real

An array of cosine terms (traditionally the A terms).

imag

An array of sine terms (traditionally the B terms).

real and imag arrays have to have the same length, otherwise an error is thrown.

constraints 可选
An dictionary object that specifies whether normalization should be disabled (if not specified, normalization is enabled by default.) It takes one property:
  • disableNormalization : If set to true , normalization is disabled for the periodic wave. The default is false .

If normalized, the resulting wave will have a maximum absolute peak value of 1.

范例

The following example illustrates simple usage of createPeriodicWave() ,要创建 PeriodicWave object containing a simple sine wave.

var real = new Float32Array(2);
var imag = new Float32Array(2);
var ac = new AudioContext();
var osc = ac.createOscillator();
real[0] = 0;
imag[0] = 0;
real[1] = 1;
imag[1] = 0;
var wave = ac.createPeriodicWave(real, imag, {disableNormalization: true});
osc.setPeriodicWave(wave);
osc.connect(ac.destination);
osc.start();
osc.stop(2);
					

This works because a sound that contains only a fundamental tone is by definition a sine wave

Here, we create a PeriodicWave with two values. The first value is the DC offset, which is the value at which the oscillator starts. 0 is good here, because we want to start the curve at the middle of the [-1.0; 1.0] range.

The second and subsequent values are sine and cosine components. You can think of it as the result of a Fourier transform, where you get frequency domain values from time domain value. Here, with createPeriodicWave() , you specify the frequencies, and the browser performs an inverse Fourier transform to get a time domain buffer for the frequency of the oscillator. Here, we only set one component at full volume (1.0) on the fundamental tone, so we get a sine wave.

The coefficients of the Fourier transform should be given in ascending order (i.e. ( a + b i ) e i , ( c + d i ) e 2 i , ( f + g i ) e 3 i \left(a+bi\right)e^{i} , \left(c+di\right)e^{2i} , \left(f+gi\right)e^{3i} etc.) and can be positive or negative.  A simple way of manually obtaining such coefficients (though not the best) is to use a graphing calculator.

规范

规范 状态 注释
Web 音频 API
The definition of 'createPeriodicWave' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
createPeriodicWave Chrome 59 注意事项
59 注意事项
Default values supported
57
10 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge ≤18 Firefox 53 注意事项
53 注意事项
Originally implemented on AudioContext in Firefox 25.
IE 不支持 No Opera 22
22
15 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari 6 Prefixed
6 Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android 59 注意事项
59 注意事项
Default values supported
57
4.4.3 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android 59 注意事项
59 注意事项
Default values supported
57
33 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 53 注意事项
53 注意事项
Originally implemented on AudioContext in Firefox Android 26.
Opera Android 22
22
14 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 6 Prefixed
6 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Samsung Internet Android 7.0 注意事项
7.0 注意事项
Default values supported
7.0
2.0 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Possible to disable normalisation Chrome Yes Edge ≤18 Firefox 不支持 No IE 不支持 No Opera ? Safari 不支持 No WebView Android Yes Chrome Android Yes Firefox Android 不支持 No Opera Android ? Safari iOS 不支持 No Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. Web 音频 API
  2. BaseAudioContext
  3. 特性
    1. audioWorklet
    2. currentTime
    3. destination
    4. listener
    5. sampleRate
    6. state
  4. 方法
    1. createAnalyser()
    2. createBiquadFilter()
    3. createBuffer()
    4. createBufferSource()
    5. createChannelMerger()
    6. createChannelSplitter()
    7. createConstantSource()
    8. createConvolver()
    9. createDelay()
    10. createDynamicsCompressor()
    11. createGain()
    12. createIIRFilter()
    13. createOscillator()
    14. createPanner()
    15. createPeriodicWave()
    16. createScriptProcessor()
    17. createStereoPanner()
    18. createWaveShaper()
    19. decodeAudioData()
  5. 继承:
    1. EventTarget
  6. Related pages for Web Audio API
    1. AnalyserNode
    2. AudioBuffer
    3. AudioBufferSourceNode
    4. AudioContext
    5. AudioContextOptions
    6. AudioDestinationNode
    7. AudioListener
    8. AudioNode
    9. AudioNodeOptions
    10. AudioParam
    11. AudioProcessingEvent
    12. AudioScheduledSourceNode
    13. AudioWorklet
    14. AudioWorkletGlobalScope
    15. AudioWorkletNode
    16. AudioWorkletProcessor
    17. BiquadFilterNode
    18. ChannelMergerNode
    19. ChannelSplitterNode
    20. ConstantSourceNode
    21. ConvolverNode
    22. DelayNode
    23. DynamicsCompressorNode
    24. GainNode
    25. IIRFilterNode
    26. MediaElementAudioSourceNode
    27. MediaStreamAudioDestinationNode
    28. MediaStreamAudioSourceNode
    29. OfflineAudioCompletionEvent
    30. OfflineAudioContext
    31. OscillatorNode
    32. PannerNode
    33. PeriodicWave
    34. StereoPannerNode
    35. WaveShaperNode

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1