| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 | 3 |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 8 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 9 <script src="../resources/merger-testing.js"></script> | 9 <script src="../resources/merger-testing.js"></script> |
| 10 </head> | 10 </head> |
| 11 | 11 |
| 12 <body> | 12 <body> |
| 13 <script> | 13 <script> |
| 14 | 14 |
| 15 var audit = Audit.createTaskRunner(); | 15 var audit = Audit.createTaskRunner(); |
| 16 | 16 |
| 17 // Task: Check if an inactive input renders a silent mono channel in the | 17 // Task: Check if an inactive input renders a silent mono channel in the |
| 18 // output. | 18 // output. |
| 19 audit.defineTask('silent-channel', function (done) { | 19 audit.define('silent-channel', (task, should) => { |
| 20 testMergerInput({ | 20 testMergerInput(should, { |
| 21 numberOfChannels: 6, | 21 numberOfChannels: 6, |
| 22 | 22 |
| 23 // Create a mono source buffer filled with '1'. | 23 // Create a mono source buffer filled with '1'. |
| 24 testBufferContent: [1], | 24 testBufferContent: [1], |
| 25 | 25 |
| 26 // Connect the output of source into the 4th input of merger. | 26 // Connect the output of source into the 4th input of merger. |
| 27 mergerInputIndex: 3, | 27 mergerInputIndex: 3, |
| 28 | 28 |
| 29 // All channels should contain 0, except channel 4 which should be 1. | 29 // All channels should contain 0, except channel 4 which should be 1. |
| 30 expected: [0, 0, 0, 1, 0, 0], | 30 expected: [0, 0, 0, 1, 0, 0], |
| 31 }, done); | 31 }) |
| 32 .then(() => task.done()); |
| 32 }); | 33 }); |
| 33 | 34 |
| 34 | 35 |
| 35 // Task: Check if a stereo input is being down-mixed to mono channel | 36 // Task: Check if a stereo input is being down-mixed to mono channel |
| 36 // correctly based on the mixing rule. | 37 // correctly based on the mixing rule. |
| 37 audit.defineTask('stereo-down-mixing', function (done) { | 38 audit.define('stereo-down-mixing', (task, should) => { |
| 38 testMergerInput({ | 39 testMergerInput(should, { |
| 39 numberOfChannels: 6, | 40 numberOfChannels: 6, |
| 40 | 41 |
| 41 // Create a stereo buffer filled with '1' and '2' for left and right | 42 // Create a stereo buffer filled with '1' and '2' for left and right |
| 42 // channels respectively. | 43 // channels respectively. |
| 43 testBufferContent: [1, 2], | 44 testBufferContent: [1, 2], |
| 44 | 45 |
| 45 // Connect the output of source into the 1st input of merger. | 46 // Connect the output of source into the 1st input of merger. |
| 46 mergerInputIndex: undefined, | 47 mergerInputIndex: undefined, |
| 47 | 48 |
| 48 // The result of summed and down-mixed stereo audio should be 1.5. | 49 // The result of summed and down-mixed stereo audio should be 1.5. |
| 49 // (= 1 * 0.5 + 2 * 0.5) | 50 // (= 1 * 0.5 + 2 * 0.5) |
| 50 expected: [1.5, 0, 0, 0, 0, 0], | 51 expected: [1.5, 0, 0, 0, 0, 0], |
| 51 }, done); | 52 }) |
| 53 .then(() => task.done()); |
| 52 }); | 54 }); |
| 53 | 55 |
| 54 | 56 |
| 55 // Task: Check if 3-channel input gets processed by the 'discrete' mixing | 57 // Task: Check if 3-channel input gets processed by the 'discrete' mixing |
| 56 // rule. | 58 // rule. |
| 57 audit.defineTask('undefined-channel-layout', function (done) { | 59 audit.define('undefined-channel-layout', (task, should) => { |
| 58 testMergerInput({ | 60 testMergerInput(should, { |
| 59 numberOfChannels: 6, | 61 numberOfChannels: 6, |
| 60 | 62 |
| 61 // Create a 3-channel buffer filled with '1', '2', and '3' respectively. | 63 // Create a 3-channel buffer filled with '1', '2', and '3' respectively. |
| 62 testBufferContent: [1, 2, 3], | 64 testBufferContent: [1, 2, 3], |
| 63 | 65 |
| 64 // Connect the output of source into the 1st input of merger. | 66 // Connect the output of source into the 1st input of merger. |
| 65 mergerInputIndex: undefined, | 67 mergerInputIndex: undefined, |
| 66 | 68 |
| 67 // The result of summed stereo audio should be 1 because 3-channel is | 69 // The result of summed stereo audio should be 1 because 3-channel is |
| 68 // not a canonical layout, so the input channel 2 and 3 should be | 70 // not a canonical layout, so the input channel 2 and 3 should be |
| 69 // dropped by 'discrete' mixing rule. | 71 // dropped by 'discrete' mixing rule. |
| 70 expected: [1, 0, 0, 0, 0, 0], | 72 expected: [1, 0, 0, 0, 0, 0], |
| 71 }, done); | 73 }) |
| 74 .then(() => task.done()); |
| 72 }); | 75 }); |
| 73 | 76 |
| 74 | 77 |
| 75 // Task: Merging two inputs into a single stereo stream. | 78 // Task: Merging two inputs into a single stereo stream. |
| 76 audit.defineTask('merging-to-stereo', function (done) { | 79 audit.define('merging-to-stereo', (task, should) => { |
| 77 | 80 |
| 78 // For this test, the number of channel should be 2. | 81 // For this test, the number of channel should be 2. |
| 79 var context = new OfflineAudioContext(2, 128, 44100); | 82 var context = new OfflineAudioContext(2, 128, 44100); |
| 80 var merger = context.createChannelMerger(); | 83 var merger = context.createChannelMerger(); |
| 81 var source1 = context.createBufferSource(); | 84 var source1 = context.createBufferSource(); |
| 82 var source2 = context.createBufferSource(); | 85 var source2 = context.createBufferSource(); |
| 83 | 86 |
| 84 // Create a DC offset buffer (mono) filled with 1 and assign it to BS | 87 // Create a DC offset buffer (mono) filled with 1 and assign it to BS |
| 85 // nodes. | 88 // nodes. |
| 86 var positiveDCOffset = createConstantBuffer(context, 128, 1); | 89 var positiveDCOffset = createConstantBuffer(context, 128, 1); |
| 87 var negativeDCOffset = createConstantBuffer(context, 128, -1); | 90 var negativeDCOffset = createConstantBuffer(context, 128, -1); |
| 88 source1.buffer = positiveDCOffset; | 91 source1.buffer = positiveDCOffset; |
| 89 source2.buffer = negativeDCOffset; | 92 source2.buffer = negativeDCOffset; |
| 90 | 93 |
| 91 // Connect: BS#1 => merger_input#0, BS#2 => Inverter => merger_input#1 | 94 // Connect: BS#1 => merger_input#0, BS#2 => Inverter => merger_input#1 |
| 92 source1.connect(merger, 0, 0); | 95 source1.connect(merger, 0, 0); |
| 93 source2.connect(merger, 0, 1); | 96 source2.connect(merger, 0, 1); |
| 94 merger.connect(context.destination); | 97 merger.connect(context.destination); |
| 95 source1.start(); | 98 source1.start(); |
| 96 source2.start(); | 99 source2.start(); |
| 97 | 100 |
| 98 context.startRendering().then(function (buffer) { | 101 context.startRendering().then(function (buffer) { |
| 99 | 102 |
| 100 // Channel#0 = 1, Channel#1 = -1 | 103 // Channel#0 = 1, Channel#1 = -1 |
| 101 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(1); | 104 should(buffer.getChannelData(0), 'Channel #0').beConstantValueOf(1); |
| 102 Should('Channel #1', buffer.getChannelData(1)).beConstantValueOf(-1); | 105 should(buffer.getChannelData(1), 'Channel #1').beConstantValueOf(-1); |
| 103 | 106 |
| 104 done(); | 107 task.done(); |
| 105 }); | 108 }); |
| 106 }); | 109 }); |
| 107 | 110 |
| 108 | 111 |
| 109 audit.defineTask('finish', function (done) { | 112 audit.run(); |
| 110 done(); | |
| 111 }); | |
| 112 | |
| 113 audit.runTasks( | |
| 114 'silent-channel', | |
| 115 'stereo-down-mixing', | |
| 116 'undefined-channel-layout', | |
| 117 'merging-to-stereo', | |
| 118 'finish' | |
| 119 ); | |
| 120 | |
| 121 successfullyParsed = true; | |
| 122 </script> | 113 </script> |
| 123 </body> | 114 </body> |
| 124 | 115 |
| 125 </html> | 116 </html> |
| OLD | NEW |