maxdelay-rounding.html (2266B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 Test DelayNode when maxDelayTime requires rounding 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 </head> 11 <body> 12 <script> 13 const sampleRate = 44100; 14 const inputLengthSeconds = 1; 15 const renderLengthSeconds = 2; 16 17 // Delay for one second plus 0.4 of a sample frame, to test that 18 // DelayNode is properly rounding up when calculating its buffer 19 // size (crbug.com/1065110). 20 const delayTimeSeconds = 1 + 0.4 / sampleRate; 21 22 promise_test(async () => { 23 const context = new OfflineAudioContext({ 24 numberOfChannels: 1, 25 length: sampleRate * renderLengthSeconds, 26 sampleRate: sampleRate, 27 }); 28 29 // Create a constant source to use as input. 30 const src = new ConstantSourceNode(context); 31 32 // Create a DelayNode to delay for delayTimeSeconds. 33 const delay = new DelayNode(context, { 34 maxDelayTime: delayTimeSeconds, 35 delayTime: delayTimeSeconds, 36 }); 37 38 src.connect(delay).connect(context.destination); 39 40 src.start(); 41 const renderedBuffer = await context.startRendering(); 42 const renderedData = renderedBuffer.getChannelData(0); 43 44 // The first delayTimeSeconds of output should be silent. 45 const expectedSilentFrames = Math.floor( 46 delayTimeSeconds * sampleRate); 47 48 assert_constant_value( 49 renderedData.slice(0, expectedSilentFrames), 50 0, 51 `output[0:${expectedSilentFrames - 1}]`); 52 53 // The rest should be non-silent: that is, there should 54 // be at least one non-zero sample. (Any reasonable 55 // interpolation algorithm will make all these samples 56 // non-zero, but I don't think that's guaranteed by the 57 // spec, so we use a conservative test for now.) 58 assert_not_constant_value_of( 59 renderedData.slice(expectedSilentFrames), 60 0, 61 `output[${expectedSilentFrames}:]`); 62 }, 'Test DelayNode when maxDelayTime requires rounding'); 63 </script> 64 </body> 65 </html>