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

Side by Side Diff: content/test/data/media/webrtc_test_audio.js

Issue 216523003: Tighten up webrtc audio tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Audio test utilities. 5 // Audio test utilities.
6 6
7 // Gathers |numSamples| samples at |frequency| number of times per second and 7 // Gathers |numSamples| samples at |frequency| number of times per second and
8 // calls back |callback| with an array with numbers in the [0, 32768] range. 8 // calls back |callback| with an array with numbers in the [0, 32768] range.
9 function gatherAudioLevelSamples(peerConnection, numSamples, frequency, 9 function gatherAudioLevelSamples(peerConnection, numSamples, frequency,
10 callback) { 10 callback) {
11 console.log('Gathering ' + numSamples + ' audio samples...'); 11 console.log('Gathering ' + numSamples + ' audio samples...');
12 var audioLevelSamples = [] 12 var audioLevelSamples = []
13 var gatherSamples = setInterval(function() { 13 var gatherSamples = setInterval(function() {
14 peerConnection.getStats(function(response) { 14 peerConnection.getStats(function(response) {
15 audioLevelSamples.push(getAudioLevelFromStats_(response)); 15 audioLevelSamples.push(getAudioLevelFromStats_(response));
16 if (audioLevelSamples.length == numSamples) { 16 if (audioLevelSamples.length == numSamples) {
17 console.log('Gathered all samples.'); 17 console.log('Gathered all samples.');
18 clearInterval(gatherSamples); 18 clearInterval(gatherSamples);
19 callback(audioLevelSamples); 19 callback(audioLevelSamples);
20 } 20 }
21 }); 21 });
22 }, 1000 / frequency); 22 }, 1000 / frequency);
23 } 23 }
24 24
25 // Tries to identify the beep-every-second signal generated by the fake audio 25 // Tries to identify the beep-every-second signal generated by the fake audio
26 // media/audio/fake_audio_input_stream.cc. Fails the test if we can't see a 26 // media/audio/fake_audio_input_stream.cc. Fails the test if we can't see a
27 // signal. 27 // signal. The samples should have been gathered over at least three seconds
28 // since we expect to see at least two "peaks" in there.
28 function verifyAudioIsPlaying(samples) { 29 function verifyAudioIsPlaying(samples) {
29 var average = 0; 30 var numPeaks = 0;
30 for (var i = 0; i < samples.length; ++i) 31 var maxLevel = 32768;
perkj_chrome 2014/03/28 13:29:17 where to this numbers come frome? What do they mea
phoglund_chromium 2014/03/28 13:55:26 Done.
31 average += samples[i] / samples.length; 32 var threshold = maxLevel * 0.8;
33 var currentlyOverThreshold = false;
34
35 // Detect when we have been been over the threshold and is going back again
36 // (i.e. count peaks). We should see about one peak per second.
37 for (var i = 0; i < samples.length; ++i) {
38 if (currentlyOverThreshold && samples[i] < threshold)
39 numPeaks++;
40 currentlyOverThreshold = samples[i] >= threshold;
41 }
32 42
33 var largest = 0; 43 var largest = 0;
34 for (var i = 0; i < samples.length; ++i) 44 for (var i = 0; i < samples.length; ++i)
35 largest = Math.max(largest, samples[i]); 45 largest = Math.max(largest, samples[i]);
36 46
37 console.log('Average audio level: ' + average + ', largest: ' + largest); 47 console.log('Number of peaks identified: ' + numPeaks + ', max: ' + largest);
38 48
39 // TODO(phoglund): Make a more sophisticated curve-fitting algorithm. We want 49 if (numPeaks < 2)
40 // to see a number of peaks with relative silence between them. The following 50 failTest('Expected to see at least two peaks in audio signal, got ' +
41 // seems to work fine on a nexus 7. 51 numPeaks + '. Dumping samples for analysis: "' + samples + '"');
42 if (average < 3000 || average > 8000) 52
43 failTest('Unexpected avg audio level: got ' + average + ', expected it ' +
44 'to be 4000 < avg < 8000.');
45 if (largest < 25000) 53 if (largest < 25000)
46 failTest('Too low max audio level: got ' + largest + ', expected > 30000.'); 54 failTest('Too low max audio level: got ' + largest + ', expected > 25000.');
47 } 55 }
48 56
49 // If silent (like when muted), we should get very near zero audio level. 57 // If silent (like when muted), we should get very near zero audio level.
50 function verifyIsSilent(samples) { 58 function verifyIsSilent(samples) {
51 var average = 0; 59 var average = 0;
52 for (var i = 0; i < samples.length; ++i) 60 for (var i = 0; i < samples.length; ++i)
53 average += samples[i] / samples.length; 61 average += samples[i] / samples.length;
54 62
55 console.log('Average audio level: ' + average); 63 console.log('Average audio level: ' + average);
56 if (average > 500) 64 if (average > 500)
(...skipping 10 matching lines...) Expand all
67 var report = reports[i]; 75 var report = reports[i];
68 if (report.names().indexOf('audioOutputLevel') != -1) { 76 if (report.names().indexOf('audioOutputLevel') != -1) {
69 audioOutputLevels.push(report.stat('audioOutputLevel')); 77 audioOutputLevels.push(report.stat('audioOutputLevel'));
70 } 78 }
71 } 79 }
72 // Should only be one audio level reported, otherwise we get confused. 80 // Should only be one audio level reported, otherwise we get confused.
73 assertEquals(1, audioOutputLevels.length); 81 assertEquals(1, audioOutputLevels.length);
74 82
75 return audioOutputLevels[0]; 83 return audioOutputLevels[0];
76 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698