Chromium Code Reviews| Index: content/test/data/media/webrtc_test_audio.js |
| diff --git a/content/test/data/media/webrtc_test_audio.js b/content/test/data/media/webrtc_test_audio.js |
| index 40668c6d38180c9e3b96f1de13d26f8a5ae6a41c..da422f0dd8b88dbe0bd6ef65035edadbb8f07a45 100644 |
| --- a/content/test/data/media/webrtc_test_audio.js |
| +++ b/content/test/data/media/webrtc_test_audio.js |
| @@ -24,26 +24,34 @@ function gatherAudioLevelSamples(peerConnection, numSamples, frequency, |
| // Tries to identify the beep-every-second signal generated by the fake audio |
| // media/audio/fake_audio_input_stream.cc. Fails the test if we can't see a |
| -// signal. |
| +// signal. The samples should have been gathered over at least three seconds |
| +// since we expect to see at least two "peaks" in there. |
| function verifyAudioIsPlaying(samples) { |
| - var average = 0; |
| - for (var i = 0; i < samples.length; ++i) |
| - average += samples[i] / samples.length; |
| + var numPeaks = 0; |
| + 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.
|
| + var threshold = maxLevel * 0.8; |
| + var currentlyOverThreshold = false; |
| + |
| + // Detect when we have been been over the threshold and is going back again |
| + // (i.e. count peaks). We should see about one peak per second. |
| + for (var i = 0; i < samples.length; ++i) { |
| + if (currentlyOverThreshold && samples[i] < threshold) |
| + numPeaks++; |
| + currentlyOverThreshold = samples[i] >= threshold; |
| + } |
| var largest = 0; |
| for (var i = 0; i < samples.length; ++i) |
| largest = Math.max(largest, samples[i]); |
| - console.log('Average audio level: ' + average + ', largest: ' + largest); |
| + console.log('Number of peaks identified: ' + numPeaks + ', max: ' + largest); |
| + |
| + if (numPeaks < 2) |
| + failTest('Expected to see at least two peaks in audio signal, got ' + |
| + numPeaks + '. Dumping samples for analysis: "' + samples + '"'); |
| - // TODO(phoglund): Make a more sophisticated curve-fitting algorithm. We want |
| - // to see a number of peaks with relative silence between them. The following |
| - // seems to work fine on a nexus 7. |
| - if (average < 3000 || average > 8000) |
| - failTest('Unexpected avg audio level: got ' + average + ', expected it ' + |
| - 'to be 4000 < avg < 8000.'); |
| if (largest < 25000) |
| - failTest('Too low max audio level: got ' + largest + ', expected > 30000.'); |
| + failTest('Too low max audio level: got ' + largest + ', expected > 25000.'); |
| } |
| // If silent (like when muted), we should get very near zero audio level. |