aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/convolvernode/index.html
blob: de43ddc6b33e2d94c1ca54e36ed8531f38daa1ce (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
title: ConvolverNode
slug: Web/API/ConvolverNode
tags:
  - 音效
  - 音频
translation_of: Web/API/ConvolverNode
---
<p>{{APIRef("Web Audio API")}}</p>

<p><code>ConvolverNode</code> 接口是一个对给定 {{domxref("AudioBuffer")}} 上执行线性卷积的 {{domxref("AudioNode")}},一般用来做音频混响效果。每一个 <code>ConvolverNode</code> 都会有一个输入值和输出值。</p>

<div class="note">
<p><strong>注意</strong>: 更多线性卷积理论的相关信息,请参阅<a href="https://en.wikipedia.org/wiki/Convolution">Convolution article on Wikipedia</a>.</p>
</div>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Number of inputs</th>
   <td><code>1</code></td>
  </tr>
  <tr>
   <th scope="row">Number of outputs</th>
   <td><code>1</code></td>
  </tr>
  <tr>
   <th scope="row">Channel count mode</th>
   <td><code>"clamped-max"</code></td>
  </tr>
  <tr>
   <th scope="row">Channel count</th>
   <td><code>1</code>, <code>2</code>, or <code>4</code></td>
  </tr>
  <tr>
   <th scope="row">Channel interpretation</th>
   <td><code>"speakers"</code></td>
  </tr>
 </tbody>
</table>

<h2 id="构造函数">构造函数</h2>

<dl>
 <dt>{{domxref("ConvolverNode.ConvolverNode()", "ConvolverNode()")}}</dt>
 <dd>创建一个新的 <span><code>ConvolverNode</code></span> 对象实例。</dd>
</dl>

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

<p>继承其父级的属性<em>, {{domxref("AudioNode")}}</em>.</p>

<dl>
 <dt>{{domxref("ConvolverNode.buffer")}}</dt>
 <dd>一个被 <span><code>ConvolverNode</code></span> 用来产生混响效果的单声道、立体声或四声道的音频缓冲器,包含了(可能是多声道)脉冲反应(IR)。</dd>
 <dt>{{domxref("ConvolverNode.normalize")}}</dt>
 <dd><span>布尔值,在设置缓冲区属性时,可绝定是否对来自 <code>buffer</code> 的脉冲反应按等功率归一化进行缩放。</span></dd>
</dl>

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

<p>没有具体的方法,从其父继承方法,<em>{{domxref("AudioNode")}}</em>.</p>

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

<p>下面的示例展示了 AudioContext 创建卷积节点的基础用法。</p>

<div class="note">
<p><strong>注意</strong>: 你需要找到一个脉冲反应来完成下面的示例。可查看 <a href="https://codepen.io/DonKarlssonSan/pen/doVKRE">此处</a> 的实例.</p>
</div>

<pre class="brush: js notranslate">let audioCtx = new window.AudioContext();

async function createReverb() {
    let convolver = audioCtx.createConvolver();

    // 从文件加载脉冲反应
    let response     = await fetch("path/to/impulse-response.wav");
    let arraybuffer  = await response.arrayBuffer();
    convolver.buffer = await audioCtx.decodeAudioData(arraybuffer);

    return convolver;
}

...

let reverb = await createReverb();

// someOtherAudioNode -&gt; reverb -&gt; destination
someOtherAudioNode.connect(reverb);
reverb.connect(audioCtx.destination);
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">注释</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Audio API', '#ConvolverNode', 'ConvolverNode')}}</td>
   <td>{{Spec2('Web Audio API')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

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

<div>


<p>{{Compat("api.ConvolverNode")}}</p>
</div>

<h2 id="相关链接">相关链接</h2>

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