From 41f9f1416160196787f0f14125cbaeaeb9b19268 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 31 Oct 2012 20:26:03 -0400 Subject: [PATCH] Bug 807533 - Implement DelayNode; r=bzbarsky --HG-- extra : rebase_source : 36bb70c9f4b9c86fc1564447a34153d92fe7f347 --- content/media/webaudio/AudioContext.cpp | 8 +++ content/media/webaudio/AudioContext.h | 4 ++ content/media/webaudio/DelayNode.cpp | 42 +++++++++++ content/media/webaudio/DelayNode.h | 51 ++++++++++++++ content/media/webaudio/Makefile.in | 2 + content/media/webaudio/test/Makefile.in | 1 + .../media/webaudio/test/test_delayNode.html | 69 +++++++++++++++++++ dom/bindings/Bindings.conf | 5 ++ dom/webidl/AudioContext.webidl | 2 + dom/webidl/DelayNode.webidl | 19 +++++ dom/webidl/WebIDL.mk | 1 + 11 files changed, 204 insertions(+) create mode 100644 content/media/webaudio/DelayNode.cpp create mode 100644 content/media/webaudio/DelayNode.h create mode 100644 content/media/webaudio/test/test_delayNode.html create mode 100644 dom/webidl/DelayNode.webidl diff --git a/content/media/webaudio/AudioContext.cpp b/content/media/webaudio/AudioContext.cpp index c5e6f4ca80f..0aa510ec794 100644 --- a/content/media/webaudio/AudioContext.cpp +++ b/content/media/webaudio/AudioContext.cpp @@ -13,6 +13,7 @@ #include "AudioBufferSourceNode.h" #include "AudioBuffer.h" #include "GainNode.h" +#include "DelayNode.h" namespace mozilla { namespace dom { @@ -94,6 +95,13 @@ AudioContext::CreateGain() return gainNode.forget(); } +already_AddRefed +AudioContext::CreateDelay(float aMaxDelayTime) +{ + nsRefPtr delayNode = new DelayNode(this, aMaxDelayTime); + return delayNode.forget(); +} + } } diff --git a/content/media/webaudio/AudioContext.h b/content/media/webaudio/AudioContext.h index 6deaccafe67..c10161ff36f 100644 --- a/content/media/webaudio/AudioContext.h +++ b/content/media/webaudio/AudioContext.h @@ -27,6 +27,7 @@ class AudioDestinationNode; class AudioBufferSourceNode; class AudioBuffer; class GainNode; +class DelayNode; class AudioContext MOZ_FINAL : public nsWrapperCache, public EnableWebAudioCheck @@ -65,6 +66,9 @@ public: already_AddRefed CreateGain(); + already_AddRefed + CreateDelay(float aMaxDelayTime); + private: nsCOMPtr mWindow; nsRefPtr mDestination; diff --git a/content/media/webaudio/DelayNode.cpp b/content/media/webaudio/DelayNode.cpp new file mode 100644 index 00000000000..be8e5d779b3 --- /dev/null +++ b/content/media/webaudio/DelayNode.cpp @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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/. */ + +#include "DelayNode.h" +#include "mozilla/dom/DelayNodeBinding.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_CYCLE_COLLECTION_CLASS(DelayNode) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DelayNode, AudioNode) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDelay) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DelayNode, AudioNode) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mDelay, AudioParam, "delay value") +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DelayNode) +NS_INTERFACE_MAP_END_INHERITING(AudioNode) + +NS_IMPL_ADDREF_INHERITED(DelayNode, AudioNode) +NS_IMPL_RELEASE_INHERITED(DelayNode, AudioNode) + +DelayNode::DelayNode(AudioContext* aContext, float aMaxDelay) + : AudioNode(aContext) + , mDelay(new AudioParam(aContext, 0.0f, 0.0f, aMaxDelay)) +{ +} + +JSObject* +DelayNode::WrapObject(JSContext* aCx, JSObject* aScope, + bool* aTriedToWrap) +{ + return DelayNodeBinding::Wrap(aCx, aScope, this, aTriedToWrap); +} + +} +} + diff --git a/content/media/webaudio/DelayNode.h b/content/media/webaudio/DelayNode.h new file mode 100644 index 00000000000..2bc4d90610c --- /dev/null +++ b/content/media/webaudio/DelayNode.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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/. */ + +#ifndef DelayNode_h_ +#define DelayNode_h_ + +#include "AudioNode.h" +#include "AudioParam.h" + +namespace mozilla { +namespace dom { + +class AudioContext; + +class DelayNode : public AudioNode +{ +public: + DelayNode(AudioContext* aContext, float aMaxDelay); + + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DelayNode, AudioNode) + + virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope, + bool* aTriedToWrap); + + virtual uint32_t MaxNumberOfInputs() const MOZ_FINAL MOZ_OVERRIDE + { + return 1; + } + virtual uint32_t MaxNumberOfOutputs() const MOZ_FINAL MOZ_OVERRIDE + { + return 1; + } + + AudioParam* DelayTime() const + { + return mDelay; + } + +private: + nsRefPtr mDelay; +}; + +} +} + +#endif + diff --git a/content/media/webaudio/Makefile.in b/content/media/webaudio/Makefile.in index 777d9fe1737..0307b4ea34b 100644 --- a/content/media/webaudio/Makefile.in +++ b/content/media/webaudio/Makefile.in @@ -22,6 +22,7 @@ CPPSRCS := \ AudioNode.cpp \ AudioParam.cpp \ AudioSourceNode.cpp \ + DelayNode.cpp \ EnableWebAudioCheck.cpp \ GainNode.cpp \ $(NULL) @@ -34,6 +35,7 @@ EXPORTS_mozilla/dom := \ AudioNode.h \ AudioParam.h \ AudioSourceNode.h \ + DelayNode.h \ GainNode.h \ $(NULL) diff --git a/content/media/webaudio/test/Makefile.in b/content/media/webaudio/test/Makefile.in index 7111a27bdea..2b48a89d690 100644 --- a/content/media/webaudio/test/Makefile.in +++ b/content/media/webaudio/test/Makefile.in @@ -14,6 +14,7 @@ MOCHITEST_FILES := \ test_AudioBuffer.html \ test_AudioContext.html \ test_badConnect.html \ + test_delayNode.html \ test_gainNode.html \ test_singleSourceDest.html \ $(NULL) diff --git a/content/media/webaudio/test/test_delayNode.html b/content/media/webaudio/test/test_delayNode.html new file mode 100644 index 00000000000..7bdfb1a50c8 --- /dev/null +++ b/content/media/webaudio/test/test_delayNode.html @@ -0,0 +1,69 @@ + + + + Test DelayNode + + + + +
+
+
+ + diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 34f118cf32d..5f33918b8ff 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -140,6 +140,11 @@ DOMInterfaces = { 'nativeType': 'nsICSSDeclaration' }, +'DelayNode': [ +{ + 'resultNotAddRefed': [ 'delayTime' ], +}], + 'Document': [ { 'nativeType': 'nsIDocument', diff --git a/dom/webidl/AudioContext.webidl b/dom/webidl/AudioContext.webidl index f92733690f9..f286721ed24 100644 --- a/dom/webidl/AudioContext.webidl +++ b/dom/webidl/AudioContext.webidl @@ -27,6 +27,8 @@ interface mozAudioContext { [Creator] GainNode createGain(); + [Creator] + DelayNode createDelay(optional float maxDelayTime = 1); }; diff --git a/dom/webidl/DelayNode.webidl b/dom/webidl/DelayNode.webidl new file mode 100644 index 00000000000..37a348ce95c --- /dev/null +++ b/dom/webidl/DelayNode.webidl @@ -0,0 +1,19 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +[PrefControlled] +interface DelayNode : AudioNode { + + readonly attribute AudioParam delayTime; + +}; + diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 225c8aaa74c..bca78af590e 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -20,6 +20,7 @@ webidl_files = \ CanvasRenderingContext2D.webidl \ ClientRectList.webidl \ CSSStyleDeclaration.webidl \ + DelayNode.webidl \ DOMImplementation.webidl \ DOMTokenList.webidl \ DOMSettableTokenList.webidl \