Commit 77459e31 authored by rtoy@google.com's avatar rtoy@google.com

ConvolverNode.buffer sample rate must match AudioContext rate

Throw an exception as required when the sample rate of the convolver
node buffer does not match the sample rate of the audio context.

Added test for this case.

BUG=352776

Review URL: https://codereview.chromium.org/200543005

git-svn-id: svn://svn.chromium.org/blink/trunk@169501 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 9a49cc63
......@@ -73,6 +73,9 @@ PASS osc1.start() did not throw exception.
PASS osc1.stop() did not throw exception.
PASS node.gain.exponentialRampToValueAtTime(-1, 0.1) threw exception InvalidStateError: Failed to execute 'exponentialRampToValueAtTime' on 'AudioParam': Target value for exponential ramp must be positive: -1.
PASS node.gain.exponentialRampToValueAtTime(0, 0.1) threw exception InvalidStateError: Failed to execute 'exponentialRampToValueAtTime' on 'AudioParam': Target value for exponential ramp must be positive: 0.
PASS oc = new webkitOfflineAudioContext(1, 44100, 44100) did not throw exception.
PASS conv = oc.createConvolver() did not throw exception.
PASS conv.buffer = oc.createBuffer(1, 100, 22050) threw exception NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer sample rate of 22050 does not match the context rate of 44100 Hz..
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -165,6 +165,13 @@ function runTest() {
node.connect(context.destination);
shouldThrow("node.gain.exponentialRampToValueAtTime(-1, 0.1)");
shouldThrow("node.gain.exponentialRampToValueAtTime(0, 0.1)");
// Convolver buffer rate must match context rate. Create on offline context so we
// specify the context rate exactly, in case the test is run on platforms with different
// HW sample rates.
shouldNotThrow("oc = new webkitOfflineAudioContext(1, 44100, 44100)");
shouldNotThrow("conv = oc.createConvolver()");
shouldThrow("conv.buffer = oc.createBuffer(1, 100, 22050)");
}
runTest();
......
......@@ -28,6 +28,8 @@
#include "modules/webaudio/ConvolverNode.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "platform/audio/Reverb.h"
#include "modules/webaudio/AudioBuffer.h"
#include "modules/webaudio/AudioContext.h"
......@@ -107,13 +109,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();
......
......@@ -33,6 +33,7 @@
namespace WebCore {
class AudioBuffer;
class ExceptionState;
class Reverb;
class ConvolverNode FINAL : public AudioNode {
......@@ -50,7 +51,7 @@ public:
virtual void uninitialize() OVERRIDE;
// Impulse responses
void setBuffer(AudioBuffer*);
void setBuffer(AudioBuffer*, ExceptionState&);
AudioBuffer* buffer();
bool normalize() const { return m_normalize; }
......
......@@ -26,6 +26,6 @@
[
Conditional=WEB_AUDIO
] interface ConvolverNode : AudioNode {
attribute AudioBuffer buffer;
[RaisesException=Setter] attribute AudioBuffer buffer;
attribute boolean normalize;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment