From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../createconstantsource/index.html | 110 ++++++++ .../baseaudiocontext/createoscillator/index.html | 64 +++++ .../baseaudiocontext/createperiodicwave/index.html | 101 +++++++ files/zh-cn/web/api/baseaudiocontext/index.html | 292 +++++++++++++++++++++ 4 files changed, 567 insertions(+) create mode 100644 files/zh-cn/web/api/baseaudiocontext/createconstantsource/index.html create mode 100644 files/zh-cn/web/api/baseaudiocontext/createoscillator/index.html create mode 100644 files/zh-cn/web/api/baseaudiocontext/createperiodicwave/index.html create mode 100644 files/zh-cn/web/api/baseaudiocontext/index.html (limited to 'files/zh-cn/web/api/baseaudiocontext') diff --git a/files/zh-cn/web/api/baseaudiocontext/createconstantsource/index.html b/files/zh-cn/web/api/baseaudiocontext/createconstantsource/index.html new file mode 100644 index 0000000000..6bff3de1e9 --- /dev/null +++ b/files/zh-cn/web/api/baseaudiocontext/createconstantsource/index.html @@ -0,0 +1,110 @@ +--- +title: BaseAudioContext.createConstantSource() +slug: Web/API/BaseAudioContext/createConstantSource +translation_of: Web/API/BaseAudioContext/createConstantSource +--- +

{{APIRef("Web Audio API")}}

+ +

 createConstantSource() 是 {{domxref("BaseAudioContext")}} 接口的一个方法, 用于生成一个 {{domxref("ConstantSourceNode")}} 对象, 该对象是一个输出单信道(one-channel)音频信号的音频源,这些音频信号都拥有一个恒定的样本值。

+ +

Syntax

+ +
var constantSourceNode = AudioContext.createConstantSource()
+ +

Parameters

+ +

None.

+ +

Returns

+ +

A {{domxref('ConstantSourceNode')}} instance.

+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API','#dom-baseaudiocontext-createconstantsource','createConstantSource()')}}{{Spec2('Web Audio API')}}Initial definition.
+ +

Browser Compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(56.0)}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatOpera(43)}}{{CompatUnknown}}
Implemented on AudioContext{{CompatChrome(10.0)}}{{property_prefix("webkit")}}{{CompatVersionUnknown}}{{CompatNo}}15.0{{property_prefix("webkit")}}
+ 22 (unprefixed)
6.0{{property_prefix("webkit")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome for Android
Basic support{{CompatNo}}{{CompatChrome(56.0)}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatOperaMobile(43)}}{{CompatUnknown}}{{CompatChrome(56.0)}}
Implemented on AudioContext{{CompatUnknown}}{{CompatVersionUnknown}}26.0{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}33.0
+
diff --git a/files/zh-cn/web/api/baseaudiocontext/createoscillator/index.html b/files/zh-cn/web/api/baseaudiocontext/createoscillator/index.html new file mode 100644 index 0000000000..3b992092cc --- /dev/null +++ b/files/zh-cn/web/api/baseaudiocontext/createoscillator/index.html @@ -0,0 +1,64 @@ +--- +title: BaseAudioContext.createOscillator() +slug: Web/API/BaseAudioContext/createOscillator +translation_of: Web/API/BaseAudioContext/createOscillator +--- +

{{APIRef("Web Audio API")}}

+ +

{{domxref("BaseAudioContext")}}接口的createOscillator()方法创建一个{{domxref("OscillatorNode")}},它是一个表示周期性波形的源。 它基本上产生一个不变的音调。

+ +

Syntax

+ +
var oscillatorNode = audioCtx.createOscillator();
+ +

Returns

+ +

An {{domxref("OscillatorNode")}}.

+ +

Example

+ +

以下示例显示了用于创建振荡器节点的AudioContext的基本用法。 有关应用示例/信息,请查看我们的Violent Theremin demo(有关相关代码,请参阅see app.js); 另请参阅我们的OscillatorNode页面以获取更多信息。

+ +
// create web audio api context
+var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
+
+// create Oscillator node
+var oscillator = audioCtx.createOscillator();
+
+oscillator.type = 'square';
+oscillator.frequency.setValueAtTime(3000, audioCtx.currentTime); // value in hertz
+oscillator.connect(audioCtx.destination);
+oscillator.start();
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#dom-baseaudiocontext-createoscillator', 'createOscillator')}}{{Spec2('Web Audio API')}} 
+ +

Browser compatibility

+ +
+
+ + +

{{Compat("api.BaseAudioContext.createOscillator")}}

+
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/baseaudiocontext/createperiodicwave/index.html b/files/zh-cn/web/api/baseaudiocontext/createperiodicwave/index.html new file mode 100644 index 0000000000..ae4d038165 --- /dev/null +++ b/files/zh-cn/web/api/baseaudiocontext/createperiodicwave/index.html @@ -0,0 +1,101 @@ +--- +title: BaseAudioContext.createPeriodicWave() +slug: Web/API/BaseAudioContext/createPeriodicWave +translation_of: Web/API/BaseAudioContext/createPeriodicWave +--- +

{{ APIRef("Web Audio API") }}

+ +
+

{{ domxref("BaseAudioContext") }} 接口的 createPeriodicWave() 方法用于创建可对 {{ domxref("OscillatorNode") }} 输出进行整形的 {{domxref("PeriodicWave")}}(周期波)。

+
+ +

语法

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

返回值

+ +

一个 {{domxref("PeriodicWave")}}.

+ +

参数

+ +
+
real
+
一系列余弦术语 (传统上的 A 项)。
+
imag
+
一系列正弦项 (传统上的 B 项)。
+
constraints {{optional_inline}}
+
一个字典对象,用于指定是否禁用规范化(如果没有指定,则默认启动规范化)。它有一个属性: +
    +
  • disableNormalization: 如果设置为 true,对周期波禁用规范化。默认值为 false.
  • +
+
+
+ +
+

如果使用规范化,生成波形的最大绝对峰值为1。

+
+ +

例子

+ +

下面的例子为 createPeriodicWave() 的简单用法,创建包含简单正弦波的 {{domxref("PeriodicWave")}} 对象。

+ +
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);
+ +

 

+ +

这之所以有用是因为根据定义仅包含基本音调的声音是正弦波。

+ +

这里,我们创建一个具有两个值的 PeriodicWave (周期波) 。第一个值是 DC(直流) 偏移,它是振荡器启动的值。0在这里是好的,因为我们想在 [-1.0; 1.0] 范围的中间开始曲线。

+ +

第二个值和后续值是正弦和余弦分量。你可以把它看做是傅里叶变换的结果,可以从时域值中获取频域值。这里,使用 createPeriodicWave(),你可以指定频率,浏览器会执行一个逆傅里叶变换,以获得振荡器的时域缓冲。这里,我们只在基础音上设置了一个全音量(1.0)的分量,所以我们得到一个正弦波。

+ +

傅里叶变换系数应该按升序给出 (例如. (a+bi)ei,(c+di)e2i,(f+gi)e3i\left(a+bi\right)e^{i} , \left(c+di\right)e^{2i} , \left(f+gi\right)e^{3i}    等.) 可以是正的或者是负的。一个简单的手动获取此类系数的方法是使用图形计算器,尽管这不是最好的。

+ +

规格

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#dom-baseaudiocontext-createperiodicwave', 'createPeriodicWave')}}{{Spec2('Web Audio API')}} 
+ +

浏览器兼容性

+ +
+ + +

{{Compat("api.BaseAudioContext.createPeriodicWave")}}

+
+ +

参见

+ + diff --git a/files/zh-cn/web/api/baseaudiocontext/index.html b/files/zh-cn/web/api/baseaudiocontext/index.html new file mode 100644 index 0000000000..5d11d7fe82 --- /dev/null +++ b/files/zh-cn/web/api/baseaudiocontext/index.html @@ -0,0 +1,292 @@ +--- +title: BaseAudioContext +slug: Web/API/BaseAudioContext +tags: + - API + - Audio + - BaseAudioContext + - Interface + - NeedsTranslation + - Reference + - TopicStub + - Web Audio API +translation_of: Web/API/BaseAudioContext +--- +
{{APIRef("Web Audio API")}}
+ +

The BaseAudioContext interface acts as a base definition for online and offline audio-processing graphs, as represented by {{domxref("AudioContext")}} and {{domxref("OfflineAudioContext")}} respectively. You wouldn't use BaseAudioContext directly — you'd use its features via one of these two inheriting interfaces.

+ +

A BaseAudioContext can be a target of events, therefore it implements the {{domxref("EventTarget")}} interface.

+ +

{{InheritanceDiagram}}

+ +

Properties

+ +
+
{{domxref("BaseAudioContext.audioWorklet")}} {{experimental_inline}} {{readonlyInline}}
+
Returns the {{domxref("AudioWorklet")}} object, used for creating custom AudioNodes with JavaScript processing.
+
{{domxref("BaseAudioContext.currentTime")}} {{readonlyInline}}
+
Returns a double representing an ever-increasing hardware time in seconds used for scheduling. It starts at 0.
+
{{domxref("BaseAudioContext.destination")}} {{readonlyInline}}
+
Returns an {{domxref("AudioDestinationNode")}} representing the final destination of all audio in the context. It can be thought of as the audio-rendering device.
+
{{domxref("BaseAudioContext.listener")}} {{readonlyInline}}
+
Returns the {{domxref("AudioListener")}} object, used for 3D spatialization.
+
{{domxref("BaseAudioContext.sampleRate")}} {{readonlyInline}}
+
Returns a float representing the sample rate (in samples per second) used by all nodes in this context. The sample-rate of an {{domxref("AudioContext")}} cannot be changed.
+
{{domxref("BaseAudioContext.state")}} {{readonlyInline}}
+
Returns the current state of the AudioContext.
+
+ +

Event handlers

+ +
+
{{domxref("BaseAudioContext.onstatechange")}}
+
An event handler that runs when an event of type {{event("statechange")}} has fired. This occurs when the AudioContext's state changes, due to the calling of one of the state change methods ({{domxref("AudioContext.suspend")}}, {{domxref("AudioContext.resume")}}, or {{domxref("AudioContext.close")}}).
+
+ +

Methods

+ +

Also implements methods from the interface {{domxref("EventTarget")}}.

+ +
+
{{domxref("BaseAudioContext.createBuffer()")}}
+
Creates a new, empty {{ domxref("AudioBuffer") }} object, which can then be populated by data and played via an {{ domxref("AudioBufferSourceNode") }}.
+
{{domxref("BaseAudioContext.createConstantSource()")}}
+
Creates a {{domxref("ConstantSourceNode")}} object, which is an audio source that continuously outputs a monaural (one-channel) sound signal whose samples all have the same value.
+
{{domxref("BaseAudioContext.createBufferSource()")}}
+
Creates an {{domxref("AudioBufferSourceNode")}}, which can be used to play and manipulate audio data contained within an {{ domxref("AudioBuffer") }} object. {{ domxref("AudioBuffer") }}s are created using {{domxref("AudioContext.createBuffer")}} or returned by {{domxref("AudioContext.decodeAudioData")}} when it successfully decodes an audio track.
+
{{domxref("BaseAudioContext.createScriptProcessor()")}}
+
Creates a {{domxref("ScriptProcessorNode")}}, which can be used for direct audio processing via JavaScript.
+
{{domxref("BaseAudioContext.createStereoPanner()")}}
+
Creates a {{domxref("StereoPannerNode")}}, which can be used to apply stereo panning to an audio source.
+
{{domxref("BaseAudioContext.createAnalyser()")}}
+
Creates an {{domxref("AnalyserNode")}}, which can be used to expose audio time and frequency data and for example to create data visualisations.
+
{{domxref("BaseAudioContext.createBiquadFilter()")}}
+
Creates a {{domxref("BiquadFilterNode")}}, which represents a second order filter configurable as several different common filter types: high-pass, low-pass, band-pass, etc.
+
{{domxref("BaseAudioContext.createChannelMerger()")}}
+
Creates a {{domxref("ChannelMergerNode")}}, which is used to combine channels from multiple audio streams into a single audio stream.
+
{{domxref("BaseAudioContext.createChannelSplitter()")}}
+
Creates a {{domxref("ChannelSplitterNode")}}, which is used to access the individual channels of an audio stream and process them separately.
+
{{domxref("BaseAudioContext.createConvolver()")}}
+
Creates a {{domxref("ConvolverNode")}}, which can be used to apply convolution effects to your audio graph, for example a reverberation effect.
+
{{domxref("BaseAudioContext.createDelay()")}}
+
Creates a {{domxref("DelayNode")}}, which is used to delay the incoming audio signal by a certain amount. This node is also useful to create feedback loops in a Web Audio API graph.
+
{{domxref("BaseAudioContext.createDynamicsCompressor()")}}
+
Creates a {{domxref("DynamicsCompressorNode")}}, which can be used to apply acoustic compression to an audio signal.
+
{{domxref("BaseAudioContext.createGain()")}}
+
Creates a {{domxref("GainNode")}}, which can be used to control the overall volume of the audio graph.
+
{{domxref("BaseAudioContext.createIIRFilter()")}}
+
Creates an {{domxref("IIRFilterNode")}}, which represents a second order filter configurable as several different common filter types.
+
{{domxref("BaseAudioContext.createOscillator()")}}
+
Creates an {{domxref("OscillatorNode")}}, a source representing a periodic waveform. It basically generates a tone.
+
{{domxref("BaseAudioContext.createPanner()")}}
+
Creates a {{domxref("PannerNode")}}, which is used to spatialise an incoming audio stream in 3D space.
+
{{domxref("BaseAudioContext.createPeriodicWave()")}}
+
Creates a {{domxref("PeriodicWave")}}, used to define a periodic waveform that can be used to determine the output of an {{ domxref("OscillatorNode") }}.
+
{{domxref("BaseAudioContext.createWaveShaper()")}}
+
Creates a {{domxref("WaveShaperNode")}}, which is used to implement non-linear distortion effects.
+
{{domxref("BaseAudioContext.decodeAudioData()")}}
+
Asynchronously decodes audio file data contained in an {{domxref("ArrayBuffer")}}. In this case, the ArrayBuffer is usually loaded from an {{domxref("XMLHttpRequest")}}'s response attribute after setting the responseType to arraybuffer. This method only works on complete files, not fragments of audio files.
+
{{domxref("BaseAudioContext.resume()")}}
+
Resumes the progression of time in an audio context that has previously been suspended/paused.
+
+ +

Examples

+ +

Basic audio context declaration:

+ +
var audioCtx = new AudioContext();
+ +

Cross browser variant:

+ +
var AudioContext = window.AudioContext || window.webkitAudioContext;
+var audioCtx = new AudioContext();
+
+var oscillatorNode = audioCtx.createOscillator();
+var gainNode = audioCtx.createGain();
+var finish = audioCtx.destination;
+// etc.
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#BaseAudioContext', 'BaseAudioContext')}}{{Spec2('Web Audio API')}} 
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatNo}}15.0{{property_prefix("webkit")}}
+ 22
6.0{{property_prefix("webkit")}}
baseLatency{{CompatChrome(60)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
createConstantSource(){{CompatChrome(56)}}{{CompatNo}}{{CompatGeckoDesktop(52)}}{{CompatNo}}{{CompatOpera(43)}}{{CompatNo}}
createStereoPanner(){{CompatChrome(42)}}{{CompatVersionUnknown}}{{CompatGeckoDesktop(37.0)}} {{CompatNo}}{{CompatNo}}{{CompatNo}}
onstatechange, state, suspend(), resume(){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoDesktop(40.0)}}{{CompatNo}}{{CompatNo}}{{CompatSafari(8.0)}}
Unprefixed{{CompatVersionUnknown}}{{CompatVersionUnknown}}    
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroid WebviewChrome for AndroidEdgeFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}2.2{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
baseLatency{{CompatChrome(60)}}{{CompatChrome(60)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
createConstantSource(){{CompatChrome(56)}}{{CompatChrome(56)}}{{CompatNo}}{{CompatGeckoMobile(52)}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
createStereoPanner(){{CompatChrome(42)}}{{CompatChrome(42)}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
onstatechange, state, suspend(), resume(){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
Unprefixed{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOperaMobile(43)}}{{CompatUnknown}}
+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf