From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../zh-cn/web/api/oscillatornode/detune/index.html | 120 +++++++++++++ .../web/api/oscillatornode/frequency/index.html | 119 +++++++++++++ files/zh-cn/web/api/oscillatornode/index.html | 190 +++++++++++++++++++++ .../api/oscillatornode/oscillatornode/index.html | 107 ++++++++++++ .../api/oscillatornode/setperiodicwave/index.html | 140 +++++++++++++++ files/zh-cn/web/api/oscillatornode/stop/index.html | 121 +++++++++++++ 6 files changed, 797 insertions(+) create mode 100644 files/zh-cn/web/api/oscillatornode/detune/index.html create mode 100644 files/zh-cn/web/api/oscillatornode/frequency/index.html create mode 100644 files/zh-cn/web/api/oscillatornode/index.html create mode 100644 files/zh-cn/web/api/oscillatornode/oscillatornode/index.html create mode 100644 files/zh-cn/web/api/oscillatornode/setperiodicwave/index.html create mode 100644 files/zh-cn/web/api/oscillatornode/stop/index.html (limited to 'files/zh-cn/web/api/oscillatornode') diff --git a/files/zh-cn/web/api/oscillatornode/detune/index.html b/files/zh-cn/web/api/oscillatornode/detune/index.html new file mode 100644 index 0000000000..436ea0a26d --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/detune/index.html @@ -0,0 +1,120 @@ +--- +title: OscillatorNode.detune +slug: Web/API/OscillatorNode/detune +translation_of: Web/API/OscillatorNode/detune +--- +

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

+ +
+

{{ domxref("OscillatorNode") }} 的 detune 属性的接口是 a-rate {{domxref("AudioParam")}} ,代表振荡频率的失谐量(cents)。

+
+ +

语法

+ +
var oscillator = audioCtx.createOscillator();
+oscillator.detune.value = 100; // value in cents
+ +
+

Note: 虽然返回的 AudioParam 是只读的,但是它表示的值不是。

+
+ +

 值

+ +

一个 a-rate {{domxref("AudioParam")}} 的值

+ +

示例

+ +

下面的例子使用 {{ domxref("AudioContext") }} 创建了一个 oscillator node。 这是已经在运行的例子,查看 Violent Theremin demo (see app.js 是相关源码)。

+ +
// create web audio api context
+var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
+
+// create Oscillator node
+var oscillator = audioCtx.createOscillator();
+
+oscillator.type = 'square';
+oscillator.frequency.value = 440; // value in hertz
+oscillator.detune.value = 100; // value in cents
+oscillator.start();
+ +

说明

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#widl-OscillatorNode-detune', 'detune')}}{{Spec2('Web Audio API')}} 
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support14 {{property_prefix("webkit")}}{{CompatVersionUnknown}}23{{CompatNo}}15 {{property_prefix("webkit")}}
+ 22 (unprefixed)
6 {{property_prefix("webkit")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeEdgeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatNo}}28 {{property_prefix("webkit")}}{{CompatVersionUnknown}}251.2{{CompatNo}}{{CompatNo}}6 {{property_prefix("webkit")}}
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/oscillatornode/frequency/index.html b/files/zh-cn/web/api/oscillatornode/frequency/index.html new file mode 100644 index 0000000000..156531a8e6 --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/frequency/index.html @@ -0,0 +1,119 @@ +--- +title: OscillatorNode.frequency +slug: Web/API/OscillatorNode/frequency +translation_of: Web/API/OscillatorNode/frequency +--- +

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

+ +
+

{{ domxref("OscillatorNode") }} 的 frequency 属性的接口a-rate {{domxref("AudioParam")}},表示振荡的频率,单位HZ(hertz)

+
+ +

语法

+ +
var oscillator = audioCtx.createOscillator();
+oscillator.frequency.value = 440; // value in hertz
+ +
+

Note: 虽然返回的 AudioParam 是只读的,但是它表示的值不是。

+
+ +

+ +

一个 a-rate {{domxref("AudioParam")}} 的值

+ +

示例

+ +

下列示例使用 {{ domxref("AudioContext") }} 创建了一个 oscillator node. 这是一个用于展示的示例,查看 Violent Theremin demo (see app.js 是相关代码).

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

说明

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#widl-OscillatorNode-frequency', 'frequency')}}{{Spec2('Web Audio API')}} 
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support14 {{property_prefix("webkit")}}{{CompatVersionUnknown}}23{{CompatNo}}15 {{property_prefix("webkit")}}
+ 22 (unprefixed)
6 {{property_prefix("webkit")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeEdgeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatNo}}28 {{property_prefix("webkit")}}{{CompatVersionUnknown}}251.2{{CompatNo}}{{CompatNo}}6 {{property_prefix("webkit")}}
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/oscillatornode/index.html b/files/zh-cn/web/api/oscillatornode/index.html new file mode 100644 index 0000000000..7b1bf096bc --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/index.html @@ -0,0 +1,190 @@ +--- +title: OscillatorNode +slug: Web/API/OscillatorNode +translation_of: Web/API/OscillatorNode +--- +

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

+ +

OscillatorNode 接口表示一个振荡器,它产生一个周期的波形信号(如正弦波)。它是一个 {{domxref("AudioScheduledSourceNode")}} 音频处理模块, 这个模块会生成一个指定频率的波形信号(即一个固定的音调)

+ +

一个 OscillatorNode 对象是通过 {{domxref("AudioContext.createOscillator()")}} 方法创建的。它总是有一个输出,但没有输入。它的基础属性(定义见 {{domxref("AudioNode")}} )默认如下:

+ + + + + + + + + + + + + + + + + + + + + + + + +
Number of inputs0
Number of outputs1
Channel count modemax
Channel count2 (not used in the default count mode)
Channel interpretationspeakers
+ +

构造函数

+ +
+
{{domxref("OscillatorNode.OscillatorNode", "OscillatorNode()")}}
+
创建一个OscillatorNode对象的示例, 为node{{anch("properties")}}提供可选的一个定义默认值的对象.  如果默认值可接受,你可以简单地调用{{domxref("AudioContext.createOscillator()")}}工厂方法.
+
+ +

属性

+ +

继承自父类 {{domxref("AudioScheduledSourceNode")}},并添加下列属性:

+ +
+
{{domxref("OscillatorNode.frequency")}}
+
一个 a-rate {{domxref("AudioParam")}} 对象的属性代表了振动的频率(单位为赫兹hertz) (虽然返回的AudioParam 是只读的,但是它所表示的值是可以修改的)。 默认值是 440 Hz (基本的中A音高).
+
+ +
+
{{domxref("OscillatorNode.detune")}}
+
一个 a-rate {{domxref("AudioParam")}} 对象的属性代表振动的音高微调(单位是cent音分)  (虽然返回的AudioParam 是只读的,但是它所表示的值是可以修改的).。默认值是0。
+
+ +
+
{{domxref("OscillatorNode.type")}}
+
一个字符串,决定 OscillatorNode 播放的声音的周期波形; 它的值可以是基础值中的一个或者用户使用 {{domxref("PeriodicWave")}}。不同的波形可以产生不同的声调。 基础值有 "sine", "square", "sawtooth", "triangle" and "custom". 默认值是"sine"。
+
+ +

方法

+ +

继承自父级, {{domxref("AudioScheduledSourceNode")}}, 自有方法如下:

+ +
+
{{domxref("OscillatorNode.setPeriodicWave()")}}
+
设置一个 {{domxref("PeriodicWave")}} ,它描述了一个周期的波形常常替代标准波形之一; 调用这个方法来设置用户自定义的波形。它取代了已经废弃了的 {{domxref("OscillatorNode.setWaveTable()")}} 方法。
+
+ +

示例

+ +

下面示例展示了 {{ domxref("AudioContext") }} 的基本使用 来创建一个 oscillator 节点 并使用它来播放音乐。这是已经在运行的例子,可以看这里 Violent Theremin demo (see app.js 是相关代码).

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

说明

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#the-oscillatornode-interface', 'OscillatorNode')}}{{Spec2('Web Audio API')}}
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support14 {{property_prefix("webkit")}}{{CompatVersionUnknown}}25{{CompatNo}}15 {{property_prefix("webkit")}}
+ 22 (unprefixed)
6 {{property_prefix("webkit")}}
constructor{{CompatChrome(55.0)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(42)}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewEdgeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari MobileChrome for Android
Basic support{{CompatNo}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}251.2{{CompatNo}}{{CompatNo}}6 {{property_prefix("webkit")}}28 {{property_prefix("webkit")}}
constructor{{CompatNo}}{{CompatChrome(55.0)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOpera(42)}}{{CompatUnknown}}{{CompatChrome(55.0)}}
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/oscillatornode/oscillatornode/index.html b/files/zh-cn/web/api/oscillatornode/oscillatornode/index.html new file mode 100644 index 0000000000..cea622d021 --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/oscillatornode/index.html @@ -0,0 +1,107 @@ +--- +title: OscillatorNode() +slug: Web/API/OscillatorNode/OscillatorNode +translation_of: Web/API/OscillatorNode/OscillatorNode +--- +

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

+ +

OscillatorNode() 构造器创建了一个新的 {{domxref("OscillatorNode")}} 对象,也是 {{domxref("AudioNode")}} 类型,表示一个周期的波形,例如正弦波,用来在不同的对象中定义其可选属性的值

+ +

如果属性的默认值可接受,也可以选择使用 {{domxref("AudioContext.createOscillator()")}} 工厂方法构造 {{domxref("OscillatorNode")}} 对象。

+ +

语法

+ +
var oscillatorNode = new OscillatorNode(context, options)
+ +

参数

+ +
+
context
+
指向 {{domxref("AudioContext")}} 的引用。
+
options {{optional_inline}}
+
一个用来给 oscillator node 的属性指定值得对象,该对象中省略的属性都将采用默认值 +
+
type
+
oscillator node 产生的波形的形状。可用的值有 'sine', 'square', 'sawtooth', 'triangle' 和 'custom',默认值是'sine'。
+
detune
+
音高微调值(cents)可以对给定的频率值进行偏移。 默认值是0.
+
frequency
+
周期性波形的频率 (in {{interwiki("wikipedia", "hertz")}})。 默认值是440.
+
periodicWave
+
任意的周期性波形,通过一个 {{domxref("PeriodicWave")}} 对象描述。
+
+
+
+ +

说明

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API','#the-oscillatornode-interface','OscillatorNode()')}}{{Spec2('Web Audio API')}}Initial definition.
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(55)}}[1]{{CompatGeckoDesktop(25)}}{{CompatUnknown}}{{CompatOpera(42)}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari Mobile
Basic support{{CompatChrome(55)}}[1]{{CompatChrome(55)}}[1]{{CompatGeckoMobile(25)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOperaMobile(42)}}{{CompatUnknown}}
+
+ +

[1] Chrome 59 之前,不支持默认属性。 

diff --git a/files/zh-cn/web/api/oscillatornode/setperiodicwave/index.html b/files/zh-cn/web/api/oscillatornode/setperiodicwave/index.html new file mode 100644 index 0000000000..43f27ec698 --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/setperiodicwave/index.html @@ -0,0 +1,140 @@ +--- +title: OscillatorNode.setPeriodicWave() +slug: Web/API/OscillatorNode/setPeriodicWave +translation_of: Web/API/OscillatorNode/setPeriodicWave +--- +

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

+ +

 {{ domxref("OscillatorNode") }} 接口的 setPeriodicWave() 方法用来指向 {{domxref("PeriodicWave")}},PeriodicWave 定义了一个周期性波形能够形成oscillator的输出, 当{{domxref("OscillatorNode.type", "type")}} 是 custom 的时候.

+ +
+

该方法取代了废弃的 {{ domxref("OscillatorNode.setWaveTable()")}}.

+
+ +

语法

+ +
OscillatorNode.setPeriodicWave(wave);
+ +

参数

+ +
+
wave
+
一个 {{domxref("PeriodicWave")}} 对象, 表示特定的波形用来形成oscillator的输出。
+
+ +

返回值

+ +

{{jsxref("undefined")}}

+ +

示例

+ +

下面示例说明了 createPeriodicWave() 方法的简单使用, 从一个周期波形中重新生成了一个正弦波形。

+ +
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);
+
+osc.setPeriodicWave(wave);
+
+osc.connect(ac.destination);
+
+osc.start();
+osc.stop(2);
+ +

这段代码可以运行因为通过定义一个正弦波形使得声音包含了基础的音调。
+  

+ +

这里,我们用两个值创建一个{{domxref("PeriodicWave")}}。第一个值是直流偏移,是oscillator开始的时候的值。这里 0 很合适,因为我们想要在 [-1.0; 1.0] 这个范围的中间值开始。

+ +

第二个和后面的值是正弦和余弦内容。可以把它看做傅里叶变换的结果,使得可以从时间阈值得到频率阈值。这里通过 createPeriodicWave() 方法,可以指定频率,并且浏览器执行逆傅里叶变换来得到一个时间阈值缓冲。Here, we only set one component at full volume (1.0) on the fundamental tone, so we get a sine wave.

+ +

说明

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#widl-OscillatorNode-setPeriodicWave-void-PeriodicWave-periodicWave', 'setPeriodicWave')}}{{Spec2('Web Audio API')}} 
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support14 {{property_prefix("webkit")}}{{CompatVersionUnknown}}23{{CompatNo}}15 {{property_prefix("webkit")}}
+ 22 (unprefixed)
6 {{property_prefix("webkit")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeEdgeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatNo}}28 {{property_prefix("webkit")}}{{CompatVersionUnknown}}251.2{{CompatNo}}{{CompatNo}}6 {{property_prefix("webkit")}}
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/oscillatornode/stop/index.html b/files/zh-cn/web/api/oscillatornode/stop/index.html new file mode 100644 index 0000000000..3b776727b6 --- /dev/null +++ b/files/zh-cn/web/api/oscillatornode/stop/index.html @@ -0,0 +1,121 @@ +--- +title: OscillatorNode.stop() +slug: Web/API/OscillatorNode/stop +translation_of: Web/API/OscillatorNode/stop +--- +

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

+ +
+

这个 stop方法 {{ domxref("OscillatorNode") }} 接口在指定时间内停止播放,它的参数是可选的,默认情况下是0.

+
+ +

语法

+ +
oscillator.stop(when); // stop playing oscillator at when
+ +

参数

+ +
+
when
+
An optional double representing the audio context time when the oscillator should stop. If a value is not included, it defaults to 0. If the time is equal to or before the current audio context time, the oscillator will stop playing immediately.
+
+ +

例如

+ +

下面的示例显示一个基本用法{{ domxref("AudioContext") }}创建子节点。一个应用的例子,看看我们的演示( Violent Theremin demo (see app.js for relevant code).

+ +
// create web audio api context
+var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
+
+// create Oscillator node
+var oscillator = audioCtx.createOscillator();
+oscillator.connect(audioCtx.destination);
+
+oscillator.start();
+
+oscillator.stop(audioCtx.currentTime + 2); // stop 2 seconds after the current time
+
+ +

规定

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#widl-OscillatorNode-stop-void-double-when', 'stop')}}{{Spec2('Web Audio API')}} 
+ +

浏览器的兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support14 {{property_prefix("webkit")}}{{CompatVersionUnknown}}23 [1]{{CompatNo}}15 {{property_prefix("webkit")}}
+ 22 (unprefixed)
6 {{property_prefix("webkit")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeEdgeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatNo}}{{CompatVersionUnknown}}28 {{property_prefix("webkit")}}25 [1]1.2{{CompatNo}}{{CompatNo}}6 {{property_prefix("webkit")}}
+
+ +

[1] The parameter wasn't optional until Firefox 30.

+ +

See also

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