Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(781)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-downmix.html

Issue 1803233002: AnalyserNode should downmix channels to mono. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-downmix-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 <script src="resources/compatibility.js"></script>
6 <script src="resources/audio-testing.js"></script>
7 <script src="resources/fft.js"></script>
8 <script src="resources/realtimeanalyser-testing.js"></script>
9 <title>Test AnalyserNode Downmixing</title>
10 </head>
11
12 <body>
13 <script>
14 description("Test AnalyserNode Downmixing");
15 window.jsTestIsAsync = true;
16
17 var sampleRate = 44100;
18 var renderFrames = 2048;
19
20 var audit = Audit.createTaskRunner();
21
22 var testConfigs = [{
23 channelCount: 1,
24 message: "mono",
25 floatRelError: 6.3283e-8
26 }, {
27 channelCount: 2,
28 message: "stereo",
29 floatRelError: 1.1681e-7
30 }, {
31 channelCount: 4,
32 message: "quad",
33 floatRelError: 4.9793e-7
34 }, {
35 channelCount: 6,
36 message: "5.1",
37 floatRelError: 2.0215e-7
38 }, {
39 channelCount: 3,
40 message: "3-channel",
41 floatRelError: 6.3283e-8
42 }];
43
44 // Create tasks for each entry in testConfigs
45 for (k in testConfigs) {
46 audit.defineTask(testConfigs[k].message, (function (config) {
47 return function(done) {
48 runTest(config).then(done);
49 };
50 })(testConfigs[k]));
51 }
52
53 audit.defineTask("finish", function (done) {
54 finishJSTest();
55 done();
56 });
57
58 audit.runTasks();
59
60 // Test downmixing of the AnalyserNode time data. We use the downmixing t hat automatically
61 // happens in the destination node to generate the reference data which is compared to the
62 // data that the Analyser node has captured.
63 function runTest(options) {
64 // Context MUST have exactly one channel so that we downmix the source t o mono to generate
65 // the reference.
66 var context = new OfflineAudioContext(1, renderFrames, sampleRate);
67
68 var channels = options.channelCount || 1;
69 var source = context.createBufferSource();
70
71 // The signals in each channel. Doesn't matter much what is in here, but it's best if the
72 // values aren't linearly increasing so that the average of the values i sn't one of the
73 // values (in case the implementation does something silly). Only need to support up to 6
74 // channels.
75 var bufferValues = [1, 2, 3, 4, 5, 6].map(function (x) {
76 return x * x
77 });;
78 source.buffer = createConstantBuffer(context, renderFrames, bufferValues .slice(0, channels));
79
80 var analyser = context.createAnalyser();
81 analyser.smoothingTimeConstant = 0;
82 analyser.fftSize = 256;
83
84 // Run analyser as an automatic pull node. Do NOT connect to the destina tion. We don't want
85 // the output of the analyser to mix in with the source that is also dir ectly connected to
86 // the destination.
87 source.connect(analyser);
88 source.connect(context.destination);
89
90 var timeData = new Float32Array(analyser.fftSize);
91 var freqData = new Float32Array(analyser.frequencyBinCount);
92
93 var suspendFrame = analyser.fftSize;
94 context.suspend(suspendFrame / context.sampleRate).then(function () {
95 analyser.getFloatTimeDomainData(timeData);
96 analyser.getFloatFrequencyData(freqData);
97 }).then(context.resume.bind(context));
98
99 source.start();
100 return context.startRendering().then(function (renderedBuffer) {
101 var success = true;
102
103 // Verify the time domain data is correct.
104 var prefix = "Analyser downmix " + options.message + " to mono"
105 success = Should(prefix + " time data", timeData, {
106 verbose: true
107 })
108 .beEqualToArray(renderedBuffer.getChannelData(0).subarray(0, analyse r.fftSize));
109
110 var expectedTimeData = renderedBuffer.getChannelData(0).subarray(0, an alyser.fftSize);
111 var fftOrder = Math.floor(Math.log2(analyser.fftSize));
112 var expectedFreqData = computeFFTMagnitude(expectedTimeData, fftOrder) .map(linearToDb);
113
114 success = compareFloatFreq(prefix + " freq data", freqData, expectedFr eqData, {
115 precision: 6,
116 floatRelError: options.floatRelError,
117 }) && success;
118
119 if (success)
120 testPassed(prefix + " downmixed correctly.\n");
121 else
122 testFailed(prefix + " not downmixed correctly.\n");
123 });
124 }
125 </script>
126 </body>
127 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-downmix-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698