| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 | |
| 4 <head> | |
| 5 <script src="../resources/js-test.js"></script> | |
| 6 <script src="resources/compatibility.js"></script> | |
| 7 <script src="resources/audit-util.js"></script> | |
| 8 <script src="resources/audio-testing.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script> | |
| 13 description('Test ChannelMergerNode behavior on dynamic input change.'); | |
| 14 window.jsTestIsAsync = true; | |
| 15 | |
| 16 var renderQuantum = 128; | |
| 17 | |
| 18 var numberOfChannels = 2; | |
| 19 var sampleRate = 44100; | |
| 20 var renderDuration = 0.5; | |
| 21 var disconnectTime = 0.5 * renderDuration; | |
| 22 | |
| 23 var audit = Audit.createTaskRunner(); | |
| 24 | |
| 25 // Task: Check if the merger outputs a silent channel when an input is | |
| 26 // disconnected. | |
| 27 audit.defineTask('silent-disconnect', function (done) { | |
| 28 var context = new OfflineAudioContext(numberOfChannels, renderDuration * s
ampleRate, sampleRate); | |
| 29 var merger = context.createChannelMerger(); | |
| 30 var source1 = context.createBufferSource(); | |
| 31 var source2 = context.createBufferSource(); | |
| 32 | |
| 33 // Create and assign a constant buffer. | |
| 34 var bufferDCOffset = createConstantBuffer(context, 1, 1); | |
| 35 source1.buffer = source2.buffer = bufferDCOffset; | |
| 36 source1.loop = source2.loop = true; | |
| 37 | |
| 38 // Connect the output of source into the 4th input of merger. The merger | |
| 39 // should produce 6 channel output. | |
| 40 source1.connect(merger, 0, 0); | |
| 41 source2.connect(merger, 0, 1); | |
| 42 merger.connect(context.destination); | |
| 43 source1.start(); | |
| 44 source2.start(); | |
| 45 | |
| 46 // Schedule the disconnection of |source2| at the half of render duration. | |
| 47 context.suspend(disconnectTime).then(function () { | |
| 48 source2.disconnect(); | |
| 49 context.resume(); | |
| 50 }); | |
| 51 | |
| 52 context.startRendering().then(function (buffer) { | |
| 53 // The entire first channel of the output should be 1. | |
| 54 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(1); | |
| 55 | |
| 56 // Calculate the first zero index in the second channel. | |
| 57 var channel1 = buffer.getChannelData(1); | |
| 58 var disconnectIndex = disconnectTime * sampleRate; | |
| 59 disconnectIndex -= (disconnectIndex) % renderQuantum; | |
| 60 var firstZeroIndex = channel1.findIndex(function (element, index) { | |
| 61 if (element === 0) | |
| 62 return index; | |
| 63 }); | |
| 64 | |
| 65 // The second channel should contain 1, and 0 after the disconnection. | |
| 66 Should('Channel #1', channel1).containValues([1, 0]); | |
| 67 Should('The index of first zero in the channel #1', firstZeroIndex) | |
| 68 .beEqualTo(disconnectIndex); | |
| 69 | |
| 70 }).then(done); | |
| 71 }); | |
| 72 | |
| 73 audit.defineTask('finish', function (done) { | |
| 74 finishJSTest(); | |
| 75 done(); | |
| 76 }); | |
| 77 | |
| 78 audit.runTasks(); | |
| 79 | |
| 80 successfullyParsed = true; | |
| 81 </script> | |
| 82 </body> | |
| 83 | |
| 84 </html> | |
| OLD | NEW |