Bug 1324659 - AudioParam.minValue/maxValue, r=padenot

This commit is contained in:
Andrea Marchesini 2016-12-21 10:53:38 +01:00
parent 60364b27c9
commit 7d3342df6b
16 changed files with 115 additions and 32 deletions

View File

@ -597,8 +597,8 @@ AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext)
, mLoopStart(0.0)
, mLoopEnd(0.0)
// mOffset and mDuration are initialized in Start().
, mPlaybackRate(new AudioParam(this, PLAYBACKRATE, 1.0f, "playbackRate"))
, mDetune(new AudioParam(this, DETUNE, 0.0f, "detune"))
, mPlaybackRate(new AudioParam(this, PLAYBACKRATE, "playbackRate", 1.0f))
, mDetune(new AudioParam(this, DETUNE, "detune", 0.0f))
, mLoop(false)
, mStartCalled(false)
{

View File

@ -35,13 +35,17 @@ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioParam, Release)
AudioParam::AudioParam(AudioNode* aNode,
uint32_t aIndex,
const char* aName,
float aDefaultValue,
const char* aName)
float aMinValue,
float aMaxValue)
: AudioParamTimeline(aDefaultValue)
, mNode(aNode)
, mName(aName)
, mIndex(aIndex)
, mDefaultValue(aDefaultValue)
, mMinValue(aMinValue)
, mMaxValue(aMaxValue)
{
}

View File

@ -27,8 +27,10 @@ class AudioParam final : public nsWrapperCache,
public:
AudioParam(AudioNode* aNode,
uint32_t aIndex,
const char* aName,
float aDefaultValue,
const char* aName);
float aMinValue = -std::numeric_limits<float>::infinity(),
float aMaxValue = std::numeric_limits<float>::infinity());
NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
NS_IMETHOD_(MozExternalRefCountType) Release(void);
@ -165,6 +167,16 @@ public:
return mDefaultValue;
}
float MinValue() const
{
return mMinValue;
}
float MaxValue() const
{
return mMaxValue;
}
const nsTArray<AudioNode::InputNode>& InputNodes() const
{
return mInputNodes;
@ -244,6 +256,8 @@ private:
RefPtr<MediaInputPort> mNodeStreamPort;
const uint32_t mIndex;
const float mDefaultValue;
const float mMinValue;
const float mMaxValue;
};
} // namespace dom

View File

@ -251,10 +251,12 @@ BiquadFilterNode::BiquadFilterNode(AudioContext* aContext)
ChannelInterpretation::Speakers)
, mType(BiquadFilterType::Lowpass)
, mFrequency(new AudioParam(this, BiquadFilterNodeEngine::FREQUENCY,
350.f, "frequency"))
, mDetune(new AudioParam(this, BiquadFilterNodeEngine::DETUNE, 0.f, "detune"))
, mQ(new AudioParam(this, BiquadFilterNodeEngine::Q, 1.f, "Q"))
, mGain(new AudioParam(this, BiquadFilterNodeEngine::GAIN, 0.f, "gain"))
"frequency", 350.f,
-(aContext->SampleRate() / 2),
aContext->SampleRate() / 2))
, mDetune(new AudioParam(this, BiquadFilterNodeEngine::DETUNE, "detune", 0.f))
, mQ(new AudioParam(this, BiquadFilterNodeEngine::Q, "Q", 1.f))
, mGain(new AudioParam(this, BiquadFilterNodeEngine::GAIN, "gain", 0.f))
{
uint64_t windowID = aContext->GetParentObject()->WindowID();
BiquadFilterNodeEngine* engine = new BiquadFilterNodeEngine(this, aContext->Destination(), windowID);

View File

@ -147,7 +147,7 @@ ConstantSourceNode::ConstantSourceNode(AudioContext* aContext)
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mOffset(new AudioParam(this, ConstantSourceNodeEngine::OFFSET,
1.0, "offset"))
"offset", 1.0f))
, mStartCalled(false)
{
ConstantSourceNodeEngine* engine = new ConstantSourceNodeEngine(this, aContext->Destination());

View File

@ -196,7 +196,8 @@ DelayNode::DelayNode(AudioContext* aContext, double aMaxDelay)
2,
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mDelay(new AudioParam(this, DelayNodeEngine::DELAY, 0.0f, "delayTime"))
, mDelay(new AudioParam(this, DelayNodeEngine::DELAY, "delayTime", 0.0f,
0.f, aMaxDelay))
{
DelayNodeEngine* engine =
new DelayNodeEngine(this, aContext->Destination(),

View File

@ -188,16 +188,16 @@ DynamicsCompressorNode::DynamicsCompressorNode(AudioContext* aContext)
ChannelCountMode::Explicit,
ChannelInterpretation::Speakers)
, mThreshold(new AudioParam(this, DynamicsCompressorNodeEngine::THRESHOLD,
-24.f, "threshold"))
"threshold", -24.f, -100.f, 0.f))
, mKnee(new AudioParam(this, DynamicsCompressorNodeEngine::KNEE,
30.f, "knee"))
"knee", 30.f, 0.f, 40.f))
, mRatio(new AudioParam(this, DynamicsCompressorNodeEngine::RATIO,
12.f, "ratio"))
"ratio", 12.f, 1.f, 20.f))
, mReduction(0)
, mAttack(new AudioParam(this, DynamicsCompressorNodeEngine::ATTACK,
0.003f, "attack"))
"attack", 0.003f, 0.f, 1.f))
, mRelease(new AudioParam(this, DynamicsCompressorNodeEngine::RELEASE,
0.25f, "release"))
"release", 0.25f, 0.f, 1.f))
{
DynamicsCompressorNodeEngine* engine = new DynamicsCompressorNodeEngine(this, aContext->Destination());
mStream = AudioNodeStream::Create(aContext, engine,

View File

@ -120,7 +120,7 @@ GainNode::GainNode(AudioContext* aContext)
2,
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mGain(new AudioParam(this, GainNodeEngine::GAIN, 1.0f, "gain"))
, mGain(new AudioParam(this, GainNodeEngine::GAIN, "gain", 1.0f))
{
GainNodeEngine* engine = new GainNodeEngine(this, aContext->Destination());
mStream = AudioNodeStream::Create(aContext, engine,

View File

@ -413,11 +413,13 @@ OscillatorNode::OscillatorNode(AudioContext* aContext)
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
, mType(OscillatorType::Sine)
, mFrequency(new AudioParam(this, OscillatorNodeEngine::FREQUENCY,
440.0f, "frequency"))
, mDetune(new AudioParam(this, OscillatorNodeEngine::DETUNE, 0.0f, "detune"))
, mFrequency(
new AudioParam(this, OscillatorNodeEngine::FREQUENCY, "frequency", 440.0f,
-(aContext->SampleRate() / 2), aContext->SampleRate() / 2))
, mDetune(new AudioParam(this, OscillatorNodeEngine::DETUNE, "detune", 0.0f))
, mStartCalled(false)
{
OscillatorNodeEngine* engine = new OscillatorNodeEngine(this, aContext->Destination());
mStream = AudioNodeStream::Create(aContext, engine,
AudioNodeStream::NEED_MAIN_THREAD_FINISHED,

View File

@ -301,12 +301,12 @@ PannerNode::PannerNode(AudioContext* aContext)
// Please keep these default values consistent with PannerNodeEngine::PannerNodeEngine above.
, mPanningModel(PanningModelType::Equalpower)
, mDistanceModel(DistanceModelType::Inverse)
, mPositionX(new AudioParam(this, PannerNode::POSITIONX, 0., this->NodeType()))
, mPositionY(new AudioParam(this, PannerNode::POSITIONY, 0., this->NodeType()))
, mPositionZ(new AudioParam(this, PannerNode::POSITIONZ, 0., this->NodeType()))
, mOrientationX(new AudioParam(this, PannerNode::ORIENTATIONX, 1., this->NodeType()))
, mOrientationY(new AudioParam(this, PannerNode::ORIENTATIONY, 0., this->NodeType()))
, mOrientationZ(new AudioParam(this, PannerNode::ORIENTATIONZ, 0., this->NodeType()))
, mPositionX(new AudioParam(this, PannerNode::POSITIONX, this->NodeType(), 0.f))
, mPositionY(new AudioParam(this, PannerNode::POSITIONY, this->NodeType(), 0.f))
, mPositionZ(new AudioParam(this, PannerNode::POSITIONZ, this->NodeType(), 0.f))
, mOrientationX(new AudioParam(this, PannerNode::ORIENTATIONX, this->NodeType(), 1.0f))
, mOrientationY(new AudioParam(this, PannerNode::ORIENTATIONY, this->NodeType(), 0.f))
, mOrientationZ(new AudioParam(this, PannerNode::ORIENTATIONZ, this->NodeType(), 0.f))
, mVelocity()
, mRefDistance(1.)
, mMaxDistance(10000.)

View File

@ -175,7 +175,7 @@ StereoPannerNode::StereoPannerNode(AudioContext* aContext)
2,
ChannelCountMode::Clamped_max,
ChannelInterpretation::Speakers)
, mPan(new AudioParam(this, StereoPannerNodeEngine::PAN, 0.f, "pan"))
, mPan(new AudioParam(this, StereoPannerNodeEngine::PAN, "pan", 0.f, -1.f, 1.f))
{
StereoPannerNodeEngine* engine = new StereoPannerNodeEngine(this, aContext->Destination());
mStream = AudioNodeStream::Create(aContext, engine,

View File

@ -13,8 +13,10 @@
[Pref="dom.webaudio.enabled"]
interface AudioParam {
attribute float value;
readonly attribute float defaultValue;
attribute float value;
readonly attribute float defaultValue;
readonly attribute float minValue;
readonly attribute float maxValue;
// Parameter automation.
[Throws]

View File

@ -32193,6 +32193,10 @@
"path": "webaudio/the-audio-api/the-audionode-interface/audionode-connect-return-value.html",
"url": "/webaudio/the-audio-api/the-audionode-interface/audionode-connect-return-value.html"
},
{
"path": "webaudio/the-audio-api/the-audioparam-interface/idl-test.html",
"url": "/webaudio/the-audio-api/the-audioparam-interface/idl-test.html"
},
{
"path": "webaudio/the-audio-api/the-audioparam-interface/retrospective-setValueAtTime.html",
"url": "/webaudio/the-audio-api/the-audioparam-interface/retrospective-setValueAtTime.html"

View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html class="a">
<head>
<title>AudioParam IDL Test</title>
<script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script><script src="/resources/idlharness.js"></script><script src="/resources/WebIDLParser.js"></script><script src="/webaudio/js/lodash.js"></script><script src="/webaudio/js/vendor-prefixes.js"></script><script src="/webaudio/js/helpers.js"></script><style type="text/css">
#audio-param-idl
{ visibility:hidden; height: 0px;}
</style>
</head>
<body class="a">
<pre id="audio-param-idl">interface AudioParam {
attribute float value;
readonly attribute float defaultValue;
readonly attribute float minValue;
readonly attribute float maxValue;
// Parameter automation.
void setValueAtTime(float value, double startTime);
void linearRampToValueAtTime(float value, double endTime);
void exponentialRampToValueAtTime(float value, double endTime);
// Exponentially approach the target value with a rate having the given time constant.
void setTargetAtTime(float target, double startTime, double timeConstant);
// Sets an array of arbitrary parameter values starting at time for the given duration.
// The number of values will be scaled to fit into the desired duration.
void setValueCurveAtTime(Float32Array values, double startTime, double duration);
// Cancels all scheduled parameter changes with times greater than or equal to startTime.
void cancelScheduledValues(double startTime);
};</pre>
<div id="log"></div>
<script>
(function() {
var idl_array = new IdlArray();
idl_array.add_untested_idls(document.getElementById("audio-param-idl").textContent);
delay_time = (new AudioContext).createDelay().delayTime;
idl_array.add_objects({AudioParam: ["delay_time"]});
idl_array.test();
})();
</script>
</body>
</html>

View File

@ -96,8 +96,10 @@ interface AudioNode : EventTarget {
<pre id="audio-param-idl">interface AudioParam {
attribute float value;
readonly attribute float defaultValue;
attribute float value;
readonly attribute float defaultValue;
readonly attribute float minValue;
readonly attribute float maxValue;
// Parameter automation.
void setValueAtTime(float value, double startTime);

View File

@ -95,8 +95,10 @@ interface AudioNode : EventTarget {
<pre id="audio-param-idl">interface AudioParam {
attribute float value;
readonly attribute float defaultValue;
attribute float value;
readonly attribute float defaultValue;
readonly attribute float minValue;
readonly attribute float maxValue;
// Parameter automation.
void setValueAtTime(float value, double startTime);