5 <script src=
"../resources/js-test.js"></script>
6 <script src=
"resources/compatibility.js"></script>
7 <script src=
"resources/audio-testing.js"></script>
8 <script src=
"resources/audiobuffersource-testing.js"></script>
9 <script src=
"resources/buffer-loader.js"></script>
14 description('AudioBufferSourceNode: oscillator-driven detune modulation.');
15 window
.jsTestIsAsync
= true;
17 var sampleRate
= 44100;
20 var context
= new OfflineAudioContext(1, sampleRate
* duration
, sampleRate
);
23 var audit
= Audit
.createTaskRunner();
25 // Task: Load the reference file asynchronously. In order to create a new
26 // reference file, use the task 'generate-reference' below.
27 audit
.defineTask('load-reference', function (done
) {
28 var loader
= new BufferLoader(context
, [
29 'audiobuffersource-detune-modulation-expected.wav'
30 ], function (bufferList
) {
31 referenceBuffer
= bufferList
[0];
39 // Task: Render the actual buffer and compare with the reference.
40 audit
.defineTask('generate-verify', function (done
) {
42 // With this setting, the detune will be changing continuously and
43 // repeatedly within the range of [-1200, 1200] around 440Hz, based on the
44 // input from the oscillator.
45 createSawtoothWithModulation(context
, 'detune', 440, 1200);
47 context
.startRendering().then(function (renderedBuffer
) {
48 var actual
= renderedBuffer
.getChannelData(0);
49 var expected
= referenceBuffer
.getChannelData(0);
51 // Compare two buffers with arbitrary (yet reasonable) constraints.
52 // There parameters are determined by try bot experiments.
53 compareBuffersWithConstraints(actual
, expected
, {
55 thresholdDiffULP
: 1.01,
56 thresholdDiffCount
: 0,
63 // Task: Create a new reference audio file. See .runTasks() below to run
65 audit
.defineTask('generate-reference', function (done
) {
66 if (!window
.testRunner
) {
71 // With this setting, the detune will be changing continuously and
72 // repeatedly within the range of [-1200, 1200] around 440Hz, based on the
73 // input from the oscillator.
74 createSawtoothWithModulation(context
, 'detune', 440, 1200);
76 // |finishAudioTest| will automatically create a reference audio file from
77 // the OAC rendering if the reference file does not exist.
78 context
.oncomplete
= finishAudioTest
;
79 context
.startRendering();
80 testRunner
.waitUntilDone();
85 audit
.defineTask('finish', function (done
) {
90 window
.onload = function () {
98 // Use this task to generate a new reference audio file. Make sure to
99 // comment out .runTasks() above before use this.
100 // audit.runTasks('generate-reference');
102 successfullyParsed
= true;