audiobuffersource-null.html (2136B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 Test ABSN Outputs Silence if buffer is null 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/webaudio/resources/audit-util.js"></script> 10 <script src="/webaudio/resources/audit.js"></script> 11 </head> 12 13 <body> 14 <script> 15 const audit = Audit.createTaskRunner(); 16 17 audit.define('ABSN with null buffer', (task, should) => { 18 // Create test context. Length and sampleRate are pretty arbitrary, but 19 // we don't need either to be very large. 20 const context = new OfflineAudioContext( 21 {numberOfChannels: 1, length: 1024, sampleRate: 8192}); 22 23 // Just create a constant buffer for testing. Anything will do as long 24 // as the buffer contents are not identically zero. 25 const audioBuffer = 26 new AudioBuffer({length: 10, sampleRate: context.sampleRate}); 27 const audioBufferSourceNode = new AudioBufferSourceNode(context); 28 29 audioBuffer.getChannelData(0).fill(1); 30 31 // These two tests are mostly for the informational messages to show 32 // what's happening. They should never fail! 33 should(() => { 34 audioBufferSourceNode.buffer = audioBuffer; 35 }, 'Setting ABSN.buffer to AudioBuffer').notThrow(); 36 37 // This is the important part. Setting the buffer to null after setting 38 // it to something else should cause the source to produce silence. 39 should(() => { 40 audioBufferSourceNode.buffer = null; 41 }, 'Setting ABSN.buffer = null').notThrow(); 42 43 audioBufferSourceNode.start(0); 44 audioBufferSourceNode.connect(context.destination); 45 46 context.startRendering() 47 .then(buffer => { 48 // Since the buffer is null, the output of the source should be 49 // silence. 50 should(buffer.getChannelData(0), 'ABSN output') 51 .beConstantValueOf(0); 52 }) 53 .then(() => task.done()); 54 }); 55 56 audit.run(); 57 </script> 58 </body> 59 </html>