4 Tests that an audio-rate signal (AudioNode output) can be connected to an AudioParam.
5 Specifically, this tests that an audio-rate signal coming from an AudioBufferSourceNode
6 playing an AudioBuffer containing a specific curve can be connected to an AudioGainNode's
7 .gain attribute (an AudioParam). Another AudioBufferSourceNode will be the audio source
8 having its gain changed. We load this one with an AudioBuffer containing a constant value of 1.
9 Thus it's easy to check that the resultant signal should be equal to the gain-scaling curve.
14 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
15 <script src="resources/audio-testing.js"></script>
16 <script src="../fast/js/resources/js-test-pre.js"></script>
23 var sampleRate = 44100.0;
24 var lengthInSeconds = 1;
27 var constantOneBuffer = 0;
28 var linearRampBuffer = 0;
30 function checkResult(event) {
31 var renderedBuffer = event.renderedBuffer;
32 var renderedData = renderedBuffer.getChannelData(0);
33 var expectedData = linearRampBuffer.getChannelData(0);
34 var n = renderedBuffer.length;
36 if (n == linearRampBuffer.length) {
37 testPassed("Rendered signal is of correct length.");
39 testFailed("Rendered signal is not of correct length.");
42 // Check that the rendered result exactly matches the buffer used to control gain.
43 // This is because we're changing the gain of a signal having constant value 1.
45 for (var i = 0; i < n; ++i) {
46 if (renderedData[i] != expectedData[i]) {
53 testPassed("Rendered signal exactly matches the audio-rate gain changing signal.");
55 testFailed("Rendered signal differs from the audio-rate gain changing signal.");
62 if (window.testRunner) {
63 testRunner.dumpAsText();
64 testRunner.waitUntilDone();
67 window.jsTestIsAsync = true;
69 var sampleFrameLength = sampleRate * lengthInSeconds;
71 // Create offline audio context.
72 context = new webkitOfflineAudioContext(1, sampleFrameLength, sampleRate);
74 // Create buffer used by the source which will have its gain controlled.
75 constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
77 // Create buffer used to control gain.
78 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength);
80 // Create the two sources.
82 var constantSource = context.createBufferSource();
83 constantSource.buffer = constantOneBuffer;
85 var gainChangingSource = context.createBufferSource();
86 gainChangingSource.buffer = linearRampBuffer;
88 // Create a gain node controlling the gain of constantSource and make the connections.
89 var gainNode = context.createGainNode();
91 // Intrinsic baseline gain of zero.
92 gainNode.gain.value = 0;
94 constantSource.connect(gainNode);
95 gainNode.connect(context.destination);
97 // Connect an audio-rate signal to control the .gain AudioParam.
98 // This is the heart of what is being tested.
99 gainChangingSource.connect(gainNode.gain);
101 // Start both sources at time 0.
102 constantSource.noteOn(0);
103 gainChangingSource.noteOn(0);
105 context.oncomplete = checkResult;
106 context.startRendering();
110 successfullyParsed = true;
113 <script src="../fast/js/resources/js-test-post.js"></script>