buffer-source-slow-resampling-1.html (1450B)
1 <!DOCTYPE html> 2 <html class="reftest-wait"> 3 <script> 4 const blockSize = 128; 5 // The sample rate is a prime number so that the resampler is not expected to 6 // simplify in/out fractions. 7 const rate = 44101; 8 var context = new window.OfflineAudioContext(1, 3 * blockSize, rate); 9 // Non-zero buffer, so it can't be optimized away. 10 var buffer = context.createBuffer(1, 128, rate); 11 buffer.getChannelData(0)[0] = 1.0; 12 var source = context.createBufferSource(); 13 source.buffer = buffer; 14 source.loop = true; 15 // Initialize the resampler with a slow input rate. 16 // With the current (Mar 2017) implementation, very slow rates give the 17 // resampler a very large denominator. 18 source.playbackRate.setValueAtTime(rate / 0x7fffffff, 0.0); 19 // Change to a moderate input rate. 20 // With the current implementation, skip_frac_num increases by den_rate for 21 // each output sample and so one block before the change in playback rate is 22 // enough for high skip_frac_num at the time of the change. 23 const changeBlock = 1; 24 const changeBlockSeconds = changeBlock * blockSize / rate; 25 // With the current speex_resampler_set_rate_frac() implementation, the 26 // moderate resampler denominator is still large enough to trigger overflow of 27 // 32-bit unsigned integer arithmetic. 28 source.playbackRate.setValueAtTime(rate / (rate + 1), changeBlockSeconds); 29 source.start(0); 30 context.startRendering(). 31 then(function() { 32 document.documentElement.removeAttribute("class"); 33 }); 34 </script>