summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/webaudio/stereo2mono-down-mixing.html
blob: 659d038868b5cfd0b653ba302f3b239a74ce5955 (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
<!DOCTYPE html>

<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/compatibility.js"></script>
<script src="resources/audio-testing.js"></script>
</head>

<body>

<div id="description"></div>
<div id="console"></div>

<script>
description("This test verifies whether down mixing from stereo to mono will cause assertion error.");

var sampleRate = 44100.0;
var renderLengthSeconds = 0.1;

var context;
var toneBuffer;
var bufferSource;

function createDataBuffer(context, lengthInSeconds) {
    var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);

    var n = audioBuffer.length;
    var data0 = audioBuffer.getChannelData(0);
    var data1 = audioBuffer.getChannelData(1);

    for (var i = 0; i < n; ++i) {
        data0[i] = 1.0;
        data1[i] = 1.0;
    }

    return audioBuffer;
}

function testFinished() {
    testPassed("Test no ASSERT error.");
    finishJSTest();
}

function runTest() {
    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    window.jsTestIsAsync = true;

    // Create offline audio context, the destination is mono.
    context = new OfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
    // Create a stereo AudioBuffer.
    toneBuffer = createDataBuffer(context, renderLengthSeconds);

    bufferSource = context.createBufferSource();
    bufferSource.buffer = toneBuffer;

    bufferSource.connect(context.destination);

    bufferSource.start(0);

    context.oncomplete = testFinished;
    context.startRendering();
}


runTest();

</script>

</body>
</html>