Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / webaudio / ConvolverNode.cpp
index 0073ae8..523d0b8 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "modules/webaudio/ConvolverNode.h"
 
+#include "bindings/core/v8/ExceptionState.h"
+#include "core/dom/ExceptionCode.h"
 #include "platform/audio/Reverb.h"
 #include "modules/webaudio/AudioBuffer.h"
 #include "modules/webaudio/AudioContext.h"
 // Very large FFTs will have worse phase errors. Given these constraints 32768 is a good compromise.
 const size_t MaxFFTSize = 32768;
 
-namespace WebCore {
+namespace blink {
 
 ConvolverNode::ConvolverNode(AudioContext* context, float sampleRate)
     : AudioNode(context, sampleRate)
     , m_normalize(true)
 {
-    ScriptWrappable::init(this);
-    addInput(adoptPtr(new AudioNodeInput(this)));
-    addOutput(adoptPtr(new AudioNodeOutput(this, 2)));
+    addInput();
+    addOutput(AudioNodeOutput::create(this, 2));
 
     // Node-specific default mixing rules.
     m_channelCount = 2;
@@ -64,7 +65,13 @@ ConvolverNode::ConvolverNode(AudioContext* context, float sampleRate)
 
 ConvolverNode::~ConvolverNode()
 {
+    ASSERT(!isInitialized());
+}
+
+void ConvolverNode::dispose()
+{
     uninitialize();
+    AudioNode::dispose();
 }
 
 void ConvolverNode::process(size_t framesToProcess)
@@ -107,13 +114,21 @@ void ConvolverNode::uninitialize()
     AudioNode::uninitialize();
 }
 
-void ConvolverNode::setBuffer(AudioBuffer* buffer)
+void ConvolverNode::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionState)
 {
     ASSERT(isMainThread());
 
     if (!buffer)
         return;
 
+    if (buffer->sampleRate() != context()->sampleRate()) {
+        exceptionState.throwDOMException(
+            NotSupportedError,
+            "The buffer sample rate of " + String::number(buffer->sampleRate())
+            + " does not match the context rate of " + String::number(context()->sampleRate())
+            + " Hz.");
+    }
+
     unsigned numberOfChannels = buffer->numberOfChannels();
     size_t bufferLength = buffer->length();
 
@@ -169,6 +184,12 @@ double ConvolverNode::latencyTime() const
     return std::numeric_limits<double>::infinity();
 }
 
-} // namespace WebCore
+void ConvolverNode::trace(Visitor* visitor)
+{
+    visitor->trace(m_buffer);
+    AudioNode::trace(visitor);
+}
+
+} // namespace blink
 
 #endif // ENABLE(WEB_AUDIO)