Chromium Code Reviews| Index: third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp |
| diff --git a/third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp b/third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp |
| index b9082f9a3d64e14c00199d0a0ea36e4dcedf5f60..291692bd57af06901b84a4a0e2678783667aba6f 100644 |
| --- a/third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp |
| +++ b/third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp |
| @@ -234,7 +234,47 @@ AudioBuffer* AbstractAudioContext::createBuffer(unsigned numberOfChannels, size_ |
| // It's ok to call createBuffer, even if the context is closed because the AudioBuffer doesn't |
| // really "belong" to any particular context. |
| - return AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate, exceptionState); |
| + AudioBuffer* buffer = AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate, exceptionState); |
| + |
| + if (buffer) { |
| + // Only record the data if the creation succeeded. |
| + DEFINE_STATIC_LOCAL(SparseHistogram, audioBufferChannelsHistogram, |
| + ("WebAudio.AudioBuffer.NumberOfChannels")); |
| + DEFINE_STATIC_LOCAL(SparseHistogram, audioBufferLengthHistogram, |
| + ("WebAudio.AudioBuffer.Length")); |
| + DEFINE_STATIC_LOCAL(SparseHistogram, audioBufferSampleRateHistogram, |
| + ("WebAudio.AudioBuffer.SampleRate")); |
| + |
| + audioBufferChannelsHistogram.sample(numberOfChannels); |
| + |
| + // To limit the size of the histogram, record 10*log10(numberOfFrames), |
| + // clipping the value at 60 (buffer size of 1 million frames). This |
| + // gives 60 entries in the histogram. |
| + double histogramValue = 10*log10(numberOfFrames); |
| + audioBufferLengthHistogram.sample(clampTo(static_cast<int>(0.5 + histogramValue), 0, 60)); |
|
Mark P
2016/06/09 20:18:23
If you're doing a histogram with min and max and e
Raymond Toy
2016/06/09 22:34:28
Done.
|
| + |
| + // To limit the size of the histogram, record |
| + // 40+10*log2(sampleRate/48000), clipping the value to lie between 0 |
| + // and 60. These limits correspond to a min rate of 3000 and a max of |
| + // 192000. This gives 60 entries in the histogram. |
| + histogramValue = 40 + 10*log2(sampleRate / 48000); |
| + audioBufferSampleRateHistogram.sample(clampTo(static_cast<int>(0.5 + histogramValue), 0, 60)); |
| + |
| + // Compute the ratio of the buffer rate and the context rate so we know |
| + // how often the buffer needs to be resampled to match the context. For |
| + // the histogram, we multiply the ratio by 100 and round to the nearest |
| + // integer. If the context is closed, don't record this because we |
| + // don't have a sample rate for closed context. |
| + if (!isContextClosed()) { |
| + DEFINE_STATIC_LOCAL(SparseHistogram, audioBufferSampleRateRatioHistogram, |
| + ("WebAudio.AudioBuffer.SampleRateRatio")); |
| + float ratio = sampleRate / this->sampleRate(); |
| + histogramValue = clampTo(40 + 10*log2(ratio), 0.0, 60.0); |
| + audioBufferSampleRateRatioHistogram.sample(static_cast<int>(0.5 + histogramValue)); |
| + } |
| + } |
| + |
| + return buffer; |
| } |
| ScriptPromise AbstractAudioContext::decodeAudioData(ScriptState* scriptState, DOMArrayBuffer* audioData, AudioBufferCallback* successCallback, AudioBufferCallback* errorCallback, ExceptionState& exceptionState) |