looped-constant-buffer.html (1494B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Looped AudioBufferSourceNode Keeps Rendering</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/webaudio/resources/audit-util.js"></script> 9 </head> 10 <body> 11 <script> 12 promise_test(async () => { 13 const sampleRate = 44100; 14 const renderFrames = 2048; 15 const loopFrames = 64; 16 17 const context = new OfflineAudioContext(1, renderFrames, sampleRate); 18 const loopDuration = loopFrames / sampleRate; 19 20 const src = new AudioBufferSourceNode(context, { 21 buffer: createConstantBuffer(context, loopFrames, 1), 22 loop: true, 23 loopStart: 0, 24 loopEnd: loopDuration, 25 }); 26 27 src.connect(context.destination); 28 src.start(); 29 30 const resultBuffer = await context.startRendering(); 31 const result = resultBuffer.getChannelData(0); 32 const expected = new Float32Array(result.length).fill(1); 33 34 // WebAudio ยง1.9.5 requires that a looped region keeps playing until it is 35 // stopped, so the rendered output should remain constant 1 even after 36 // multiple loop passes. 37 assert_array_equals( 38 result, 39 expected, 40 'looped buffer should continue emitting ones even after first loop' 41 ); 42 }, 'looped-constant-buffer-keeps-rendering'); 43 </script> 44 </body> 45 </html>