aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/audioparam/index.html
blob: af31212d17930ed8b2bd25db6016c9e36349b9ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
title: AudioParam
slug: Web/API/AudioParam
translation_of: Web/API/AudioParam
---
<p>{{APIRef("Web Audio API")}}</p>

<div>
<p><code>AudioParam</code> 接口代表音频相关的参数, 通常是一个 {{domxref("AudioNode")}} (例如 {{ domxref("GainNode.gain") }}) 的参数。一个 <code>AudioParam</code> 可以被设置为一个具体的值或者数值的改变 ,可以被安排在在一个具体的时刻并且遵循一个特定的模式发生。</p>
</div>

<p>下面有两种类型的 <code>AudioParam</code>, <em>a-rate</em> 和 <em>k-rate</em> 参数:</p>

<ul>
 <li id="a-rate">一个 <em>a-rate</em> <code>AudioParam</code> 获取音频信号的每个<a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#Audio_buffers.3A_frames.2C_samples_and_channels">采样帧</a>的当前音频参数值。</li>
 <li id="k-rate">一个 <em>k-rate</em> <code>AudioParam</code> 对于待处理的整个块使用相同的初始音频参数值,即128个采样帧。</li>
</ul>

<p>每个 {{domxref("AudioNode")}} 定义了其规格中哪一个参数是 <em>a-rate</em> 或 <em>k-rate</em></p>

<p>每个 <code>AudioParam</code> 有一个事件的列表,初始化时列表为空。该列表定义了什么时候数值怎么改变。当这个列表不是空的时候,使用 <code>AudioParam.value</code> 属性的改变会被忽略 。事件的列表允许我们去有计划地进行必须在非常精确的时间发生的更改,使用任意的基于时间轴的自动化曲线。被使用的时间在{{domxref("AudioContext.currentTime")}} 中被定义。</p>

<h2 id="属性">属性</h2>

<p><code>AudioParam</code><em> 继承的属性来自于它的父类, </em><code>AudioNode。</code></p>

<dl>
 <dt>{{domxref("AudioParam.defaultValue")}} {{readonlyInline}}</dt>
 <dd>代表被具体的{{domxref("AudioNode")}} 创建的 <code>AudioParam</code> 的属性的初始的音量。</dd>
 <dt>{{domxref("AudioParam.maxValue")}} {{readonlyInline}}</dt>
 <dd>代表参数有效范围的最大可能值。</dd>
 <dt>{{domxref("AudioParam.minValue")}} {{readonlyinline}}</dt>
 <dd>代表参数有效范围的最小可能值。</dd>
 <dt>{{domxref("AudioParam.value")}}</dt>
 <dd>代表参数的浮点数音量值;初始化设定为 <code>AudioParam.defaultValue 的值。虽然它可以被设置,但是任何发生在自动化事件(事件被计划用于 AudioParam )的修改会被忽略,</code>没有任何例外。</dd>
</dl>

<h2 id="方法">方法</h2>

<p>AudioParam<em> 初始化的方法来自它的父类,</em><code>AudioNode</code>.</p>

<dl>
 <dt>{{domxref("AudioParam.setValueAtTime()")}}</dt>
 <dd>在一个确切的时间,即时更改 <code>AudioParam </code>的值,按照{{domxref("AudioContext.currentTime")}} 的时间。新的值会被传递到 <code>value</code> 参数。</dd>
 <dt>{{domxref("AudioParam.linearRampToValueAtTime()")}}</dt>
 <dd>调整 <code>AudioParam 的值,使其逐渐按线性变化。这个改变会从上一个事件指定的事件开始,跟随一个线性“斜坡”到参数给的新值,并在 endTime 参数给定的时间到达新值。</code></dd>
 <dt>{{domxref("AudioParam.exponentialRampToValueAtTime()")}}</dt>
 <dd>调整 <code>AudioParam 的值,使其逐渐按指数变化。这个改变会从上一个事件指定的事件开始,跟随一个指数“斜坡”到参数给的新值,并在 endTime 参数给定的时间到达新值。</code></dd>
 <dt>{{domxref("AudioParam.setTargetAtTime()")}}</dt>
 <dd>将开始计划改变 <code>AudioParam 的值</code>。这个改变将从 <code>startTime 指定的时间开始,并且以指定的方式向目标参数给定的值改变。指数衰减速率由 timeConstant 参数定义,</code>time 参数使以秒作为测量单位的时间。</dd>
 <dt>{{domxref("AudioParam.setValueCurveAtTime()")}}</dt>
 <dd>调整 <code>AudioParam</code> 的值以跟随一组定义为 {{domxref("Float32Array")}} 的值,数值会缩放到适应给定的间隔,,从 <code>startTime 时间开始并具有特定的持续时间(duration)。</code> </dd>
 <dt>{{domxref("AudioParam.cancelScheduledValues()")}}</dt>
 <dd>取消全部在 <code>AudioParam 中</code>的未来计划发生的改变。</dd>
 <dt>{{domxref("AudioParam.cancelAndHoldAtTime()")}}</dt>
 <dd>取消全部计划将来对 <code>AudioParam 的</code>改变,但是保持给定时间的值,直到将来的使用其他方法产生改变。新的值会被赋予到 <code>value</code> 属性中。</dd>
</dl>

<h2 id="例子">例子</h2>

<p>首先,一个基础的例子展示了 {{domxref("GainNode")}} 拥有的 <code>gain</code> 一些值合。<code>gain</code> 是一个 a-rate AudioParam 的例子,因为该值可以针对音频的每个样本帧进行不同的设置。</p>

<pre class="brush: js;highlight[5]">var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();

var gainNode = audioCtx.createGain();
gainNode.gain.value = 0;</pre>

<p>另外,一个例子展示了 {{ domxref("BiquadFilterNode") }} 拥有的一些值。这是一个 k-rate AudioParam 的例子,因为一次为整个音频块设置的值。</p>

<pre class="brush: js;highlight[6,7,8]">var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();

var biquadFilter = audioCtx.createBiquadFilter();

biquadFilter.type = "lowshelf";
biquadFilter.frequency.value = 1000;
biquadFilter.gain.value = 25;</pre>

<h2 id="标准">标准</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Audio API', '#the-audioparam-interface', 'AudioParam')}}</td>
   <td>{{Spec2('Web Audio API')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

{{Compat("api.AudioParam")}}

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web_Audio_API/Using_Web_Audio_API">Using the Web Audio API</a></li>
</ul>