mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Initial WebAudio API stubs
This commit is contained in:
parent
de48f25d0b
commit
7ee42e4223
17 changed files with 863 additions and 0 deletions
81
components/script/dom/audiocontext.rs
Normal file
81
components/script/dom/audiocontext.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::baseaudiocontext::BaseAudioContext;
|
||||
use dom::bindings::codegen::Bindings::AudioContextBinding;
|
||||
use dom::bindings::codegen::Bindings::AudioContextBinding::AudioContextMethods;
|
||||
use dom::bindings::codegen::Bindings::AudioContextBinding::{AudioContextOptions, AudioTimestamp};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom::promise::Promise;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct AudioContext {
|
||||
context: BaseAudioContext,
|
||||
base_latency: f64,
|
||||
output_latency: f64,
|
||||
}
|
||||
|
||||
impl AudioContext {
|
||||
fn new_inherited(global: &GlobalScope, sample_rate: f32) -> AudioContext {
|
||||
AudioContext {
|
||||
context: BaseAudioContext::new_inherited(global, 2 /* channel_count */, sample_rate),
|
||||
base_latency: 0., // TODO
|
||||
output_latency: 0., // TODO
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(global: &GlobalScope,
|
||||
options: &AudioContextOptions) -> DomRoot<AudioContext> {
|
||||
let context = AudioContext::new_inherited(
|
||||
global,
|
||||
*options.sampleRate.unwrap_or(Finite::wrap(0.)),
|
||||
); // TODO
|
||||
reflect_dom_object(Box::new(context), global, AudioContextBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn Constructor(window: &Window,
|
||||
options: &AudioContextOptions) -> Fallible<DomRoot<AudioContext>> {
|
||||
let global = window.upcast::<GlobalScope>();
|
||||
Ok(AudioContext::new(global, options))
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioContextMethods for AudioContext {
|
||||
fn BaseLatency(&self) -> Finite<f64> {
|
||||
Finite::wrap(self.base_latency)
|
||||
}
|
||||
|
||||
fn OutputLatency(&self) -> Finite<f64> {
|
||||
Finite::wrap(self.output_latency)
|
||||
}
|
||||
|
||||
fn GetOutputTimestamp(&self) -> AudioTimestamp {
|
||||
// TODO
|
||||
AudioTimestamp {
|
||||
contextTime: Some(Finite::wrap(0.)),
|
||||
performanceTime: Some(Finite::wrap(0.)),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
fn Suspend(&self) -> Rc<Promise> {
|
||||
// TODO
|
||||
Promise::new(&self.global())
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
fn Close(&self) -> Rc<Promise> {
|
||||
// TODO
|
||||
Promise::new(&self.global())
|
||||
}
|
||||
}
|
41
components/script/dom/audiodestinationnode.rs
Normal file
41
components/script/dom/audiodestinationnode.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::audionode::{AudioNode, MAX_CHANNEL_COUNT};
|
||||
use dom::baseaudiocontext::BaseAudioContext;
|
||||
use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding;
|
||||
use dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::AudioDestinationNodeMethods;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom_struct::dom_struct;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct AudioDestinationNode {
|
||||
node: AudioNode,
|
||||
}
|
||||
|
||||
impl AudioDestinationNode {
|
||||
fn new_inherited(context: &BaseAudioContext,
|
||||
options: &AudioNodeOptions) -> AudioDestinationNode {
|
||||
AudioDestinationNode {
|
||||
node: AudioNode::new_inherited(context, options, 1, 1),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(global: &GlobalScope,
|
||||
context: &BaseAudioContext,
|
||||
options: &AudioNodeOptions) -> DomRoot<AudioDestinationNode> {
|
||||
let node = AudioDestinationNode::new_inherited(context, options);
|
||||
reflect_dom_object(Box::new(node), global, AudioDestinationNodeBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioDestinationNodeMethods for AudioDestinationNode {
|
||||
fn MaxChannelCount(&self) -> u32 {
|
||||
MAX_CHANNEL_COUNT
|
||||
}
|
||||
}
|
166
components/script/dom/audionode.rs
Normal file
166
components/script/dom/audionode.rs
Normal file
|
@ -0,0 +1,166 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::baseaudiocontext::BaseAudioContext;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{AudioNodeMethods, AudioNodeOptions};
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::audioparam::AudioParam;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom_struct::dom_struct;
|
||||
use std::cell::Cell;
|
||||
|
||||
// 32 is the minimum required by the spec for createBuffer() and
|
||||
// createScriptProcessor() and matches what is used by Blink and Gecko.
|
||||
// The limit protects against large memory allocations.
|
||||
pub static MAX_CHANNEL_COUNT: u32 = 32;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct AudioNode {
|
||||
reflector_: Reflector,
|
||||
context: DomRoot<BaseAudioContext>,
|
||||
number_of_inputs: u32,
|
||||
number_of_outputs: u32,
|
||||
channel_count: Cell<u32>,
|
||||
channel_count_mode: Cell<ChannelCountMode>,
|
||||
channel_interpretation: Cell<ChannelInterpretation>,
|
||||
}
|
||||
|
||||
impl AudioNode {
|
||||
pub fn new_inherited(context: &BaseAudioContext,
|
||||
options: &AudioNodeOptions,
|
||||
number_of_inputs: u32,
|
||||
number_of_outputs: u32) -> AudioNode {
|
||||
AudioNode {
|
||||
reflector_: Reflector::new(),
|
||||
context: DomRoot::from_ref(context),
|
||||
number_of_inputs,
|
||||
number_of_outputs,
|
||||
channel_count: Cell::new(options.channelCount.unwrap_or(2)),
|
||||
channel_count_mode: Cell::new(options.channelCountMode.unwrap_or_default()),
|
||||
channel_interpretation: Cell::new(options.channelInterpretation.unwrap_or_default()),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(global: &GlobalScope,
|
||||
context: &BaseAudioContext,
|
||||
options: &AudioNodeOptions) -> DomRoot<AudioNode> {
|
||||
let audio_node = AudioNode::new_inherited(context, options, 1, 1);
|
||||
reflect_dom_object(Box::new(audio_node), global, AudioNodeBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioNodeMethods for AudioNode {
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect
|
||||
fn Connect(&self,
|
||||
_destinationNode: &AudioNode,
|
||||
_output: u32,
|
||||
_input: u32) -> Fallible<DomRoot<AudioNode>> {
|
||||
// TODO
|
||||
let options = AudioNodeOptions {
|
||||
channelCount: Some(self.channel_count.get()),
|
||||
channelCountMode: Some(self.channel_count_mode.get()),
|
||||
channelInterpretation: Some(self.channel_interpretation.get()),
|
||||
};
|
||||
Ok(AudioNode::new(&self.global(), &self.context, &options))
|
||||
}
|
||||
|
||||
fn Connect_(&self,
|
||||
_: &AudioParam,
|
||||
_: u32) -> Fallible<()> {
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
|
||||
fn Disconnect(&self) -> ErrorResult {
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
|
||||
fn Disconnect_(&self, _: u32) -> ErrorResult {
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
|
||||
fn Disconnect__(&self, _: &AudioNode) -> ErrorResult {
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
|
||||
fn Disconnect___(&self, _: &AudioNode, _: u32) -> ErrorResult{
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
|
||||
fn Disconnect____(&self, _: &AudioNode, _: u32, _: u32) -> ErrorResult {
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
|
||||
fn Disconnect_____(&self, _: &AudioParam) -> ErrorResult {
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
|
||||
fn Disconnect______(&self, _: &AudioParam, _: u32) -> ErrorResult {
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-context
|
||||
fn Context(&self) -> DomRoot<BaseAudioContext> {
|
||||
DomRoot::from_ref(&self.context)
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-numberofinputs
|
||||
fn NumberOfInputs(&self) -> u32 {
|
||||
self.number_of_inputs
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-numberofoutputs
|
||||
fn NumberOfOutputs(&self) -> u32 {
|
||||
self.number_of_outputs
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount
|
||||
fn ChannelCount(&self) -> u32 {
|
||||
self.channel_count.get()
|
||||
}
|
||||
|
||||
fn SetChannelCount(&self, value: u32) -> ErrorResult {
|
||||
if value == 0 || value > MAX_CHANNEL_COUNT {
|
||||
return Err(Error::NotSupported);
|
||||
}
|
||||
self.channel_count.set(value);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ChannelCountMode(&self) -> ChannelCountMode {
|
||||
self.channel_count_mode.get()
|
||||
}
|
||||
|
||||
fn SetChannelCountMode(&self, value: ChannelCountMode) -> ErrorResult {
|
||||
self.channel_count_mode.set(value);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ChannelInterpretation(&self) -> ChannelInterpretation {
|
||||
self.channel_interpretation.get()
|
||||
}
|
||||
|
||||
fn SetChannelInterpretation(&self, value: ChannelInterpretation) {
|
||||
self.channel_interpretation.set(value);
|
||||
}
|
||||
}
|
66
components/script/dom/audioparam.rs
Normal file
66
components/script/dom/audioparam.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::AudioParamBinding;
|
||||
use dom::bindings::codegen::Bindings::AudioParamBinding::AudioParamMethods;
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom_struct::dom_struct;
|
||||
use std::cell::Cell;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct AudioParam {
|
||||
reflector_: Reflector,
|
||||
value: Cell<f32>,
|
||||
default_value: f32,
|
||||
min_value: f32,
|
||||
max_value: f32,
|
||||
}
|
||||
|
||||
impl AudioParam {
|
||||
pub fn new_inherited(default_value: f32,
|
||||
min_value: f32,
|
||||
max_value: f32) -> AudioParam {
|
||||
AudioParam {
|
||||
reflector_: Reflector::new(),
|
||||
value: Cell::new(default_value),
|
||||
default_value,
|
||||
min_value,
|
||||
max_value,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(global: &GlobalScope,
|
||||
default_value: f32,
|
||||
min_value: f32,
|
||||
max_value: f32) -> DomRoot<AudioParam> {
|
||||
let audio_param = AudioParam::new_inherited(default_value, min_value, max_value);
|
||||
reflect_dom_object(Box::new(audio_param), global, AudioParamBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioParamMethods for AudioParam {
|
||||
fn Value(&self) -> Finite<f32> {
|
||||
Finite::wrap(self.value.get())
|
||||
}
|
||||
|
||||
fn SetValue(&self, value: Finite<f32>) {
|
||||
self.value.set(*value);
|
||||
}
|
||||
|
||||
fn DefaultValue(&self) -> Finite<f32> {
|
||||
Finite::wrap(self.default_value)
|
||||
}
|
||||
|
||||
fn MinValue(&self) -> Finite<f32> {
|
||||
Finite::wrap(self.min_value)
|
||||
}
|
||||
|
||||
fn MaxValue(&self) -> Finite<f32> {
|
||||
Finite::wrap(self.max_value)
|
||||
}
|
||||
}
|
38
components/script/dom/audioscheduledsourcenode.rs
Normal file
38
components/script/dom/audioscheduledsourcenode.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
use dom::audionode::AudioNode;
|
||||
use dom::baseaudiocontext::BaseAudioContext;
|
||||
use dom::bindings::codegen::Bindings::AudioScheduledSourceNodeBinding::AudioScheduledSourceNodeMethods;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||
use dom::bindings::num::Finite;
|
||||
use dom_struct::dom_struct;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct AudioScheduledSourceNode {
|
||||
node: AudioNode,
|
||||
}
|
||||
|
||||
impl AudioScheduledSourceNode {
|
||||
pub fn new_inherited(context: &BaseAudioContext,
|
||||
options: &AudioNodeOptions,
|
||||
number_of_inputs: u32,
|
||||
number_of_outputs: u32) -> AudioScheduledSourceNode {
|
||||
AudioScheduledSourceNode {
|
||||
node: AudioNode::new_inherited(context, options, number_of_inputs, number_of_outputs),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioScheduledSourceNodeMethods for AudioScheduledSourceNode {
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-onended
|
||||
event_handler!(ended, GetOnended, SetOnended);
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-start
|
||||
fn Start(&self, _when: Finite<f64>) {
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audioscheduledsourcenode-stop
|
||||
fn Stop(&self, _when: Finite<f64>) {
|
||||
}
|
||||
}
|
79
components/script/dom/baseaudiocontext.rs
Normal file
79
components/script/dom/baseaudiocontext.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::audiodestinationnode::AudioDestinationNode;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
||||
use dom::bindings::codegen::Bindings::BaseAudioContextBinding::BaseAudioContextMethods;
|
||||
use dom::bindings::codegen::Bindings::BaseAudioContextBinding::AudioContextState;
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::reflector::{DomObject, Reflector};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom::promise::Promise;
|
||||
use dom_struct::dom_struct;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct BaseAudioContext {
|
||||
reflector_: Reflector,
|
||||
destination: Option<DomRoot<AudioDestinationNode>>,
|
||||
sample_rate: f32,
|
||||
current_time: f64,
|
||||
state: AudioContextState,
|
||||
}
|
||||
|
||||
impl BaseAudioContext {
|
||||
#[allow(unrooted_must_root)]
|
||||
#[allow(unsafe_code)]
|
||||
pub fn new_inherited(
|
||||
global: &GlobalScope,
|
||||
channel_count: u32,
|
||||
sample_rate: f32,
|
||||
) -> BaseAudioContext {
|
||||
let mut context = BaseAudioContext {
|
||||
reflector_: Reflector::new(),
|
||||
destination: None,
|
||||
current_time: 0.,
|
||||
sample_rate,
|
||||
state: AudioContextState::Suspended,
|
||||
};
|
||||
|
||||
let mut options = unsafe { AudioNodeOptions::empty(global.get_cx()) };
|
||||
options.channelCount = Some(channel_count);
|
||||
options.channelCountMode = Some(ChannelCountMode::Explicit);
|
||||
options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
||||
|
||||
context.destination = Some(AudioDestinationNode::new(global, &context, &options));
|
||||
|
||||
context
|
||||
}
|
||||
}
|
||||
|
||||
impl BaseAudioContextMethods for BaseAudioContext {
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-samplerate
|
||||
fn SampleRate(&self) -> Finite<f32> {
|
||||
Finite::wrap(self.sample_rate)
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-currenttime
|
||||
fn CurrentTime(&self) -> Finite<f64> {
|
||||
Finite::wrap(self.current_time)
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-resume
|
||||
#[allow(unrooted_must_root)]
|
||||
fn Resume(&self) -> Rc<Promise> {
|
||||
// TODO
|
||||
Promise::new(&self.global())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-destination
|
||||
fn Destination(&self) -> DomRoot<AudioDestinationNode> {
|
||||
DomRoot::from_ref(self.destination.as_ref().unwrap())
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-onstatechange
|
||||
event_handler!(statechange, GetOnstatechange, SetOnstatechange);
|
||||
}
|
|
@ -216,6 +216,12 @@ pub mod abstractworker;
|
|||
pub mod abstractworkerglobalscope;
|
||||
pub mod activation;
|
||||
pub mod attr;
|
||||
pub mod audiocontext;
|
||||
pub mod audiodestinationnode;
|
||||
pub mod audionode;
|
||||
pub mod audioparam;
|
||||
pub mod audioscheduledsourcenode;
|
||||
pub mod baseaudiocontext;
|
||||
pub mod beforeunloadevent;
|
||||
pub mod bindings;
|
||||
pub mod blob;
|
||||
|
@ -392,6 +398,7 @@ pub mod navigatorinfo;
|
|||
pub mod node;
|
||||
pub mod nodeiterator;
|
||||
pub mod nodelist;
|
||||
pub mod oscillatornode;
|
||||
pub mod pagetransitionevent;
|
||||
pub mod paintrenderingcontext2d;
|
||||
pub mod paintsize;
|
||||
|
@ -404,6 +411,7 @@ pub mod performanceobserver;
|
|||
pub mod performanceobserverentrylist;
|
||||
pub mod performancepainttiming;
|
||||
pub mod performancetiming;
|
||||
pub mod periodicwave;
|
||||
pub mod permissions;
|
||||
pub mod permissionstatus;
|
||||
pub mod plugin;
|
||||
|
|
81
components/script/dom/oscillatornode.rs
Normal file
81
components/script/dom/oscillatornode.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::audioscheduledsourcenode::AudioScheduledSourceNode;
|
||||
use dom::baseaudiocontext::BaseAudioContext;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions;
|
||||
use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation};
|
||||
use dom::bindings::codegen::Bindings::OscillatorNodeBinding;
|
||||
use dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorOptions;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OscillatorNode {
|
||||
node: AudioScheduledSourceNode,
|
||||
// oscillator_type: OscillatorType,
|
||||
// frequency: AudioParam,
|
||||
// detune: AudioParam,
|
||||
}
|
||||
|
||||
impl OscillatorNode {
|
||||
#[allow(unrooted_must_root)]
|
||||
#[allow(unsafe_code)]
|
||||
pub fn new_inherited(
|
||||
window: &Window,
|
||||
context: &BaseAudioContext,
|
||||
) -> OscillatorNode {
|
||||
let mut options = unsafe { AudioNodeOptions::empty(window.get_cx()) };
|
||||
options.channelCount = Some(2);
|
||||
options.channelCountMode = Some(ChannelCountMode::Max);
|
||||
options.channelInterpretation = Some(ChannelInterpretation::Speakers);
|
||||
OscillatorNode {
|
||||
node: AudioScheduledSourceNode::new_inherited(
|
||||
context,
|
||||
&options,
|
||||
0, /* inputs */
|
||||
1, /* outputs */
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(
|
||||
window: &Window,
|
||||
context: &BaseAudioContext,
|
||||
_options: &OscillatorOptions,
|
||||
) -> DomRoot<OscillatorNode> {
|
||||
let node = OscillatorNode::new_inherited(window, context);
|
||||
reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn Constructor(
|
||||
window: &Window,
|
||||
context: &BaseAudioContext,
|
||||
options: &OscillatorOptions,
|
||||
) -> Fallible<DomRoot<OscillatorNode>> {
|
||||
Ok(OscillatorNode::new(window, context, options))
|
||||
}
|
||||
}
|
||||
|
||||
/*impl OscillatorNodeMethods for OscillatorNode {
|
||||
fn SetPeriodicWave(&self, periodic_wave: PeriodicWave) {
|
||||
// XXX
|
||||
}
|
||||
|
||||
fn Type(&self) -> OscillatorType {
|
||||
self.oscillator_type
|
||||
}
|
||||
|
||||
fn Frequency(&self) -> DomRoot<AudioParam> {
|
||||
DomRoot::from_ref(&self.frequency)
|
||||
}
|
||||
|
||||
fn Detune(&self) -> DomRoot<AudioParam> {
|
||||
DomRoot::from_ref(&self.detune)
|
||||
}
|
||||
}*/
|
40
components/script/dom/periodicwave.rs
Normal file
40
components/script/dom/periodicwave.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::baseaudiocontext::BaseAudioContext;
|
||||
use dom::bindings::codegen::Bindings::PeriodicWaveBinding;
|
||||
use dom::bindings::codegen::Bindings::PeriodicWaveBinding::PeriodicWaveOptions;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct PeriodicWave {
|
||||
reflector_: Reflector,
|
||||
}
|
||||
|
||||
impl PeriodicWave {
|
||||
pub fn new_inherited() -> PeriodicWave {
|
||||
PeriodicWave {
|
||||
reflector_: Reflector::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(window: &Window) -> DomRoot<PeriodicWave> {
|
||||
let periodic_wave = PeriodicWave::new_inherited();
|
||||
reflect_dom_object(Box::new(periodic_wave), window, PeriodicWaveBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn Constructor(
|
||||
window: &Window,
|
||||
_context: &BaseAudioContext,
|
||||
_options: &PeriodicWaveOptions,
|
||||
) -> Fallible<DomRoot<PeriodicWave>> {
|
||||
// TODO.
|
||||
Ok(PeriodicWave::new(&window))
|
||||
}
|
||||
}
|
40
components/script/dom/webidls/AudioContext.webidl
Normal file
40
components/script/dom/webidls/AudioContext.webidl
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/#dom-audiocontext
|
||||
*/
|
||||
|
||||
enum AudioContextLatencyCategory {
|
||||
"balanced",
|
||||
"interactive",
|
||||
"playback"
|
||||
};
|
||||
|
||||
dictionary AudioContextOptions {
|
||||
AudioContextLatencyCategory latencyHint = "interactive";
|
||||
float sampleRate;
|
||||
};
|
||||
|
||||
dictionary AudioTimestamp {
|
||||
double contextTime;
|
||||
DOMHighResTimeStamp performanceTime;
|
||||
};
|
||||
|
||||
[Exposed=Window,
|
||||
Constructor(optional AudioContextOptions contextOptions)]
|
||||
interface AudioContext : BaseAudioContext {
|
||||
readonly attribute double baseLatency;
|
||||
readonly attribute double outputLatency;
|
||||
|
||||
AudioTimestamp getOutputTimestamp();
|
||||
|
||||
Promise<void> suspend();
|
||||
Promise<void> close();
|
||||
|
||||
// MediaElementAudioSourceNode createMediaElementSource(HTMLMediaElement mediaElement);
|
||||
// MediaStreamAudioSourceNode createMediaStreamSource(MediaStream mediaStream);
|
||||
// MediaStreamTrackAudioSourceNode createMediaStreamTrackSource(MediaStreamTrack mediaStreamTrack);
|
||||
// MediaStreamAudioDestinationNode createMediaStreamDestination();
|
||||
};
|
12
components/script/dom/webidls/AudioDestinationNode.webidl
Normal file
12
components/script/dom/webidls/AudioDestinationNode.webidl
Normal file
|
@ -0,0 +1,12 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/#dom-audiodestinationnode
|
||||
*/
|
||||
|
||||
[Exposed=Window]
|
||||
interface AudioDestinationNode : AudioNode {
|
||||
readonly attribute unsigned long maxChannelCount;
|
||||
};
|
61
components/script/dom/webidls/AudioNode.webidl
Normal file
61
components/script/dom/webidls/AudioNode.webidl
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/#dom-audionode
|
||||
*/
|
||||
|
||||
enum ChannelCountMode {
|
||||
"max",
|
||||
"clamped-max",
|
||||
"explicit"
|
||||
};
|
||||
|
||||
enum ChannelInterpretation {
|
||||
"speakers",
|
||||
"discrete"
|
||||
};
|
||||
|
||||
dictionary AudioNodeOptions {
|
||||
unsigned long channelCount;
|
||||
ChannelCountMode channelCountMode;
|
||||
ChannelInterpretation channelInterpretation;
|
||||
};
|
||||
|
||||
[Exposed=Window]
|
||||
interface AudioNode : EventTarget {
|
||||
[Throws]
|
||||
AudioNode connect(AudioNode destinationNode,
|
||||
optional unsigned long output = 0,
|
||||
optional unsigned long input = 0);
|
||||
[Throws]
|
||||
void connect(AudioParam destinationParam,
|
||||
optional unsigned long output = 0);
|
||||
[Throws]
|
||||
void disconnect();
|
||||
[Throws]
|
||||
void disconnect(unsigned long output);
|
||||
[Throws]
|
||||
void disconnect(AudioNode destination);
|
||||
[Throws]
|
||||
void disconnect(AudioNode destination, unsigned long output);
|
||||
[Throws]
|
||||
void disconnect(AudioNode destination,
|
||||
unsigned long output,
|
||||
unsigned long input);
|
||||
[Throws]
|
||||
void disconnect(AudioParam destination);
|
||||
[Throws]
|
||||
void disconnect(AudioParam destination, unsigned long output);
|
||||
|
||||
readonly attribute BaseAudioContext context;
|
||||
readonly attribute unsigned long numberOfInputs;
|
||||
readonly attribute unsigned long numberOfOutputs;
|
||||
|
||||
[SetterThrows]
|
||||
attribute unsigned long channelCount;
|
||||
[SetterThrows]
|
||||
attribute ChannelCountMode channelCountMode;
|
||||
attribute ChannelInterpretation channelInterpretation;
|
||||
};
|
26
components/script/dom/webidls/AudioParam.webidl
Normal file
26
components/script/dom/webidls/AudioParam.webidl
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/#dom-audioparam
|
||||
*/
|
||||
|
||||
[Exposed=Window]
|
||||
interface AudioParam {
|
||||
attribute float value;
|
||||
readonly attribute float defaultValue;
|
||||
readonly attribute float minValue;
|
||||
readonly attribute float maxValue;
|
||||
// AudioParam setValueAtTime(float value, double startTime);
|
||||
// AudioParam linearRampToValueAtTime(float value, double endTime);
|
||||
// AudioParam exponentialRampToValueAtTime(float value, double endTime);
|
||||
// AudioParam setTargetAtTime(float target,
|
||||
// double startTime,
|
||||
// float timeConstant);
|
||||
// AudioParam setValueCurveAtTime(sequence<float> values,
|
||||
// double startTime,
|
||||
// double duration);
|
||||
// AudioParam cancelScheduledValues(double cancelTime);
|
||||
// AudioParam cancelAndHoldAtTime(double cancelTime);
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/#AudioScheduledSourceNode
|
||||
*/
|
||||
|
||||
[Exposed=Window]
|
||||
interface AudioScheduledSourceNode : AudioNode {
|
||||
attribute EventHandler onended;
|
||||
void start(optional double when = 0);
|
||||
void stop(optional double when = 0);
|
||||
};
|
55
components/script/dom/webidls/BaseAudioContext.webidl
Normal file
55
components/script/dom/webidls/BaseAudioContext.webidl
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/#BaseAudioContext
|
||||
*/
|
||||
|
||||
enum AudioContextState {
|
||||
"suspended",
|
||||
"running",
|
||||
"closed"
|
||||
};
|
||||
|
||||
// callback DecodeErrorCallback = void (DOMException error);
|
||||
// callback DecodeSuccessCallback = void (AudioBuffer decodedData);
|
||||
|
||||
[Exposed=Window]
|
||||
interface BaseAudioContext : EventTarget {
|
||||
readonly attribute AudioDestinationNode destination;
|
||||
readonly attribute float sampleRate;
|
||||
readonly attribute double currentTime;
|
||||
// readonly attribute AudioListener listener;
|
||||
// readonly attribute AudioContextState state;
|
||||
Promise<void> resume();
|
||||
attribute EventHandler onstatechange;
|
||||
// AudioBuffer createBuffer(unsigned long numberOfChannels,
|
||||
// unsigned long length,
|
||||
// float sampleRate);
|
||||
// Promise<AudioBuffer> decodeAudioData(ArrayBuffer audioData,
|
||||
// optional DecodeSuccessCallback successCallback,
|
||||
// optional DecodeErrorCallback errorCallback);
|
||||
// AudioBufferSourceNode createBufferSource();
|
||||
// ConstantSourceNode createConstantSource();
|
||||
// ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0,
|
||||
// optional unsigned long numberOfInputChannels = 2,
|
||||
// optional unsigned long numberOfOutputChannels = 2);
|
||||
// AnalyserNode createAnalyser();
|
||||
// GainNode createGain();
|
||||
// DelayNode createDelay(optional double maxDelayTime = 1);
|
||||
// BiquadFilterNode createBiquadFilter();
|
||||
// IIRFilterNode createIIRFilter(sequence<double> feedforward,
|
||||
// sequence<double> feedback);
|
||||
// WaveShaperNode createWaveShaper();
|
||||
// PannerNode createPanner();
|
||||
// StereoPannerNode createStereoPanner();
|
||||
// ConvolverNode createConvolver();
|
||||
// ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
|
||||
// ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs = 6);
|
||||
// DynamicsCompressorNode createDynamicsCompressor();
|
||||
// OscillatorNode createOscillator();
|
||||
// PeriodicWave createPeriodicWave(sequence<float> real,
|
||||
// sequence<float> imag,
|
||||
// optional PeriodicWaveConstraints constraints);
|
||||
};
|
34
components/script/dom/webidls/OscillatorNode.webidl
Normal file
34
components/script/dom/webidls/OscillatorNode.webidl
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/#oscillatornode
|
||||
*/
|
||||
|
||||
enum OscillatorType {
|
||||
"sine",
|
||||
"square",
|
||||
"sawtooth",
|
||||
"triangle",
|
||||
"custom"
|
||||
};
|
||||
|
||||
dictionary OscillatorOptions : AudioNodeOptions {
|
||||
OscillatorType type = "sine";
|
||||
float frequency = 440;
|
||||
float detune = 0;
|
||||
PeriodicWave periodicWave;
|
||||
};
|
||||
|
||||
[Exposed=Window,
|
||||
Constructor (BaseAudioContext context, optional OscillatorOptions options)]
|
||||
interface OscillatorNode : AudioScheduledSourceNode {
|
||||
/* [SetterThrows]
|
||||
attribute OscillatorType type;
|
||||
|
||||
readonly attribute AudioParam frequency;
|
||||
readonly attribute AudioParam detune;
|
||||
|
||||
void setPeriodicWave (PeriodicWave periodicWave);*/
|
||||
};
|
21
components/script/dom/webidls/PeriodicWave.webidl
Normal file
21
components/script/dom/webidls/PeriodicWave.webidl
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://webaudio.github.io/web-audio-api/#periodicwave
|
||||
*/
|
||||
|
||||
dictionary PeriodicWaveConstraints {
|
||||
boolean disableNormalization = false;
|
||||
};
|
||||
|
||||
dictionary PeriodicWaveOptions : PeriodicWaveConstraints {
|
||||
sequence<float> real;
|
||||
sequence<float> imag;
|
||||
};
|
||||
|
||||
[Exposed=Window,
|
||||
Constructor(BaseAudioContext context, optional PeriodicWaveOptions options)]
|
||||
interface PeriodicWave {
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue