test_decodeMultichannel.html (1787B)
1 <!DOCTYPE HTML> 2 <html> 3 <meta charset=utf-8> 4 <head> 5 <title>Test that we can decode multichannel file with webaudio and <audio></title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 </head> 9 <body> 10 <pre id="test"> 11 <script class="testbody" type="text/javascript"> 12 var testcases = [ 13 { 14 filename: "audio-quad.wav", 15 channels: 4 16 }, 17 { 18 filename: "8kHz-320kbps-6ch.aac", 19 channels: 6 20 } 21 ]; 22 23 SimpleTest.waitForExplicitFinish(); 24 25 function decodeUsingAudioElement(filename, resolve) { 26 var a = new Audio(); 27 a.addEventListener("error", function() { 28 ok(false, "Error loading metadata"); 29 resolve(); 30 }); 31 a.addEventListener("loadedmetadata", function() { 32 ok(true, "Metadata Loaded"); 33 resolve(); 34 }); 35 36 a.src = filename; 37 a.load(); 38 } 39 40 function testOne({filename, channels}) { 41 return new Promise(resolve => { 42 var xhr = new XMLHttpRequest(); 43 xhr.open("GET", filename); 44 xhr.responseType = "arraybuffer"; 45 xhr.onload = function() { 46 var context = new AudioContext(); 47 context.decodeAudioData(xhr.response, function(b) { 48 ok(true, "Decoding of a wave file with four channels succeded."); 49 is(b.numberOfChannels, 50 channels, 51 `The AudioBuffer decoded from ${filename} should have ${channels} channels.`); 52 decodeUsingAudioElement(filename, resolve); 53 }, function() { 54 ok(false, `Decoding ${filename} failed)`); 55 decodeUsingAudioElement(filename, resolve); 56 }); 57 }; 58 xhr.send(null); 59 }); 60 } 61 62 async function runTest() { 63 for (var testcase of testcases) { 64 await testOne(testcase); 65 } 66 67 SimpleTest.finish(); 68 } 69 70 addLoadEvent(runTest); 71 72 </script> 73 </pre> 74 </body> 75 </html>