Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant source node DOM #23152

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -21,6 +21,7 @@ use crate::dom::bindings::codegen::Bindings::BaseAudioContextBinding::BaseAudioC
use crate::dom::bindings::codegen::Bindings::BaseAudioContextBinding::DecodeErrorCallback;
use crate::dom::bindings::codegen::Bindings::BaseAudioContextBinding::DecodeSuccessCallback;
use crate::dom::bindings::codegen::Bindings::BiquadFilterNodeBinding::BiquadFilterOptions;
use crate::dom::bindings::codegen::Bindings::ConstantSourceNodeBinding::ConstantSourceOptions;
use crate::dom::bindings::codegen::Bindings::ChannelMergerNodeBinding::ChannelMergerOptions;
use crate::dom::bindings::codegen::Bindings::ChannelSplitterNodeBinding::ChannelSplitterOptions;
use crate::dom::bindings::codegen::Bindings::GainNodeBinding::GainOptions;
@@ -35,6 +36,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::biquadfilternode::BiquadFilterNode;
use crate::dom::channelmergernode::ChannelMergerNode;
use crate::dom::channelsplitternode::ChannelSplitterNode;
use crate::dom::constantsourcenode::ConstantSourceNode;
use crate::dom::domexception::{DOMErrorName, DOMException};
use crate::dom::eventtarget::EventTarget;
use crate::dom::gainnode::GainNode;
@@ -355,6 +357,15 @@ impl BaseAudioContextMethods for BaseAudioContext {
)
}

/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createconstantsource
fn CreateConstantSource(&self) -> Fallible<DomRoot<ConstantSourceNode>> {
ConstantSourceNode::new(
&self.global().as_window(),
&self,
&ConstantSourceOptions::empty(),
)
}

/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelmerger
fn CreateChannelMerger(&self, count: u32) -> Fallible<DomRoot<ChannelMergerNode>> {
let mut opts = ChannelMergerOptions::empty();
@@ -0,0 +1,103 @@
/* 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::ConstantSourceNodeBinding::ConstantSourceNodeMethods;
use crate::dom::bindings::codegen::Bindings::ConstantSourceNodeBinding::{
self, ConstantSourceOptions,
};
use crate::dom::bindings::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::constant_source_node::ConstantSourceNodeOptions as ServoMediaConstantSourceOptions;
use servo_media::audio::node::AudioNodeInit;
use servo_media::audio::param::ParamType;
use std::f32;

#[dom_struct]
pub struct ConstantSourceNode {
source_node: AudioScheduledSourceNode,
offset: Dom<AudioParam>,
}

impl ConstantSourceNode {
#[allow(unrooted_must_root)]
pub fn new_inherited(
window: &Window,
context: &BaseAudioContext,
options: &ConstantSourceOptions,
) -> Fallible<ConstantSourceNode> {
let node_options =
options
.parent
.unwrap_or(2, ChannelCountMode::Max, ChannelInterpretation::Speakers);
let source_node = AudioScheduledSourceNode::new_inherited(
AudioNodeInit::ConstantSourceNode(options.into()),
context,
node_options,
0, /* inputs */
1, /* outputs */
)?;
let node_id = source_node.node().node_id();
let offset = AudioParam::new(
window,
context,
node_id,
ParamType::Offset,
AutomationRate::A_rate,
1.,

This comment has been minimized.

Copy link
@Manishearth

Manishearth Apr 2, 2019

Member

You should use options.offset here.

f32::MIN,
f32::MAX,
);

Ok(ConstantSourceNode {
source_node,
offset: Dom::from_ref(&offset),
})
}

#[allow(unrooted_must_root)]
pub fn new(
window: &Window,
context: &BaseAudioContext,
options: &ConstantSourceOptions,
) -> Fallible<DomRoot<ConstantSourceNode>> {
let node = ConstantSourceNode::new_inherited(window, context, options)?;
Ok(reflect_dom_object(
Box::new(node),
window,
ConstantSourceNodeBinding::Wrap,
))
}

pub fn Constructor(
window: &Window,
context: &BaseAudioContext,
options: &ConstantSourceOptions,
) -> Fallible<DomRoot<ConstantSourceNode>> {
ConstantSourceNode::new(window, context, options)
}
}

impl ConstantSourceNodeMethods for ConstantSourceNode {
fn Offset(&self) -> DomRoot<AudioParam> {
DomRoot::from_ref(&self.offset)
}
}

impl<'a> From<&'a ConstantSourceOptions> for ServoMediaConstantSourceOptions {
fn from(options: &'a ConstantSourceOptions) -> Self {
Self {
offset: *options.offset,
}
}
}
@@ -254,6 +254,7 @@ pub mod closeevent;
pub mod comment;
pub mod compositionevent;
pub mod console;
pub mod constantsourcenode;
mod create;
pub mod crypto;
pub mod css;
@@ -31,7 +31,7 @@ interface BaseAudioContext : EventTarget {
optional DecodeSuccessCallback successCallback,
optional DecodeErrorCallback errorCallback);
[Throws] AudioBufferSourceNode createBufferSource();
// ConstantSourceNode createConstantSource();
[Throws] ConstantSourceNode createConstantSource();
// ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0,
// optional unsigned long numberOfInputChannels = 2,
// optional unsigned long numberOfOutputChannels = 2);
@@ -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/#ConstantSourceNode
*/

dictionary ConstantSourceOptions: AudioNodeOptions {
float offset = 1;
};

[Exposed=Window,
Constructor (BaseAudioContext context, optional ConstantSourceOptions options)]
interface ConstantSourceNode : AudioScheduledSourceNode {
readonly attribute AudioParam offset;
};
@@ -1,5 +1,4 @@
[constant-source-basic.html]
expected: ERROR
[X Factory method: node = context.createConstantSource() incorrectly threw TypeError: "context.createConstantSource is not a function".]
expected: FAIL

@@ -1,2 +1,22 @@
[constant-source-output.html]
expected: ERROR
[X Connected param: ConstantSourceNode frames [10, 6000) does not equal [1.5446391105651855,1.5920131206512451,1.6374239921569824,1.6807208061218262,1.7217602729797363,1.7604060173034668,1.7965298891067505,1.830012321472168,1.8607419729232788,1.8886172771453857,1.9135454893112183,1.9354441165924072,1.954240322113037,1.969871997833252,1.9822871685028076,1.9914448261260986...\] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.\n\tIndex\tActual\t\t\tExpected\t\tAbsError\t\tRelError\t\tTest threshold\n\t[119\]\t1.9689673185348511e+0\t1.9114032983779907e+0\t5.7564020156860352e-2\t3.0116103810069256e-2\t0.0000000000000000e+0\n\t[120\]\t2.0485177040100098e+0\t1.9335803985595703e+0\t1.1493730545043945e-1\t5.9442734078222211e-2\t0.0000000000000000e+0\n\t[121\]\t2.1245903968811035e+0\t1.9526615142822266e+0\t1.7192888259887695e-1\t8.8048482208180262e-2\t0.0000000000000000e+0\n\t[122\]\t2.1969339847564697e+0\t1.9685831069946289e+0\t2.2835087776184082e-1\t1.1599758067133706e-1\t0.0000000000000000e+0\n\t[123\]\t2.2653079032897949e+0\t1.9812927246093750e+0\t2.8401517868041992e-1\t1.4334841851115937e-1\t0.0000000000000000e+0\n\t...and 122 more errors.\n\tMax AbsError of 9.9994510412216187e-1 at index of 200.\n\t[200\]\t-4.5393562316894531e-1\t5.4600948095321655e-1\t9.9994510412216187e-1\t1.8313694889994769e+0\t0.0000000000000000e+0\n\tMax RelError of 3.4132869565217392e+4 at index of 181.\n\t[181\]\t-4.6791613101959229e-1\t1.3709068298339844e-5\t4.6792984008789063e-1\t3.4132869565217392e+4\t0.0000000000000000e+0\n]
expected: FAIL

[< [connected audioparam\] 1 out of 2 assertions were failed.]
expected: FAIL

[< [basic automation\] 1 out of 2 assertions were failed.]
expected: FAIL

[X Automation: ConstantSourceNode.linearRamp(1, 0.5) does not equal [0.5,0.5001666666666666,0.5003333333333333,0.5005,0.5006666666666667,0.5008333333333334,0.501,0.5011666666666666,0.5013333333333333,0.5015,0.5016666666666667,0.5018333333333334,0.502,0.5021666666666667,0.5023333333333333,0.5025...\] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":7.161e-7}.\n\tIndex\tActual\t\t\tExpected\t\tAbsError\t\tRelError\t\tTest threshold\n\t[1\]\t5.0000000000000000e-1\t5.0016666666666665e-1\t1.6666666666664831e-4\t3.3322225924688100e-4\t3.5816935000000001e-7\n\t[2\]\t5.0016671419143677e-1\t5.0033333333333330e-1\t1.6661914189652904e-4\t3.3301627294442850e-4\t3.5828869999999996e-7\n\t[3\]\t5.0033342838287354e-1\t5.0049999999999994e-1\t1.6657161712640978e-4\t3.3281042382899057e-4\t3.5840804999999996e-7\n\t[4\]\t5.0050014257431030e-1\t5.0066666666666670e-1\t1.6652409235640153e-4\t3.3260471176378465e-4\t3.5852740000000001e-7\n\t[5\]\t5.0066691637039185e-1\t5.0083333333333335e-1\t1.6641696294150687e-4\t3.3228012567355778e-4\t3.5864675000000001e-7\n\t...and 2982 more errors.\n\tMax AbsError of 1.6666666666664831e-4 at index of 1.\n\tMax RelError of 3.3322225924688100e-4 at index of 1.\n]
expected: FAIL

[X start/stop: ConstantSourceNode frames [300, 6000): Expected 0 for all values but found 1 unexpected values: \n\tIndex\tActual\n\t[0\]\t1]
expected: FAIL

[< [start/stop\] 1 out of 3 assertions were failed.]
expected: FAIL

[# AUDIT TASK RUNNER FINISHED: 3 out of 6 tasks were failed.]
expected: FAIL

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

@@ -1,19 +1,4 @@
[test-constantsourcenode.html]
[ConstantSourceNode with no automation]
expected: FAIL

[ConstantSourceNode stop and start]
expected: FAIL

[ConstantSourceNode onended event]
expected: FAIL

[ConstantSourceNode can be constructed]
expected: FAIL

[ConstantSourceNode with automation]
expected: FAIL

[ConstantSourceNode start and stop when work]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.