aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/audioparam/setvalueattime/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ru/web/api/audioparam/setvalueattime/index.html')
-rw-r--r--files/ru/web/api/audioparam/setvalueattime/index.html97
1 files changed, 97 insertions, 0 deletions
diff --git a/files/ru/web/api/audioparam/setvalueattime/index.html b/files/ru/web/api/audioparam/setvalueattime/index.html
new file mode 100644
index 0000000000..f60d3e7d99
--- /dev/null
+++ b/files/ru/web/api/audioparam/setvalueattime/index.html
@@ -0,0 +1,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>