OLD | NEW |
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) { |
(...skipping 22 matching lines...) Expand all Loading... |
33 largest = Math.max(largest, samples[i]); | 33 largest = Math.max(largest, samples[i]); |
34 | 34 |
35 console.log('Average audio level: ' + average + ', largest: ' + largest); | 35 console.log('Average audio level: ' + average + ', largest: ' + largest); |
36 | 36 |
37 // TODO(phoglund): Make a more sophisticated curve-fitting algorithm. We want | 37 // TODO(phoglund): Make a more sophisticated curve-fitting algorithm. We want |
38 // to see a number of peaks with relative silence between them. The following | 38 // to see a number of peaks with relative silence between them. The following |
39 // seems to work fine on a nexus 7. | 39 // seems to work fine on a nexus 7. |
40 if (average < 3000 || average > 8000) | 40 if (average < 3000 || average > 8000) |
41 throw 'Unexpected avg audio level: got ' + average + ', expected it ' + | 41 throw 'Unexpected avg audio level: got ' + average + ', expected it ' + |
42 'to be 4000 < avg < 8000.' | 42 'to be 4000 < avg < 8000.' |
43 if (largest < 30000) | 43 if (largest < 25000) |
44 throw 'Too low max audio level: got ' + largest + ', expected > 30000.'; | 44 throw 'Too low max audio level: got ' + largest + ', expected > 30000.'; |
45 }; | 45 }; |
46 | 46 |
47 // If silent (like when muted), we should get very near zero audio level. | 47 // If silent (like when muted), we should get very near zero audio level. |
48 function verifyIsSilent(samples) { | 48 function verifyIsSilent(samples) { |
49 var average = 0; | 49 var average = 0; |
50 for (var i = 0; i < samples.length; ++i) | 50 for (var i = 0; i < samples.length; ++i) |
51 average += samples[i] / samples.length; | 51 average += samples[i] / samples.length; |
52 | 52 |
53 console.log('Average audio level: ' + average); | 53 console.log('Average audio level: ' + average); |
(...skipping 11 matching lines...) Expand all Loading... |
65 var report = reports[i]; | 65 var report = reports[i]; |
66 if (report.names().indexOf('audioOutputLevel') != -1) { | 66 if (report.names().indexOf('audioOutputLevel') != -1) { |
67 audioOutputLevels.push(report.stat('audioOutputLevel')); | 67 audioOutputLevels.push(report.stat('audioOutputLevel')); |
68 } | 68 } |
69 } | 69 } |
70 // Should only be one audio level reported, otherwise we get confused. | 70 // Should only be one audio level reported, otherwise we get confused. |
71 expectEquals(1, audioOutputLevels.length); | 71 expectEquals(1, audioOutputLevels.length); |
72 | 72 |
73 return audioOutputLevels[0]; | 73 return audioOutputLevels[0]; |
74 } | 74 } |
OLD | NEW |