| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title> | |
| Test setValueCurveAtTime with Huge Duration | |
| </title> | |
| <script src="../../resources/testharness.js"></script> | |
| <script src="../../resources/testharnessreport.js"></script> | |
| </head> | |
| <body> | |
| <script> | |
| const sampleRate = 48000; | |
| const renderFrames = 1000; | |
| promise_test(async () => { | |
| // We only need to generate a small number of frames for this test. | |
| const context = new OfflineAudioContext(1, renderFrames, sampleRate); | |
| // Constant source of amplitude 1. | |
| const src = new ConstantSourceNode(context, { offset: 1 }); | |
| // Automate the gain with a setValueCurve with a very long duration. | |
| // The duration should produce a frame number greater than 2^64 (larger | |
| // than the largest size_t value). | |
| const gain = new GainNode(context); | |
| const duration = Math.pow(2, 64); | |
| const curve = Float32Array.from([0, 1]); | |
| gain.gain.setValueCurveAtTime(curve, 0, duration); | |
| src.connect(gain).connect(context.destination); | |
| src.start(); | |
| const result = await context.startRendering(); | |
| // Find the maximum value of the buffer. | |
| const max = Math.max.apply(null, result.getChannelData(0)); | |
| // The automation does linear interpolation between 0 and 1 from | |
| // time 0 to duration. Hence the max value of the interpolation | |
| // occurs at the end of the rendering. Compute this value. | |
| const expectedMax = (renderFrames / sampleRate) * (1 / duration); | |
| assert_less_than_equal( | |
| max, | |
| expectedMax, | |
| `Max amplitude of setValueCurve([${curve}], 0, ${duration})`); | |
| }, 'long duration'); | |
| </script> | |
| </body> | |
| </html> |