b=991533 move sample rate limits to WebAudioUtils r=padenot

Also change WebAudioUtils from a class to a namespace, so that constant
variables can be defined inline with internal linkage.

static class variables cannot be defined inline because this violates the one
definition rule, even though some compilers may not notice.

--HG--
extra : transplant_source : %9F4%2Ct%BA%D2%BD%8A1Xev%92%C0%A1%AD%88IH%BF
This commit is contained in:
Karl Tomlinson 2014-05-16 08:44:17 +12:00
Родитель 0719aef351
Коммит 6578a0d181
4 изменённых файлов: 31 добавлений и 26 удалений

Просмотреть файл

@ -204,7 +204,9 @@ AudioContext::CreateBuffer(JSContext* aJSContext, uint32_t aNumberOfChannels,
uint32_t aLength, float aSampleRate,
ErrorResult& aRv)
{
if (aSampleRate < 8000 || aSampleRate > 192000 || !aLength || !aNumberOfChannels) {
if (aSampleRate < WebAudioUtils::MinSampleRate ||
aSampleRate > WebAudioUtils::MaxSampleRate ||
!aLength || !aNumberOfChannels) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return nullptr;
}

Просмотреть файл

@ -14,10 +14,6 @@ namespace mozilla {
namespace dom {
// 32 is the minimum required by the spec and matches what is used by blink.
// The limit protects against large memory allocations.
const size_t WebAudioUtils::MaxChannelCount = 32;
struct ConvertTimeToTickHelper
{
AudioNodeStream* mSourceStream;

Просмотреть файл

@ -24,15 +24,22 @@ namespace dom {
class AudioParamTimeline;
struct WebAudioUtils {
static const size_t MaxChannelCount;
namespace WebAudioUtils {
// 32 is the minimum required by the spec for createBuffer() and
// createScriptProcessor() and matches what is used by Blink. The limit
// protects against large memory allocations.
const size_t MaxChannelCount = 32;
// AudioContext::CreateBuffer() "must support sample-rates in at least the
// range 22050 to 96000."
const uint32_t MinSampleRate = 8000;
const uint32_t MaxSampleRate = 192000;
static bool FuzzyEqual(float v1, float v2)
inline bool FuzzyEqual(float v1, float v2)
{
using namespace std;
return fabsf(v1 - v2) < 1e-7f;
}
static bool FuzzyEqual(double v1, double v2)
inline bool FuzzyEqual(double v1, double v2)
{
using namespace std;
return fabs(v1 - v2) < 1e-7;
@ -42,7 +49,7 @@ struct WebAudioUtils {
* Computes an exponential smoothing rate for a time based variable
* over aDuration seconds.
*/
static double ComputeSmoothingRate(double aDuration, double aSampleRate)
inline double ComputeSmoothingRate(double aDuration, double aSampleRate)
{
return 1.0 - std::exp(-1.0 / (aDuration * aSampleRate));
}
@ -56,15 +63,15 @@ struct WebAudioUtils {
* received. This means that such engines need to be aware of their source
* and destination streams as well.
*/
static void ConvertAudioParamToTicks(AudioParamTimeline& aParam,
AudioNodeStream* aSource,
AudioNodeStream* aDest);
void ConvertAudioParamToTicks(AudioParamTimeline& aParam,
AudioNodeStream* aSource,
AudioNodeStream* aDest);
/**
* Converts a linear value to decibels. Returns aMinDecibels if the linear
* value is 0.
*/
static float ConvertLinearToDecibels(float aLinearValue, float aMinDecibels)
inline float ConvertLinearToDecibels(float aLinearValue, float aMinDecibels)
{
return aLinearValue ? 20.0f * std::log10(aLinearValue) : aMinDecibels;
}
@ -72,7 +79,7 @@ struct WebAudioUtils {
/**
* Converts a decibel value to a linear value.
*/
static float ConvertDecibelsToLinear(float aDecibels)
inline float ConvertDecibelsToLinear(float aDecibels)
{
return std::pow(10.0f, 0.05f * aDecibels);
}
@ -80,24 +87,24 @@ struct WebAudioUtils {
/**
* Converts a decibel to a linear value.
*/
static float ConvertDecibelToLinear(float aDecibel)
inline float ConvertDecibelToLinear(float aDecibel)
{
return std::pow(10.0f, 0.05f * aDecibel);
}
static void FixNaN(double& aDouble)
inline void FixNaN(double& aDouble)
{
if (IsNaN(aDouble) || IsInfinite(aDouble)) {
aDouble = 0.0;
}
}
static double DiscreteTimeConstantForSampleRate(double timeConstant, double sampleRate)
inline double DiscreteTimeConstantForSampleRate(double timeConstant, double sampleRate)
{
return 1.0 - std::exp(-1.0 / (sampleRate * timeConstant));
}
static bool IsTimeValid(double aTime)
inline bool IsTimeValid(double aTime)
{
return aTime >= 0 && aTime <= (MEDIA_TIME_MAX >> MEDIA_TIME_FRAC_BITS);
}
@ -165,7 +172,7 @@ struct WebAudioUtils {
* it sees a NaN.
*/
template <typename IntType, typename FloatType>
static IntType TruncateFloatToInt(FloatType f)
IntType TruncateFloatToInt(FloatType f)
{
using namespace std;
@ -196,26 +203,26 @@ struct WebAudioUtils {
return IntType(f);
}
static void Shutdown();
void Shutdown();
static int
int
SpeexResamplerProcess(SpeexResamplerState* aResampler,
uint32_t aChannel,
const float* aIn, uint32_t* aInLen,
float* aOut, uint32_t* aOutLen);
static int
int
SpeexResamplerProcess(SpeexResamplerState* aResampler,
uint32_t aChannel,
const int16_t* aIn, uint32_t* aInLen,
float* aOut, uint32_t* aOutLen);
static int
int
SpeexResamplerProcess(SpeexResamplerState* aResampler,
uint32_t aChannel,
const int16_t* aIn, uint32_t* aInLen,
int16_t* aOut, uint32_t* aOutLen);
};
}
}
}

Просмотреть файл

@ -37,7 +37,7 @@
using namespace std;
using mozilla::dom::WebAudioUtils;
using namespace mozilla::dom; // for WebAudioUtils
using mozilla::IsInfinite;
using mozilla::IsNaN;