StereoPannerNode DOM

This commit is contained in:
Maria Sable 2019-04-27 10:02:14 -04:00 committed by Manish Goregaokar
parent 549d320167
commit 58f027468c
12 changed files with 173 additions and 109 deletions

View file

@ -10,7 +10,9 @@ use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
ChannelCountMode, ChannelInterpretation,
};
use crate::dom::bindings::codegen::InheritTypes::{AudioNodeTypeId, EventTargetTypeId};
use crate::dom::bindings::codegen::InheritTypes::{
AudioNodeTypeId, AudioScheduledSourceNodeTypeId, EventTargetTypeId,
};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{Dom, DomRoot};
@ -236,6 +238,13 @@ impl AudioNodeMethods for AudioNode {
return Err(Error::NotSupported);
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::AudioScheduledSourceNode(
AudioScheduledSourceNodeTypeId::StereoPannerNode,
)) => {
if value > 2 {
return Err(Error::NotSupported);
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelMergerNode) => {
return Err(Error::InvalidState);
},
@ -280,6 +289,13 @@ impl AudioNodeMethods for AudioNode {
return Err(Error::NotSupported);
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::AudioScheduledSourceNode(
AudioScheduledSourceNodeTypeId::StereoPannerNode,
)) => {
if value == ChannelCountMode::Max {
return Err(Error::NotSupported);
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelMergerNode) => {
return Err(Error::InvalidState);
},

View file

@ -27,6 +27,7 @@ use crate::dom::bindings::codegen::Bindings::ChannelSplitterNodeBinding::Channel
use crate::dom::bindings::codegen::Bindings::GainNodeBinding::GainOptions;
use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorOptions;
use crate::dom::bindings::codegen::Bindings::PannerNodeBinding::PannerOptions;
use crate::dom::bindings::codegen::Bindings::StereoPannerNodeBinding::StereoPannerOptions;
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
@ -42,6 +43,7 @@ use crate::dom::gainnode::GainNode;
use crate::dom::oscillatornode::OscillatorNode;
use crate::dom::pannernode::PannerNode;
use crate::dom::promise::Promise;
use crate::dom::stereopannernode::StereoPannerNode;
use crate::dom::window::Window;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
@ -361,6 +363,15 @@ impl BaseAudioContextMethods for BaseAudioContext {
)
}
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createstereopanner
fn CreateStereoPanner(&self) -> Fallible<DomRoot<StereoPannerNode>> {
StereoPannerNode::new(
&self.global().as_window(),
&self,
&StereoPannerOptions::empty(),
)
}
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelmerger
fn CreateChannelMerger(&self, count: u32) -> Fallible<DomRoot<ChannelMergerNode>> {
let mut opts = ChannelMergerOptions::empty();

View file

@ -457,6 +457,7 @@ pub mod serviceworkerglobalscope;
pub mod serviceworkerregistration;
pub mod servoparser;
pub mod shadowroot;
pub mod stereopannernode;
pub mod storage;
pub mod storageevent;
pub mod stylepropertymapreadonly;

View file

@ -0,0 +1,106 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::audioparam::AudioParam;
use crate::dom::audioscheduledsourcenode::AudioScheduledSourceNode;
use crate::dom::baseaudiocontext::BaseAudioContext;
use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
ChannelCountMode, ChannelInterpretation,
};
use crate::dom::bindings::codegen::Bindings::AudioParamBinding::AutomationRate;
use crate::dom::bindings::codegen::Bindings::StereoPannerNodeBinding::StereoPannerNodeMethods;
use crate::dom::bindings::codegen::Bindings::StereoPannerNodeBinding::{self, StereoPannerOptions};
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::window::Window;
use dom_struct::dom_struct;
use servo_media::audio::node::AudioNodeInit;
use servo_media::audio::param::ParamType;
use servo_media::audio::stereo_panner::StereoPannerOptions as ServoMediaStereoPannerOptions;
#[dom_struct]
pub struct StereoPannerNode {
source_node: AudioScheduledSourceNode,
pan: Dom<AudioParam>,
}
impl StereoPannerNode {
#[allow(unrooted_must_root)]
pub fn new_inherited(
window: &Window,
context: &BaseAudioContext,
options: &StereoPannerOptions,
) -> Fallible<StereoPannerNode> {
let node_options = options.parent.unwrap_or(
2,
ChannelCountMode::Clamped_max,
ChannelInterpretation::Speakers,
);
if node_options.mode == ChannelCountMode::Max {
return Err(Error::NotSupported);
}
if node_options.count > 2 || node_options.count == 0 {
return Err(Error::NotSupported);
}
let source_node = AudioScheduledSourceNode::new_inherited(
AudioNodeInit::StereoPannerNode(options.into()),
context,
node_options,
1, /* inputs */
1, /* outputs */
)?;
let node_id = source_node.node().node_id();
let pan = AudioParam::new(
window,
context,
node_id,
ParamType::Pan,
AutomationRate::A_rate,
*options.pan,
-1.,
1.,
);
Ok(StereoPannerNode {
source_node,
pan: Dom::from_ref(&pan),
})
}
#[allow(unrooted_must_root)]
pub fn new(
window: &Window,
context: &BaseAudioContext,
options: &StereoPannerOptions,
) -> Fallible<DomRoot<StereoPannerNode>> {
let node = StereoPannerNode::new_inherited(window, context, options)?;
Ok(reflect_dom_object(
Box::new(node),
window,
StereoPannerNodeBinding::Wrap,
))
}
pub fn Constructor(
window: &Window,
context: &BaseAudioContext,
options: &StereoPannerOptions,
) -> Fallible<DomRoot<StereoPannerNode>> {
StereoPannerNode::new(window, context, options)
}
}
impl StereoPannerNodeMethods for StereoPannerNode {
// https://webaudio.github.io/web-audio-api/#dom-stereopannernode-pan
fn Pan(&self) -> DomRoot<AudioParam> {
DomRoot::from_ref(&self.pan)
}
}
impl<'a> From<&'a StereoPannerOptions> for ServoMediaStereoPannerOptions {
fn from(options: &'a StereoPannerOptions) -> Self {
Self { pan: *options.pan }
}
}

View file

@ -43,7 +43,7 @@ interface BaseAudioContext : EventTarget {
// sequence<double> feedback);
// WaveShaperNode createWaveShaper();
[Throws] PannerNode createPanner();
// StereoPannerNode createStereoPanner();
[Throws] StereoPannerNode createStereoPanner();
// ConvolverNode createConvolver();
[Throws] ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
[Throws] ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs = 6);

View file

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is
* https://webaudio.github.io/web-audio-api/#StereoPannerNode
*/
dictionary StereoPannerOptions: AudioNodeOptions {
float pan = 0;
};
[Exposed=Window,
Constructor (BaseAudioContext context, optional StereoPannerOptions options)]
interface StereoPannerNode : AudioScheduledSourceNode {
readonly attribute AudioParam pan;
};

View file

@ -2,9 +2,6 @@
[AudioNode interface: calling connect(AudioNode, unsigned long, unsigned long) on new ConvolverNode(context) with too few arguments must throw TypeError]
expected: FAIL
[StereoPannerNode interface: attribute pan]
expected: FAIL
[AudioNode interface: new MediaElementAudioSourceNode(context, {mediaElement: new Audio}) must inherit property "disconnect(AudioParam)" with the proper type]
expected: FAIL
@ -80,9 +77,6 @@
[AudioNode interface: calling disconnect(AudioNode, unsigned long) on new ConstantSourceNode(context) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "connect(AudioNode, unsigned long, unsigned long)" with the proper type]
expected: FAIL
[AudioNode interface: new ConstantSourceNode(context) must inherit property "numberOfInputs" with the proper type]
expected: FAIL
@ -113,9 +107,6 @@
[ConstantSourceNode interface object length]
expected: FAIL
[Stringification of new StereoPannerNode(context)]
expected: FAIL
[AudioContext interface: operation close()]
expected: FAIL
@ -194,18 +185,12 @@
[AudioNode interface: context.createScriptProcessor() must inherit property "disconnect(unsigned long)" with the proper type]
expected: FAIL
[AudioNode interface: calling disconnect(AudioNode) on new StereoPannerNode(context) with too few arguments must throw TypeError]
expected: FAIL
[Stringification of worklet_node]
expected: FAIL
[AudioNode interface: context.createScriptProcessor() must inherit property "connect(AudioNode, unsigned long, unsigned long)" with the proper type]
expected: FAIL
[StereoPannerNode interface: new StereoPannerNode(context) must inherit property "pan" with the proper type]
expected: FAIL
[MediaStreamAudioSourceNode interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
@ -215,9 +200,6 @@
[AudioNode interface: new IIRFilterNode(context, {feedforward: [1\], feedback: [1\]}) must inherit property "disconnect()" with the proper type]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "disconnect(AudioParam)" with the proper type]
expected: FAIL
[BaseAudioContext interface: new OfflineAudioContext(1, 1, sample_rate) must inherit property "createDelay(double)" with the proper type]
expected: FAIL
@ -248,18 +230,12 @@
[AudioNode interface: calling disconnect(AudioNode, unsigned long) on new IIRFilterNode(context, {feedforward: [1\], feedback: [1\]}) with too few arguments must throw TypeError]
expected: FAIL
[BaseAudioContext interface: new OfflineAudioContext(1, 1, sample_rate) must inherit property "createStereoPanner()" with the proper type]
expected: FAIL
[ScriptProcessorNode interface: existence and properties of interface prototype object]
expected: FAIL
[AudioContext interface: calling createMediaElementSource(HTMLMediaElement) on context with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: calling disconnect(AudioNode, unsigned long, unsigned long) on new StereoPannerNode(context) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: calling connect(AudioNode, unsigned long, unsigned long) on new DynamicsCompressorNode(context) with too few arguments must throw TypeError]
expected: FAIL
@ -299,9 +275,6 @@
[AudioNode interface: calling connect(AudioParam, unsigned long) on new DelayNode(context) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "disconnect(AudioNode)" with the proper type]
expected: FAIL
[AudioNode interface: new IIRFilterNode(context, {feedforward: [1\], feedback: [1\]}) must inherit property "connect(AudioNode, unsigned long, unsigned long)" with the proper type]
expected: FAIL
@ -377,9 +350,6 @@
[AudioNode interface: calling disconnect(AudioParam) on new MediaElementAudioSourceNode(context, {mediaElement: new Audio}) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "numberOfOutputs" with the proper type]
expected: FAIL
[AudioWorklet interface object name]
expected: FAIL
@ -416,9 +386,6 @@
[AudioNode interface: new MediaElementAudioSourceNode(context, {mediaElement: new Audio}) must inherit property "disconnect()" with the proper type]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "disconnect(AudioNode, unsigned long, unsigned long)" with the proper type]
expected: FAIL
[MediaStreamAudioSourceNode interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
@ -464,18 +431,12 @@
[PeriodicWave interface: existence and properties of interface object]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "context" with the proper type]
expected: FAIL
[AudioNode interface: new ConstantSourceNode(context) must inherit property "context" with the proper type]
expected: FAIL
[AudioNode interface: calling disconnect(AudioParam) on new DynamicsCompressorNode(context) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "channelCountMode" with the proper type]
expected: FAIL
[AudioNode interface: calling disconnect(AudioNode) on new DynamicsCompressorNode(context) with too few arguments must throw TypeError]
expected: FAIL
@ -494,15 +455,9 @@
[AudioNode interface: calling disconnect(AudioParam) on new ConstantSourceNode(context) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "channelInterpretation" with the proper type]
expected: FAIL
[AudioProcessingEvent interface: attribute inputBuffer]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "connect(AudioParam, unsigned long)" with the proper type]
expected: FAIL
[AudioParamMap interface object length]
expected: FAIL
@ -518,9 +473,6 @@
[BaseAudioContext interface: attribute audioWorklet]
expected: FAIL
[AudioNode interface: calling connect(AudioNode, unsigned long, unsigned long) on new StereoPannerNode(context) with too few arguments must throw TypeError]
expected: FAIL
[BaseAudioContext interface: operation createWaveShaper()]
expected: FAIL
@ -539,9 +491,6 @@
[AudioNode interface: new ConvolverNode(context) must inherit property "disconnect()" with the proper type]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "disconnect()" with the proper type]
expected: FAIL
[Stringification of new PeriodicWave(context)]
expected: FAIL
@ -734,9 +683,6 @@
[MediaStreamAudioDestinationNode interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[StereoPannerNode interface object name]
expected: FAIL
[AudioNode interface: new MediaElementAudioSourceNode(context, {mediaElement: new Audio}) must inherit property "channelInterpretation" with the proper type]
expected: FAIL
@ -848,9 +794,6 @@
[AudioNode interface: new WaveShaperNode(context) must inherit property "channelCount" with the proper type]
expected: FAIL
[StereoPannerNode interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[DynamicsCompressorNode interface: attribute release]
expected: FAIL
@ -881,9 +824,6 @@
[AudioNode interface: new MediaElementAudioSourceNode(context, {mediaElement: new Audio}) must inherit property "disconnect(AudioParam, unsigned long)" with the proper type]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "disconnect(unsigned long)" with the proper type]
expected: FAIL
[AudioNode interface: calling disconnect(AudioParam, unsigned long) on new WaveShaperNode(context) with too few arguments must throw TypeError]
expected: FAIL
@ -893,12 +833,6 @@
[AudioProcessingEvent interface: attribute playbackTime]
expected: FAIL
[AudioNode interface: calling connect(AudioParam, unsigned long) on new StereoPannerNode(context) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: calling disconnect(unsigned long) on new StereoPannerNode(context) with too few arguments must throw TypeError]
expected: FAIL
[BaseAudioContext interface: new OfflineAudioContext(1, 1, sample_rate) must inherit property "createConvolver()" with the proper type]
expected: FAIL
@ -929,9 +863,6 @@
[AudioNode interface: new DelayNode(context) must inherit property "disconnect(AudioParam)" with the proper type]
expected: FAIL
[AudioNode interface: calling disconnect(AudioParam, unsigned long) on new StereoPannerNode(context) with too few arguments must throw TypeError]
expected: FAIL
[OfflineAudioContext interface: calling suspend(double) on new OfflineAudioContext(1, 1, sample_rate) with too few arguments must throw TypeError]
expected: FAIL
@ -947,9 +878,6 @@
[AudioNode interface: calling disconnect(AudioNode, unsigned long) on new MediaStreamAudioDestinationNode(context) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "disconnect(AudioNode, unsigned long)" with the proper type]
expected: FAIL
[MediaElementAudioSourceNode must be primary interface of new MediaElementAudioSourceNode(context, {mediaElement: new Audio})]
expected: FAIL
@ -1025,9 +953,6 @@
[OscillatorNode interface: calling setPeriodicWave(PeriodicWave) on new OscillatorNode(context) with too few arguments must throw TypeError]
expected: FAIL
[BaseAudioContext interface: context must inherit property "createStereoPanner()" with the proper type]
expected: FAIL
[MediaElementAudioSourceNode interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
@ -1073,18 +998,12 @@
[AudioNode interface: new ConvolverNode(context) must inherit property "disconnect(AudioParam)" with the proper type]
expected: FAIL
[StereoPannerNode must be primary interface of new StereoPannerNode(context)]
expected: FAIL
[AudioNode interface: new MediaElementAudioSourceNode(context, {mediaElement: new Audio}) must inherit property "numberOfOutputs" with the proper type]
expected: FAIL
[DynamicsCompressorNode interface: attribute attack]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "numberOfInputs" with the proper type]
expected: FAIL
[AudioContext interface: calling createMediaStreamTrackSource(MediaStreamTrack) on context with too few arguments must throw TypeError]
expected: FAIL
@ -1103,9 +1022,6 @@
[AudioNode interface: calling disconnect(AudioParam) on new WaveShaperNode(context) with too few arguments must throw TypeError]
expected: FAIL
[StereoPannerNode interface object length]
expected: FAIL
[AudioContext interface: operation createMediaStreamDestination()]
expected: FAIL
@ -1142,9 +1058,6 @@
[AudioNode interface: new ConstantSourceNode(context) must inherit property "disconnect(AudioParam)" with the proper type]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "disconnect(AudioParam, unsigned long)" with the proper type]
expected: FAIL
[AudioNode interface: new MediaStreamAudioDestinationNode(context) must inherit property "channelInterpretation" with the proper type]
expected: FAIL
@ -1319,9 +1232,6 @@
[IIRFilterNode interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
[AudioNode interface: calling disconnect(AudioParam) on new StereoPannerNode(context) with too few arguments must throw TypeError]
expected: FAIL
[AudioNode interface: new MediaStreamAudioDestinationNode(context) must inherit property "connect(AudioParam, unsigned long)" with the proper type]
expected: FAIL
@ -1343,12 +1253,6 @@
[Stringification of new DynamicsCompressorNode(context)]
expected: FAIL
[StereoPannerNode interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
[AudioNode interface: calling disconnect(AudioNode, unsigned long) on new StereoPannerNode(context) with too few arguments must throw TypeError]
expected: FAIL
[BaseAudioContext interface: context must inherit property "createWaveShaper()" with the proper type]
expected: FAIL
@ -1358,9 +1262,6 @@
[AudioNode interface: new IIRFilterNode(context, {feedforward: [1\], feedback: [1\]}) must inherit property "channelInterpretation" with the proper type]
expected: FAIL
[BaseAudioContext interface: operation createStereoPanner()]
expected: FAIL
[AudioWorkletNode interface object length]
expected: FAIL
@ -1373,9 +1274,6 @@
[BaseAudioContext interface: new OfflineAudioContext(1, 1, sample_rate) must inherit property "createWaveShaper()" with the proper type]
expected: FAIL
[AudioNode interface: new StereoPannerNode(context) must inherit property "channelCount" with the proper type]
expected: FAIL
[AudioNode interface: new MediaStreamAudioDestinationNode(context) must inherit property "disconnect(AudioNode, unsigned long)" with the proper type]
expected: FAIL

View file

@ -1,5 +1,4 @@
[ctor-stereopanner.html]
expected: ERROR
[X node0 = new StereoPannerNode(context) incorrectly threw TypeError: "window[name\] is not a constructor".]
expected: FAIL

View file

@ -1,2 +0,0 @@
[stereopannernode-basic.html]
expected: ERROR

View file

@ -1,2 +1,19 @@
[stereopannernode-panning.html]
expected: ERROR
[# AUDIT TASK RUNNER FINISHED: 2 out of 2 tasks were failed.]
expected: FAIL
[< [mono-test\] 1 out of 4 assertions were failed.]
expected: FAIL
[< [stereo-test\] 2 out of 4 assertions were failed.]
expected: FAIL
[X Stereo: Right channel error magnitude is not less than or equal to 9.8015e-8. Got 1.0266453775997775e-7.]
expected: FAIL
[X Mono: Left channel error magnitude is not less than or equal to 9.8015e-8. Got 1.3439545697158106e-7.]
expected: FAIL
[X Stereo: Left channel error magnitude is not less than or equal to 9.8015e-8. Got 1.4099019063351648e-7.]
expected: FAIL

View file

@ -20306,7 +20306,7 @@
"testharness"
],
"mozilla/interfaces.html": [
"c7e1929c626007e2ef3cdf9f2276620aa995c5b7",
"2effd46f565c4787e8632f5e898e1b43d457672f",
"testharness"
],
"mozilla/interfaces.js": [

View file

@ -203,6 +203,7 @@ test_interfaces([
"Response",
"Screen",
"ShadowRoot",
"StereoPannerNode",
"Storage",
"StorageEvent",
"StyleSheet",