exponentialRamp-special-cases.html (2138B)
1 <!DOCTYPE html> 2 <title>Test exponentialRampToValueAtTime() special cases</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script> 6 promise_test(async function() { 7 const bufferSize = 5; 8 const sampleRate = 16384; 9 const startSample = 3; 10 const offset0 = 2.; 11 const offset1 = -3.; 12 const context = new OfflineAudioContext(1, bufferSize, sampleRate); 13 14 const source = new ConstantSourceNode(context); 15 source.start(); 16 // Explicit event to work around 17 // https://bugzilla.mozilla.org/show_bug.cgi?id=1265393 18 source.offset.setValueAtTime(offset0, 0.); 19 source.offset.exponentialRampToValueAtTime(offset1, startSample/sampleRate); 20 source.connect(context.destination); 21 22 const buffer = await context.startRendering(); 23 assert_equals(buffer.length, bufferSize, "output buffer length"); 24 const output = buffer.getChannelData(0); 25 for (let i = 0; i < startSample; ++i) { 26 assert_equals(output[i], offset0, "initial offset at sample " + i); 27 } 28 for (let i = startSample; i < bufferSize; ++i) { 29 assert_equals(output[i], offset1, "scheduled value at sample " + i); 30 } 31 }, "v0 and v1 have opposite signs"); 32 33 promise_test(async function() { 34 const bufferSize = 4; 35 const sampleRate = 16384; 36 const startSample = 2; 37 const offset = -2.; 38 const context = new OfflineAudioContext(1, bufferSize, sampleRate); 39 40 const source = new ConstantSourceNode(context); 41 source.start(); 42 // Explicit event to work around 43 // https://bugzilla.mozilla.org/show_bug.cgi?id=1265393 44 source.offset.setValueAtTime(0, 0.); 45 source.offset.exponentialRampToValueAtTime(offset, startSample/sampleRate); 46 source.connect(context.destination); 47 48 const buffer = await context.startRendering(); 49 assert_equals(buffer.length, bufferSize, "output buffer length"); 50 const output = buffer.getChannelData(0); 51 for (let i = 0; i < startSample; ++i) { 52 assert_equals(output[i], 0., "initial offset at sample " + i); 53 } 54 for (let i = startSample; i < bufferSize; ++i) { 55 assert_equals(output[i], offset, "scheduled value at sample " + i); 56 } 57 }, "v0 is zero"); 58 </script>