| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 | |
| 3 <!-- | |
| 4 Tests that an audio-rate signal (AudioNode output) can be connected to an AudioP
aram. | |
| 5 Specifically, this tests that an audio-rate signal coming from an AudioBufferSou
rceNode | |
| 6 playing an AudioBuffer containing a specific curve can be connected to an AudioG
ainNode's | |
| 7 .gain attribute (an AudioParam). Another AudioBufferSourceNode will be the audi
o source | |
| 8 having its gain changed. We load this one with an AudioBuffer containing a cons
tant value of 1. | |
| 9 Thus it's easy to check that the resultant signal should be equal to the gain-sc
aling curve. | |
| 10 --> | |
| 11 | |
| 12 <html> | |
| 13 <head> | |
| 14 <script src="../resources/js-test.js"></script> | |
| 15 <script src="resources/compatibility.js"></script> | |
| 16 <script src="resources/audit-util.js"></script> | |
| 17 <script src="resources/audio-testing.js"></script> | |
| 18 | |
| 19 </head> | |
| 20 <body> | |
| 21 | |
| 22 <script> | |
| 23 | |
| 24 var sampleRate = 44100.0; | |
| 25 var lengthInSeconds = 1; | |
| 26 | |
| 27 var context = 0; | |
| 28 var constantOneBuffer = 0; | |
| 29 var linearRampBuffer = 0; | |
| 30 | |
| 31 function checkResult(event) { | |
| 32 var renderedBuffer = event.renderedBuffer; | |
| 33 var renderedData = renderedBuffer.getChannelData(0); | |
| 34 var expectedData = linearRampBuffer.getChannelData(0); | |
| 35 var n = renderedBuffer.length; | |
| 36 | |
| 37 if (n == linearRampBuffer.length) { | |
| 38 testPassed("Rendered signal is of correct length."); | |
| 39 } else { | |
| 40 testFailed("Rendered signal is not of correct length."); | |
| 41 } | |
| 42 | |
| 43 // Check that the rendered result exactly matches the buffer used to control
gain. | |
| 44 // This is because we're changing the gain of a signal having constant value
1. | |
| 45 var success = true; | |
| 46 for (var i = 0; i < n; ++i) { | |
| 47 if (renderedData[i] != expectedData[i]) { | |
| 48 success = false; | |
| 49 break; | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 if (success) { | |
| 54 testPassed("Rendered signal exactly matches the audio-rate gain changing
signal."); | |
| 55 } else { | |
| 56 testFailed("Rendered signal differs from the audio-rate gain changing si
gnal."); | |
| 57 } | |
| 58 | |
| 59 finishJSTest(); | |
| 60 } | |
| 61 | |
| 62 function runTest() { | |
| 63 if (window.testRunner) { | |
| 64 testRunner.dumpAsText(); | |
| 65 testRunner.waitUntilDone(); | |
| 66 } | |
| 67 | |
| 68 window.jsTestIsAsync = true; | |
| 69 | |
| 70 var sampleFrameLength = sampleRate * lengthInSeconds; | |
| 71 | |
| 72 // Create offline audio context. | |
| 73 context = new OfflineAudioContext(1, sampleFrameLength, sampleRate); | |
| 74 | |
| 75 // Create buffer used by the source which will have its gain controlled. | |
| 76 constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1); | |
| 77 | |
| 78 // Create buffer used to control gain. | |
| 79 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength); | |
| 80 | |
| 81 // Create the two sources. | |
| 82 | |
| 83 var constantSource = context.createBufferSource(); | |
| 84 constantSource.buffer = constantOneBuffer; | |
| 85 | |
| 86 var gainChangingSource = context.createBufferSource(); | |
| 87 gainChangingSource.buffer = linearRampBuffer; | |
| 88 | |
| 89 // Create a gain node controlling the gain of constantSource and make the co
nnections. | |
| 90 var gainNode = context.createGain(); | |
| 91 | |
| 92 // Intrinsic baseline gain of zero. | |
| 93 gainNode.gain.value = 0; | |
| 94 | |
| 95 constantSource.connect(gainNode); | |
| 96 gainNode.connect(context.destination); | |
| 97 | |
| 98 // Connect an audio-rate signal to control the .gain AudioParam. | |
| 99 // This is the heart of what is being tested. | |
| 100 gainChangingSource.connect(gainNode.gain); | |
| 101 | |
| 102 // Start both sources at time 0. | |
| 103 constantSource.start(0); | |
| 104 gainChangingSource.start(0); | |
| 105 | |
| 106 context.oncomplete = checkResult; | |
| 107 context.startRendering(); | |
| 108 } | |
| 109 | |
| 110 runTest(); | |
| 111 successfullyParsed = true; | |
| 112 | |
| 113 </script> | |
| 114 | |
| 115 </body> | |
| 116 </html> | |
| OLD | NEW |