summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletglobalscope-timing-info.https.html
blob: 5f4bee7c5312c89207a25801cd0c2d6055ec00b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
  <head>
    <title>
      Test currentTime and currentFrame in AudioWorkletGlobalScope
    </title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/webaudio/resources/audit.js"></script>
  </head>
  <body>
    <script id="layout-test-code">
      let audit = Audit.createTaskRunner();

      setup(() => {
        let sampleRate = 48000;
        let renderLength = 512;
        let context = new OfflineAudioContext(1, renderLength, sampleRate);

        let filePath = 'processors/timing-info-processor.js';

        audit.define(
            'Check the timing information from AudioWorkletProcessor',
            (task, should) => {
              let portWorkletNode =
                  new AudioWorkletNode(context, 'timing-info-processor');
              portWorkletNode.connect(context.destination);

              // Suspend at render quantum boundary and check the timing
              // information between the main thread and the rendering thread.
              [0, 128, 256, 384].map((suspendFrame) => {
                context.suspend(suspendFrame/sampleRate).then(() => {
                  portWorkletNode.port.onmessage = (event) => {
                    should(event.data.currentFrame,
                           'currentFrame from the processor at ' + suspendFrame)
                        .beEqualTo(suspendFrame);
                    should(event.data.currentTime,
                           'currentTime from the processor at '
                               + context.currentTime)
                        .beEqualTo(context.currentTime);
                    context.resume();
                  };

                  portWorkletNode.port.postMessage('query-timing-info');
                });
              });

              context.startRendering().then(() => {
                task.done();
              });
            });

        context.audioWorklet.addModule(filePath).then(() => {
          audit.run();
        });
      });
    </script>
  </body>
</html>