mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibWeb/WebAudio: Implement automation rate constraints
Some nodes have parameters whose automation rate is not allowed to be changed. This change enforces that constraint for all parameters it applies to.
This commit is contained in:
parent
575edf8a90
commit
c87f80454b
Notes:
github-actions[bot]
2025-01-19 16:25:50 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/c87f80454be Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3301
6 changed files with 316 additions and 13 deletions
|
@ -18,8 +18,8 @@ GC_DEFINE_ALLOCATOR(AudioBufferSourceNode);
|
||||||
AudioBufferSourceNode::AudioBufferSourceNode(JS::Realm& realm, GC::Ref<BaseAudioContext> context, AudioBufferSourceOptions const& options)
|
AudioBufferSourceNode::AudioBufferSourceNode(JS::Realm& realm, GC::Ref<BaseAudioContext> context, AudioBufferSourceOptions const& options)
|
||||||
: AudioScheduledSourceNode(realm, context)
|
: AudioScheduledSourceNode(realm, context)
|
||||||
, m_buffer(options.buffer)
|
, m_buffer(options.buffer)
|
||||||
, m_playback_rate(AudioParam::create(realm, context, options.playback_rate, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::KRate))
|
, m_playback_rate(AudioParam::create(realm, context, options.playback_rate, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::KRate, AudioParam::FixedAutomationRate::Yes))
|
||||||
, m_detune(AudioParam::create(realm, context, options.detune, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::KRate))
|
, m_detune(AudioParam::create(realm, context, options.detune, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::KRate, AudioParam::FixedAutomationRate::Yes))
|
||||||
, m_loop(options.loop)
|
, m_loop(options.loop)
|
||||||
, m_loop_start(options.loop_start)
|
, m_loop_start(options.loop_start)
|
||||||
, m_loop_end(options.loop_end)
|
, m_loop_end(options.loop_end)
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Web::WebAudio {
|
||||||
|
|
||||||
GC_DEFINE_ALLOCATOR(AudioParam);
|
GC_DEFINE_ALLOCATOR(AudioParam);
|
||||||
|
|
||||||
AudioParam::AudioParam(JS::Realm& realm, GC::Ref<BaseAudioContext> context, float default_value, float min_value, float max_value, Bindings::AutomationRate automation_rate)
|
AudioParam::AudioParam(JS::Realm& realm, GC::Ref<BaseAudioContext> context, float default_value, float min_value, float max_value, Bindings::AutomationRate automation_rate, FixedAutomationRate fixed_automation_rate)
|
||||||
: Bindings::PlatformObject(realm)
|
: Bindings::PlatformObject(realm)
|
||||||
, m_context(context)
|
, m_context(context)
|
||||||
, m_current_value(default_value)
|
, m_current_value(default_value)
|
||||||
|
@ -22,12 +22,13 @@ AudioParam::AudioParam(JS::Realm& realm, GC::Ref<BaseAudioContext> context, floa
|
||||||
, m_min_value(min_value)
|
, m_min_value(min_value)
|
||||||
, m_max_value(max_value)
|
, m_max_value(max_value)
|
||||||
, m_automation_rate(automation_rate)
|
, m_automation_rate(automation_rate)
|
||||||
|
, m_fixed_automation_rate(fixed_automation_rate)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GC::Ref<AudioParam> AudioParam::create(JS::Realm& realm, GC::Ref<BaseAudioContext> context, float default_value, float min_value, float max_value, Bindings::AutomationRate automation_rate)
|
GC::Ref<AudioParam> AudioParam::create(JS::Realm& realm, GC::Ref<BaseAudioContext> context, float default_value, float min_value, float max_value, Bindings::AutomationRate automation_rate, FixedAutomationRate fixed_automation_rate)
|
||||||
{
|
{
|
||||||
return realm.create<AudioParam>(realm, context, default_value, min_value, max_value, automation_rate);
|
return realm.create<AudioParam>(realm, context, default_value, min_value, max_value, automation_rate, fixed_automation_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioParam::~AudioParam() = default;
|
AudioParam::~AudioParam() = default;
|
||||||
|
@ -56,7 +57,9 @@ Bindings::AutomationRate AudioParam::automation_rate() const
|
||||||
// https://webaudio.github.io/web-audio-api/#dom-audioparam-automationrate
|
// https://webaudio.github.io/web-audio-api/#dom-audioparam-automationrate
|
||||||
WebIDL::ExceptionOr<void> AudioParam::set_automation_rate(Bindings::AutomationRate automation_rate)
|
WebIDL::ExceptionOr<void> AudioParam::set_automation_rate(Bindings::AutomationRate automation_rate)
|
||||||
{
|
{
|
||||||
dbgln("FIXME: Fully implement AudioParam::set_automation_rate");
|
if (automation_rate != m_automation_rate && m_fixed_automation_rate == FixedAutomationRate::Yes)
|
||||||
|
return WebIDL::InvalidStateError::create(realm(), "Automation rate cannot be changed"_string);
|
||||||
|
|
||||||
m_automation_rate = automation_rate;
|
m_automation_rate = automation_rate;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,11 @@ class AudioParam final : public Bindings::PlatformObject {
|
||||||
GC_DECLARE_ALLOCATOR(AudioParam);
|
GC_DECLARE_ALLOCATOR(AudioParam);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static GC::Ref<AudioParam> create(JS::Realm&, GC::Ref<BaseAudioContext>, float default_value, float min_value, float max_value, Bindings::AutomationRate);
|
enum class FixedAutomationRate {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
};
|
||||||
|
static GC::Ref<AudioParam> create(JS::Realm&, GC::Ref<BaseAudioContext>, float default_value, float min_value, float max_value, Bindings::AutomationRate, FixedAutomationRate = FixedAutomationRate::No);
|
||||||
|
|
||||||
virtual ~AudioParam() override;
|
virtual ~AudioParam() override;
|
||||||
|
|
||||||
|
@ -43,7 +47,7 @@ public:
|
||||||
WebIDL::ExceptionOr<GC::Ref<AudioParam>> cancel_and_hold_at_time(double cancel_time);
|
WebIDL::ExceptionOr<GC::Ref<AudioParam>> cancel_and_hold_at_time(double cancel_time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AudioParam(JS::Realm&, GC::Ref<BaseAudioContext>, float default_value, float min_value, float max_value, Bindings::AutomationRate);
|
AudioParam(JS::Realm&, GC::Ref<BaseAudioContext>, float default_value, float min_value, float max_value, Bindings::AutomationRate, FixedAutomationRate = FixedAutomationRate::No);
|
||||||
|
|
||||||
GC::Ref<BaseAudioContext> m_context;
|
GC::Ref<BaseAudioContext> m_context;
|
||||||
|
|
||||||
|
@ -57,6 +61,8 @@ private:
|
||||||
|
|
||||||
Bindings::AutomationRate m_automation_rate {};
|
Bindings::AutomationRate m_automation_rate {};
|
||||||
|
|
||||||
|
FixedAutomationRate m_fixed_automation_rate { FixedAutomationRate::No };
|
||||||
|
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
virtual void visit_edges(Cell::Visitor&) override;
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,11 +41,11 @@ WebIDL::ExceptionOr<GC::Ref<DynamicsCompressorNode>> DynamicsCompressorNode::con
|
||||||
|
|
||||||
DynamicsCompressorNode::DynamicsCompressorNode(JS::Realm& realm, GC::Ref<BaseAudioContext> context, DynamicsCompressorOptions const& options)
|
DynamicsCompressorNode::DynamicsCompressorNode(JS::Realm& realm, GC::Ref<BaseAudioContext> context, DynamicsCompressorOptions const& options)
|
||||||
: AudioNode(realm, context)
|
: AudioNode(realm, context)
|
||||||
, m_threshold(AudioParam::create(realm, context, options.threshold, -100, 0, Bindings::AutomationRate::KRate))
|
, m_threshold(AudioParam::create(realm, context, options.threshold, -100, 0, Bindings::AutomationRate::KRate, AudioParam::FixedAutomationRate::Yes))
|
||||||
, m_knee(AudioParam::create(realm, context, options.knee, 0, 40, Bindings::AutomationRate::KRate))
|
, m_knee(AudioParam::create(realm, context, options.knee, 0, 40, Bindings::AutomationRate::KRate, AudioParam::FixedAutomationRate::Yes))
|
||||||
, m_ratio(AudioParam::create(realm, context, options.ratio, 1, 20, Bindings::AutomationRate::KRate))
|
, m_ratio(AudioParam::create(realm, context, options.ratio, 1, 20, Bindings::AutomationRate::KRate, AudioParam::FixedAutomationRate::Yes))
|
||||||
, m_attack(AudioParam::create(realm, context, options.attack, 0, 1, Bindings::AutomationRate::KRate))
|
, m_attack(AudioParam::create(realm, context, options.attack, 0, 1, Bindings::AutomationRate::KRate, AudioParam::FixedAutomationRate::Yes))
|
||||||
, m_release(AudioParam::create(realm, context, options.release, 0, 1, Bindings::AutomationRate::KRate))
|
, m_release(AudioParam::create(realm, context, options.release, 0, 1, Bindings::AutomationRate::KRate, AudioParam::FixedAutomationRate::Yes))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 122 tests
|
||||||
|
|
||||||
|
122 Pass
|
||||||
|
Pass # AUDIT TASK RUNNER STARTED.
|
||||||
|
Pass Executing "AudioBufferSourceNode"
|
||||||
|
Pass Executing "BiquadFilterNode"
|
||||||
|
Pass Executing "ConstantSourceNode"
|
||||||
|
Pass Executing "DelayNode"
|
||||||
|
Pass Executing "DynamicsCompressorNode"
|
||||||
|
Pass Executing "GainNode"
|
||||||
|
Pass Executing "OscillatorNode"
|
||||||
|
Pass Executing "PannerNode"
|
||||||
|
Pass Executing "StereoPannerNode"
|
||||||
|
Pass Executing "AudioListener"
|
||||||
|
Pass Audit report
|
||||||
|
Pass > [AudioBufferSourceNode]
|
||||||
|
Pass Default AudioBufferSourceNode.detune.automationRate is equal to k-rate.
|
||||||
|
Pass Set AudioBufferSourceNode.detune.automationRate to "a-rate" threw InvalidStateError: "Automation rate cannot be changed".
|
||||||
|
Pass Default AudioBufferSourceNode.playbackRate.automationRate is equal to k-rate.
|
||||||
|
Pass Set AudioBufferSourceNode.playbackRate.automationRate to "a-rate" threw InvalidStateError: "Automation rate cannot be changed".
|
||||||
|
Pass < [AudioBufferSourceNode] All assertions passed. (total 4 assertions)
|
||||||
|
Pass > [BiquadFilterNode]
|
||||||
|
Pass Default BiquadFilterNode.frequency.automationRate is equal to a-rate.
|
||||||
|
Pass Set BiquadFilterNode.frequency.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass BiquadFilterNode.frequency.automationRate is equal to k-rate.
|
||||||
|
Pass Default BiquadFilterNode.detune.automationRate is equal to a-rate.
|
||||||
|
Pass Set BiquadFilterNode.detune.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass BiquadFilterNode.detune.automationRate is equal to k-rate.
|
||||||
|
Pass Default BiquadFilterNode.Q.automationRate is equal to a-rate.
|
||||||
|
Pass Set BiquadFilterNode.Q.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass BiquadFilterNode.Q.automationRate is equal to k-rate.
|
||||||
|
Pass Default BiquadFilterNode.gain.automationRate is equal to a-rate.
|
||||||
|
Pass Set BiquadFilterNode.gain.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass BiquadFilterNode.gain.automationRate is equal to k-rate.
|
||||||
|
Pass < [BiquadFilterNode] All assertions passed. (total 12 assertions)
|
||||||
|
Pass > [ConstantSourceNode]
|
||||||
|
Pass Default ConstantSourceNode.offset.automationRate is equal to a-rate.
|
||||||
|
Pass Set ConstantSourceNode.offset.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass ConstantSourceNode.offset.automationRate is equal to k-rate.
|
||||||
|
Pass < [ConstantSourceNode] All assertions passed. (total 3 assertions)
|
||||||
|
Pass > [DelayNode]
|
||||||
|
Pass Default DelayNode.delayTime.automationRate is equal to a-rate.
|
||||||
|
Pass Set DelayNode.delayTime.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass DelayNode.delayTime.automationRate is equal to k-rate.
|
||||||
|
Pass < [DelayNode] All assertions passed. (total 3 assertions)
|
||||||
|
Pass > [DynamicsCompressorNode]
|
||||||
|
Pass Default DynamicsCompressorNode.threshold.automationRate is equal to k-rate.
|
||||||
|
Pass Set DynamicsCompressorNode.threshold.automationRate to "a-rate" threw InvalidStateError: "Automation rate cannot be changed".
|
||||||
|
Pass Default DynamicsCompressorNode.knee.automationRate is equal to k-rate.
|
||||||
|
Pass Set DynamicsCompressorNode.knee.automationRate to "a-rate" threw InvalidStateError: "Automation rate cannot be changed".
|
||||||
|
Pass Default DynamicsCompressorNode.ratio.automationRate is equal to k-rate.
|
||||||
|
Pass Set DynamicsCompressorNode.ratio.automationRate to "a-rate" threw InvalidStateError: "Automation rate cannot be changed".
|
||||||
|
Pass Default DynamicsCompressorNode.attack.automationRate is equal to k-rate.
|
||||||
|
Pass Set DynamicsCompressorNode.attack.automationRate to "a-rate" threw InvalidStateError: "Automation rate cannot be changed".
|
||||||
|
Pass Default DynamicsCompressorNode.release.automationRate is equal to k-rate.
|
||||||
|
Pass Set DynamicsCompressorNode.release.automationRate to "a-rate" threw InvalidStateError: "Automation rate cannot be changed".
|
||||||
|
Pass < [DynamicsCompressorNode] All assertions passed. (total 10 assertions)
|
||||||
|
Pass > [GainNode]
|
||||||
|
Pass Default GainNode.gain.automationRate is equal to a-rate.
|
||||||
|
Pass Set GainNode.gain.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass GainNode.gain.automationRate is equal to k-rate.
|
||||||
|
Pass < [GainNode] All assertions passed. (total 3 assertions)
|
||||||
|
Pass > [OscillatorNode]
|
||||||
|
Pass Default OscillatorNode.frequency.automationRate is equal to a-rate.
|
||||||
|
Pass Set OscillatorNode.frequency.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass OscillatorNode.frequency.automationRate is equal to k-rate.
|
||||||
|
Pass Default OscillatorNode.detune.automationRate is equal to a-rate.
|
||||||
|
Pass Set OscillatorNode.detune.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass OscillatorNode.detune.automationRate is equal to k-rate.
|
||||||
|
Pass < [OscillatorNode] All assertions passed. (total 6 assertions)
|
||||||
|
Pass > [PannerNode]
|
||||||
|
Pass Default PannerNode.positionX.automationRate is equal to a-rate.
|
||||||
|
Pass Set PannerNode.positionX.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass PannerNode.positionX.automationRate is equal to k-rate.
|
||||||
|
Pass Default PannerNode.positionY.automationRate is equal to a-rate.
|
||||||
|
Pass Set PannerNode.positionY.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass PannerNode.positionY.automationRate is equal to k-rate.
|
||||||
|
Pass Default PannerNode.positionZ.automationRate is equal to a-rate.
|
||||||
|
Pass Set PannerNode.positionZ.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass PannerNode.positionZ.automationRate is equal to k-rate.
|
||||||
|
Pass Default PannerNode.orientationX.automationRate is equal to a-rate.
|
||||||
|
Pass Set PannerNode.orientationX.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass PannerNode.orientationX.automationRate is equal to k-rate.
|
||||||
|
Pass Default PannerNode.orientationY.automationRate is equal to a-rate.
|
||||||
|
Pass Set PannerNode.orientationY.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass PannerNode.orientationY.automationRate is equal to k-rate.
|
||||||
|
Pass Default PannerNode.orientationZ.automationRate is equal to a-rate.
|
||||||
|
Pass Set PannerNode.orientationZ.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass PannerNode.orientationZ.automationRate is equal to k-rate.
|
||||||
|
Pass < [PannerNode] All assertions passed. (total 18 assertions)
|
||||||
|
Pass > [StereoPannerNode]
|
||||||
|
Pass Default StereoPannerNode.pan.automationRate is equal to a-rate.
|
||||||
|
Pass Set StereoPannerNode.pan.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass StereoPannerNode.pan.automationRate is equal to k-rate.
|
||||||
|
Pass < [StereoPannerNode] All assertions passed. (total 3 assertions)
|
||||||
|
Pass > [AudioListener]
|
||||||
|
Pass Default AudioListener.positionX.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.positionX.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.positionX.automationRate is equal to k-rate.
|
||||||
|
Pass Default AudioListener.positionY.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.positionY.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.positionY.automationRate is equal to k-rate.
|
||||||
|
Pass Default AudioListener.positionZ.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.positionZ.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.positionZ.automationRate is equal to k-rate.
|
||||||
|
Pass Default AudioListener.forwardX.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.forwardX.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.forwardX.automationRate is equal to k-rate.
|
||||||
|
Pass Default AudioListener.forwardY.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.forwardY.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.forwardY.automationRate is equal to k-rate.
|
||||||
|
Pass Default AudioListener.forwardZ.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.forwardZ.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.forwardZ.automationRate is equal to k-rate.
|
||||||
|
Pass Default AudioListener.upX.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.upX.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.upX.automationRate is equal to k-rate.
|
||||||
|
Pass Default AudioListener.upY.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.upY.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.upY.automationRate is equal to k-rate.
|
||||||
|
Pass Default AudioListener.upZ.automationRate is equal to a-rate.
|
||||||
|
Pass Set AudioListener.upZ.automationRate to "k-rate" did not throw an exception.
|
||||||
|
Pass AudioListener.upZ.automationRate is equal to k-rate.
|
||||||
|
Pass < [AudioListener] All assertions passed. (total 27 assertions)
|
||||||
|
Pass # AUDIT TASK RUNNER FINISHED: 10 tasks ran successfully.
|
|
@ -0,0 +1,167 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>AudioParam.automationRate tests</title>
|
||||||
|
<script src="../../../resources/testharness.js"></script>
|
||||||
|
<script src="../../../resources/testharnessreport.js"></script>
|
||||||
|
<script src="../../../webaudio/resources/audit-util.js"></script>
|
||||||
|
<script src="../../../webaudio/resources/audit.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
// For each node that has an AudioParam, verify that the default
|
||||||
|
// |automationRate| has the expected value and that we can change it or
|
||||||
|
// throw an error if it can't be changed.
|
||||||
|
|
||||||
|
// Any valid sample rate is fine; we don't actually render anything in the
|
||||||
|
// tests.
|
||||||
|
let sampleRate = 8000;
|
||||||
|
|
||||||
|
let audit = Audit.createTaskRunner();
|
||||||
|
|
||||||
|
// Array of tests. Each test is a dictonary consisting of the name of the
|
||||||
|
// node and an array specifying the AudioParam's of the node. This array
|
||||||
|
// in turn gives the name of the AudioParam, the default value for the
|
||||||
|
// |automationRate|, and whether it is fixed (isFixed).
|
||||||
|
const tests = [
|
||||||
|
{
|
||||||
|
nodeName: 'AudioBufferSourceNode',
|
||||||
|
audioParams: [
|
||||||
|
{name: 'detune', defaultRate: 'k-rate', isFixed: true},
|
||||||
|
{name: 'playbackRate', defaultRate: 'k-rate', isFixed: true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: 'BiquadFilterNode',
|
||||||
|
audioParams: [
|
||||||
|
{name: 'frequency', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'detune', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'Q', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'gain', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: 'ConstantSourceNode',
|
||||||
|
audioParams: [{name: 'offset', defaultRate: 'a-rate', isFixed: false}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: 'DelayNode',
|
||||||
|
audioParams:
|
||||||
|
[{name: 'delayTime', defaultRate: 'a-rate', isFixed: false}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: 'DynamicsCompressorNode',
|
||||||
|
audioParams: [
|
||||||
|
{name: 'threshold', defaultRate: 'k-rate', isFixed: true},
|
||||||
|
{name: 'knee', defaultRate: 'k-rate', isFixed: true},
|
||||||
|
{name: 'ratio', defaultRate: 'k-rate', isFixed: true},
|
||||||
|
{name: 'attack', defaultRate: 'k-rate', isFixed: true},
|
||||||
|
{name: 'release', defaultRate: 'k-rate', isFixed: true}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: 'GainNode',
|
||||||
|
audioParams: [{name: 'gain', defaultRate: 'a-rate', isFixed: false}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: 'OscillatorNode',
|
||||||
|
audioParams: [
|
||||||
|
{name: 'frequency', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'detune', defaultRate: 'a-rate', isFixed: false}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: 'PannerNode',
|
||||||
|
audioParams: [
|
||||||
|
{name: 'positionX', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'positionY', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'positionZ', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'orientationX', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'orientationY', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'orientationZ', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: 'StereoPannerNode',
|
||||||
|
audioParams: [{name: 'pan', defaultRate: 'a-rate', isFixed: false}]
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
tests.forEach(test => {
|
||||||
|
// Define a separate test for each test entry.
|
||||||
|
audit.define(test.nodeName, (task, should) => {
|
||||||
|
let context = new OfflineAudioContext(
|
||||||
|
{length: sampleRate, sampleRate: sampleRate});
|
||||||
|
// Construct the node and test each AudioParam of the node.
|
||||||
|
let node = new window[test.nodeName](context);
|
||||||
|
test.audioParams.forEach(param => {
|
||||||
|
testAudioParam(
|
||||||
|
should, {nodeName: test.nodeName, node: node, param: param});
|
||||||
|
});
|
||||||
|
|
||||||
|
task.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// AudioListener needs it's own special test since it's not a node.
|
||||||
|
audit.define('AudioListener', (task, should) => {
|
||||||
|
let context = new OfflineAudioContext(
|
||||||
|
{length: sampleRate, sampleRate: sampleRate});
|
||||||
|
|
||||||
|
[{name: 'positionX', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'positionY', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'positionZ', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'forwardX', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'forwardY', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'forwardZ', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'upX', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'upY', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
{name: 'upZ', defaultRate: 'a-rate', isFixed: false},
|
||||||
|
].forEach(param => {
|
||||||
|
testAudioParam(should, {
|
||||||
|
nodeName: 'AudioListener',
|
||||||
|
node: context.listener,
|
||||||
|
param: param
|
||||||
|
});
|
||||||
|
});
|
||||||
|
task.done();
|
||||||
|
});
|
||||||
|
|
||||||
|
audit.run();
|
||||||
|
|
||||||
|
function testAudioParam(should, options) {
|
||||||
|
let param = options.param;
|
||||||
|
let audioParam = options.node[param.name];
|
||||||
|
let defaultRate = param.defaultRate;
|
||||||
|
|
||||||
|
// Verify that the default value is correct.
|
||||||
|
should(
|
||||||
|
audioParam.automationRate,
|
||||||
|
`Default ${options.nodeName}.${param.name}.automationRate`)
|
||||||
|
.beEqualTo(defaultRate);
|
||||||
|
|
||||||
|
// Try setting the rate to a different rate. If the |automationRate|
|
||||||
|
// is fixed, expect an error. Otherwise, expect no error and expect
|
||||||
|
// the value is changed to the new value.
|
||||||
|
let newRate = defaultRate === 'a-rate' ? 'k-rate' : 'a-rate';
|
||||||
|
let setMessage = `Set ${
|
||||||
|
options.nodeName
|
||||||
|
}.${param.name}.automationRate to "${newRate}"`
|
||||||
|
|
||||||
|
if (param.isFixed) {
|
||||||
|
should(() => audioParam.automationRate = newRate, setMessage)
|
||||||
|
.throw(DOMException, 'InvalidStateError');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
should(() => audioParam.automationRate = newRate, setMessage)
|
||||||
|
.notThrow();
|
||||||
|
should(
|
||||||
|
audioParam.automationRate,
|
||||||
|
`${options.nodeName}.${param.name}.automationRate`)
|
||||||
|
.beEqualTo(newRate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue