summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-biquad.html
blob: 85ae4f175fe182a4bf993443163dea14f00fa203 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!doctype html>
<html>
  <head>
    <title>Test k-rate AudioParams of BiquadFilterNode</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/webaudio/resources/audit-util.js"></script>
    <script src="/webaudio/resources/audit.js"></script>
    <script src="automation-rate-testing.js"></script>
  </head>

  <body>
    <script>
      let audit = Audit.createTaskRunner();

      audit.define(
          {task: 'BiquadFilter-0', label: 'Biquad k-rate AudioParams (all)'},
          (task, should) => {
            // Arbitrary sample rate and duration.
            let sampleRate = 8000;
            let testDuration = 1;
            let context = new OfflineAudioContext({
              numberOfChannels: 3,
              sampleRate: sampleRate,
              length: testDuration * sampleRate
            });

            doTest(context, should, {
              nodeName: 'BiquadFilterNode',
              nodeOptions: {type: 'lowpass'},
              prefix: 'All k-rate params',
              // Set all AudioParams to k-rate
              rateSettings: [
                {name: 'Q', value: 'k-rate'},
                {name: 'detune', value: 'k-rate'},
                {name: 'frequency', value: 'k-rate'},
                {name: 'gain', value: 'k-rate'},
              ],
              // Automate just the frequency
              automations: [{
                name: 'frequency',
                methods: [
                  {name: 'setValueAtTime', options: [350, 0]}, {
                    name: 'linearRampToValueAtTime',
                    options: [0, testDuration]
                  }
                ]
              }]
            }).then(() => task.done());
          });

      // Define a test where we verify that a k-rate audio param produces
      // different results from an a-rate audio param for each of the audio
      // params of a biquad.
      //
      // Each entry gives the name of the AudioParam, an initial value to be
      // used with setValueAtTime, and a final value to be used with
      // linearRampToValueAtTime. (See |doTest| for details as well.)

      [{name: 'Q',
        initial: 1,
        final: 10
       },
       {name: 'detune',
        initial: 0,
        final: 1200
       },
       {name: 'frequency',
        initial: 350,
        final: 0
       },
       {name: 'gain',
        initial: 10,
        final: 0
       }].forEach(paramProperty => {
        audit.define('Biquad k-rate ' + paramProperty.name, (task, should) => {
          // Arbitrary sample rate and duration.
          let sampleRate = 8000;
          let testDuration = 1;
          let context = new OfflineAudioContext({
            numberOfChannels: 3,
            sampleRate: sampleRate,
            length: testDuration * sampleRate
          });

          doTest(context, should, {
            nodeName: 'BiquadFilterNode',
            nodeOptions: {type: 'peaking', Q: 1, gain: 10},
            prefix: `k-rate ${paramProperty.name}`,
            // Just set the frequency to k-rate
            rateSettings: [
              {name: paramProperty.name, value: 'k-rate'},
            ],
            // Automate just the given AudioParam
            automations: [{
              name: paramProperty.name,
              methods: [
                {name: 'setValueAtTime', options: [paramProperty.initial, 0]}, {
                  name: 'linearRampToValueAtTime',
                  options: [paramProperty.final, testDuration]
                }
              ]
            }]
          }).then(() => task.done());
        });
      });

      audit.run();
    </script>
  </body>
</html>