k-rate-oscillator.html (2493B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Test k-rate AudioParams of OscillatorNode</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/webaudio/resources/audit-util.js"></script> 8 </head> 9 10 <body> 11 <script> 12 // Arbitrary sample rate and duration. 13 const sampleRate = 8000; 14 15 // Only new a few render quanta to verify things are working. 16 const testDuration = 4 * 128 / sampleRate; 17 18 [{name: 'detune', initial: 0, final: 1200}, { 19 name: 'frequency', 20 initial: 440, 21 final: sampleRate / 2}].forEach((paramProperty) => { 22 promise_test(async () => { 23 const context = new OfflineAudioContext({ 24 numberOfChannels: 3, 25 sampleRate: sampleRate, 26 length: testDuration * sampleRate 27 }); 28 29 const merger = new ChannelMergerNode( 30 context, {numberOfInputs: context.destination.channelCount}); 31 merger.connect(context.destination); 32 const inverter = new GainNode(context, {gain: -1}); 33 inverter.connect(merger, 0, 2); 34 35 const kRateNode = new OscillatorNode(context); 36 const aRateNode = new OscillatorNode(context); 37 38 kRateNode.connect(merger, 0, 0); 39 aRateNode.connect(merger, 0, 1); 40 41 kRateNode.connect(merger, 0, 2); 42 aRateNode.connect(inverter); 43 44 // Set the rate 45 kRateNode[paramProperty.name].automationRate = 'k-rate'; 46 47 // Automate the offset 48 kRateNode[paramProperty.name].setValueAtTime( 49 paramProperty.initial, 0); 50 kRateNode[paramProperty.name].linearRampToValueAtTime( 51 paramProperty.final, testDuration); 52 53 aRateNode[paramProperty.name].setValueAtTime( 54 paramProperty.initial, 0); 55 aRateNode[paramProperty.name].linearRampToValueAtTime( 56 paramProperty.final, testDuration); 57 58 kRateNode.start(); 59 aRateNode.start(); 60 61 const audioBuffer = await context.startRendering(); 62 const diff = audioBuffer.getChannelData(2); 63 // Verify that the outputs are different. 64 assert_not_constant_value_of( 65 diff, 0, 66 `k-rate ${paramProperty.name}: ` + 67 `Difference between a-rate and k-rate outputs`); 68 }, `Oscillator k-rate ${paramProperty.name}`); 69 }); 70 </script> 71 </body> 72 </html>