4 This is a very basic test to make sure testRunner.setAudioData() works correctly.
5 It generates a 2 seconds long stereo result @44.1KHz
6 The left channel will be a 880Hz tone, while the right will be 440Hz.
11 <script src=
"../resources/js-test.js"></script>
12 <script type=
"text/javascript" src=
"resources/audio-testing.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
21 description("Tests basic audio test infrastructure: specifically testRunner.setAudioData()");
23 var sampleRate
= 44100.0;
24 var lengthInSeconds
= 2;
26 function generateSinWave(audioBuffer
) {
27 var n
= audioBuffer
.length
;
28 var channelL
= audioBuffer
.getChannelData(0);
29 var channelR
= audioBuffer
.getChannelData(1);
30 var sampleRate
= audioBuffer
.sampleRate
;
32 for (var i
= 0; i
< n
; ++i
) {
33 channelL
[i
] = Math
.sin(880.0 * 2.0*Math
.PI
* i
/ sampleRate
);
34 channelR
[i
] = Math
.sin(440.0 * 2.0*Math
.PI
* i
/ sampleRate
);
39 if (!window
.testRunner
)
42 var context
= new AudioContext();
43 var audioBuffer
= context
.createBuffer(2, lengthInSeconds
* sampleRate
, sampleRate
);
45 generateSinWave(audioBuffer
);
47 var audioData
= createAudioData(audioBuffer
);
48 testRunner
.setAudioData(audioData
);
50 testRunner
.notifyDone();