Bug 1171436 - support at least 8192 elements for PeriodicWave r=padenot

This increases the maximum PeriodicWave size to 8192 and adds an optimization
to use 8192 elements only in the case where we receive more than 4096
components. In accordance with the spec, a maximum number of components is no
longer enforced.

--HG--
extra : rebase_source : ecb9a401fabdb14f23f690c44944ece434599055
This commit is contained in:
Dan Minor 2015-10-27 22:05:47 -04:00
parent 288258a78d
commit 229f2b76cc
5 changed files with 22 additions and 18 deletions

View File

@ -527,8 +527,7 @@ AudioContext::CreatePeriodicWave(const Float32Array& aRealData,
aImagData.ComputeLengthAndData();
if (aRealData.Length() != aImagData.Length() ||
aRealData.Length() == 0 ||
aRealData.Length() > 4096) {
aRealData.Length() == 0) {
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
}

View File

@ -27,7 +27,6 @@ PeriodicWave::PeriodicWave(AudioContext* aContext,
// Caller should have checked this and thrown.
MOZ_ASSERT(aLength > 0);
MOZ_ASSERT(aLength <= 4096);
mLength = aLength;
// Copy coefficient data. The two arrays share an allocation.

View File

@ -31,8 +31,8 @@
#include <cmath>
#include "mozilla/FFTBlock.h"
const unsigned PeriodicWaveSize = 4096; // This must be a power of two.
const unsigned NumberOfRanges = 36; // There should be 3 * log2(PeriodicWaveSize) 1/3 octave ranges.
const unsigned MinPeriodicWaveSize = 4096; // This must be a power of two.
const unsigned MaxPeriodicWaveSize = 8192; // This must be a power of two.
const float CentsPerRange = 1200 / 3; // 1/3 Octave.
using namespace mozilla;
@ -46,12 +46,11 @@ PeriodicWave::create(float sampleRate,
const float* imag,
size_t numberOfComponents)
{
bool isGood = real && imag && numberOfComponents > 0 &&
numberOfComponents <= PeriodicWaveSize;
bool isGood = real && imag && numberOfComponents > 0;
MOZ_ASSERT(isGood);
if (isGood) {
RefPtr<PeriodicWave> periodicWave =
new PeriodicWave(sampleRate);
new PeriodicWave(sampleRate, numberOfComponents);
periodicWave->createBandLimitedTables(real, imag, numberOfComponents);
return periodicWave.forget();
}
@ -62,7 +61,7 @@ already_AddRefed<PeriodicWave>
PeriodicWave::createSine(float sampleRate)
{
RefPtr<PeriodicWave> periodicWave =
new PeriodicWave(sampleRate);
new PeriodicWave(sampleRate, MinPeriodicWaveSize);
periodicWave->generateBasicWaveform(OscillatorType::Sine);
return periodicWave.forget();
}
@ -71,7 +70,7 @@ already_AddRefed<PeriodicWave>
PeriodicWave::createSquare(float sampleRate)
{
RefPtr<PeriodicWave> periodicWave =
new PeriodicWave(sampleRate);
new PeriodicWave(sampleRate, MinPeriodicWaveSize);
periodicWave->generateBasicWaveform(OscillatorType::Square);
return periodicWave.forget();
}
@ -80,7 +79,7 @@ already_AddRefed<PeriodicWave>
PeriodicWave::createSawtooth(float sampleRate)
{
RefPtr<PeriodicWave> periodicWave =
new PeriodicWave(sampleRate);
new PeriodicWave(sampleRate, MinPeriodicWaveSize);
periodicWave->generateBasicWaveform(OscillatorType::Sawtooth);
return periodicWave.forget();
}
@ -89,18 +88,25 @@ already_AddRefed<PeriodicWave>
PeriodicWave::createTriangle(float sampleRate)
{
RefPtr<PeriodicWave> periodicWave =
new PeriodicWave(sampleRate);
new PeriodicWave(sampleRate, MinPeriodicWaveSize);
periodicWave->generateBasicWaveform(OscillatorType::Triangle);
return periodicWave.forget();
}
PeriodicWave::PeriodicWave(float sampleRate)
PeriodicWave::PeriodicWave(float sampleRate, size_t numberOfComponents)
: m_sampleRate(sampleRate)
, m_periodicWaveSize(PeriodicWaveSize)
, m_numberOfRanges(NumberOfRanges)
, m_centsPerRange(CentsPerRange)
{
float nyquist = 0.5 * m_sampleRate;
if (numberOfComponents <= MinPeriodicWaveSize) {
m_periodicWaveSize = MinPeriodicWaveSize;
} else {
unsigned npow2 = powf(2.0f, floorf(logf(numberOfComponents - 1.0)/logf(2.0f) + 1.0f));
m_periodicWaveSize = std::min(MaxPeriodicWaveSize, npow2);
}
m_numberOfRanges = (unsigned)(3.0f*logf(m_periodicWaveSize)/logf(2.0f));
m_lowestFundamentalFrequency = nyquist / maxNumberOfPartials();
m_rateScale = m_periodicWaveSize / m_sampleRate;
}

View File

@ -76,7 +76,7 @@ public:
size_t sizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
private:
explicit PeriodicWave(float sampleRate);
explicit PeriodicWave(float sampleRate, size_t numberOfComponents);
~PeriodicWave() {}
void generateBasicWaveform(mozilla::dom::OscillatorType);

View File

@ -37,9 +37,9 @@ addLoadEvent(function() {
expectException(function() {
ac.createPeriodicWave(new Float32Array(0), new Float32Array(0));
}, DOMException.NOT_SUPPORTED_ERR);
expectException(function() {
expectNoException(function() {
ac.createPeriodicWave(new Float32Array(4097), new Float32Array(4097));
}, DOMException.NOT_SUPPORTED_ERR);
});
runTest();
});