Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / test / data / webrtc / webaudio.js
blob73dbd4f4dc4c43c120e6ccab1a4c26604dc574d0
1 /**
2 * Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
7 var gContext = null;
9 function loadAudioAndAddToPeerConnection(url, peerconnection) {
10 if (gContext == null)
11 gContext = new AudioContext();
13 var inputSink = gContext.createMediaStreamDestination();
14 peerconnection.addStream(inputSink.stream);
16 loadAudioBuffer_(url, function(voiceSoundBuffer) {
17 if (peerconnection.webAudioBufferSource)
18 throw failTest('Cannot load more than one sound per peerconnection.');
20 peerconnection.webAudioBufferSource = gContext.createBufferSource();
21 peerconnection.webAudioBufferSource.buffer = voiceSoundBuffer;
22 peerconnection.webAudioBufferSource.connect(inputSink);
23 returnToTest('ok-added');
24 });
27 function playPreviouslyLoadedAudioFile(peerconnection) {
28 if (!peerconnection.webAudioBufferSource)
29 throw failTest('Must call loadAudioAndAddToPeerConnection before this.');
30 peerconnection.webAudioBufferSource.start(gContext.currentTime);
33 /** @private */
34 function loadAudioBuffer_(url, callback) {
35 var request = new XMLHttpRequest();
36 request.open('GET', url, true);
37 request.responseType = 'arraybuffer';
39 request.onload = function() {
40 gContext.decodeAudioData(request.response, function (decodedAudio) {
41 voiceSoundBuffer = decodedAudio;
42 callback(voiceSoundBuffer);
43 });
45 request.send();