blob: 202e13d971cb80277f3a0d2b3d6800ff4d1dc1dd (
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
|
---
title: AudioParam.setValueAtTime()
slug: Web/API/AudioParam/setValueAtTime
translation_of: Web/API/AudioParam/setValueAtTime
---
<p>{{ APIRef("Web Audio API") }}</p>
<p class="summary"><code>setValueAtTime()</code> метод интерфейса {{domxref("AudioParam")}} позволяющий мгновенно точно по времени изменять значение <code>AudioParam</code> , сравнивая с {{domxref("AudioContext.currentTime")}}. Новое значение даётся в значении параметра.</p>
<h2 id="Синтаксис">Синтаксис</h2>
<pre class="syntaxbox notranslate">var AudioParam = AudioParam.setValueAtTime(<em>value</em>, <em>startTime</em>)</pre>
<h3 id="Параметры">Параметры</h3>
<dl>
<dt>value</dt>
<dd>Число с плавающей точкой представляет значение AudioParam изменяемое в данное время.</dd>
<dt>startTime</dt>
<dd>A double representing the time (in seconds) after the {{domxref("AudioContext")}} was first created that the change in value will happen. A {{jsxref("TypeError")}} is thrown if this value is negative.</dd>
</dl>
<h3 id="Returns">Returns</h3>
<p>A reference to this <code>AudioParam</code> object. In some browsers older implementations of this interface return void.</p>
<h2 id="Examples">Examples</h2>
<p>This simple example features a media element source with two control buttons (see our <a href="https://github.com/mdn/webaudio-examples/blob/master/audio-param/index.html">webaudio-examples repo</a> for the source code, or <a href="https://mdn.github.io/webaudio-examples/audio-param/">view the example live</a>). When the buttons are pressed, the <code>currGain</code> variable is incremented/decremented by 0.25, then the <code>setValueAtTime()</code> method is used to set the gain value equal to <code>currGain</code>, one second from now (<code>audioCtx.currentTime + 1</code>.)</p>
<pre class="brush: js;highlight[32,37] notranslate">// create audio context
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();
// set basic variables for example
var myAudio = document.querySelector('audio');
var pre = document.querySelector('pre');
var myScript = document.querySelector('script');
pre.innerHTML = myScript.innerHTML;
var targetAtTimePlus = document.querySelector('.set-target-at-time-plus');
var targetAtTimeMinus = document.querySelector('.set-target-at-time-minus');
// Create a MediaElementAudioSourceNode
// Feed the HTMLMediaElement into it
var source = audioCtx.createMediaElementSource(myAudio);
// Create a gain node and set it's gain value to 0.5
var gainNode = audioCtx.createGain();
gainNode.gain.value = 0.5;
var currGain = gainNode.gain.value;
// connect the AudioBufferSourceNode to the gainNode
// and the gainNode to the destination
source.connect(gainNode);
gainNode.connect(audioCtx.destination);
// set buttons to do something onclick
targetAtTimePlus.onclick = function() {
currGain += 0.25;
gainNode.gain.setValueAtTime(currGain, audioCtx.currentTime + 1);
}
targetAtTimeMinus.onclick = function() {
currGain -= 0.25;
gainNode.gain.setValueAtTime(currGain, audioCtx.currentTime + 1);
}</pre>
<h2 id="Specifications">Specifications</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', '#dom-audioparam-setvalueattime', 'setValueAtTime')}}</td>
<td>{{Spec2('Web Audio API')}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.AudioParam.setValueAtTime")}}</p>
<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>
|