Commit c5f32c5a authored by rtoy@chromium.org's avatar rtoy@chromium.org

Remove 2-arg createBuffer from WebAudio

Originally the 2-arg createBuffer method was a method for synchronously decoding a blob of encoded audio data. This is no longer allowed in the WebAudio specification.

See http://webaudio.github.io/web-audio-api/#methods for the valid createBuffer method.

Update tests accordingly.

BUG=354133

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

git-svn-id: svn://svn.chromium.org/blink/trunk@171498 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent aac79d73
...@@ -8,7 +8,7 @@ PASS context.createBuffer(1, 1, 1e6) threw exception NotSupportedError: Failed t ...@@ -8,7 +8,7 @@ PASS context.createBuffer(1, 1, 1e6) threw exception NotSupportedError: Failed t
PASS context.createBuffer(1, 1, 3000) did not throw exception. PASS context.createBuffer(1, 1, 3000) did not throw exception.
PASS context.createBuffer(1, 1, 192000) did not throw exception. PASS context.createBuffer(1, 1, 192000) did not throw exception.
PASS context.createBuffer(1, 0, context.sampleRate) threw exception NotSupportedError: Failed to execute 'createBuffer' on 'AudioContext': number of frames must be greater than 0.. PASS context.createBuffer(1, 0, context.sampleRate) threw exception NotSupportedError: Failed to execute 'createBuffer' on 'AudioContext': number of frames must be greater than 0..
PASS context.createBuffer(new ArrayBuffer(100), true) threw exception SyntaxError: Failed to execute 'createBuffer' on 'AudioContext': invalid audio data in ArrayBuffer.. PASS context.createBuffer(new ArrayBuffer(100), true) threw exception TypeError: Failed to execute 'createBuffer' on 'AudioContext': 3 arguments required, but only 2 present..
PASS context.decodeAudioData(null, function() {}, function () {}) threw exception SyntaxError: Failed to execute 'decodeAudioData' on 'AudioContext': invalid ArrayBuffer for audioData.. PASS context.decodeAudioData(null, function() {}, function () {}) threw exception SyntaxError: Failed to execute 'decodeAudioData' on 'AudioContext': invalid ArrayBuffer for audioData..
PASS context.createMediaElementSource(null) threw exception InvalidStateError: Failed to execute 'createMediaElementSource' on 'AudioContext': invalid HTMLMedialElement.. PASS context.createMediaElementSource(null) threw exception InvalidStateError: Failed to execute 'createMediaElementSource' on 'AudioContext': invalid HTMLMedialElement..
PASS context.createMediaStreamSource(null) threw exception InvalidStateError: Failed to execute 'createMediaStreamSource' on 'AudioContext': invalid MediaStream source. PASS context.createMediaStreamSource(null) threw exception InvalidStateError: Failed to execute 'createMediaStreamSource' on 'AudioContext': invalid MediaStream source.
......
...@@ -40,7 +40,7 @@ function runTest() { ...@@ -40,7 +40,7 @@ function runTest() {
shouldNotThrow("context.createBuffer(1, 1, 192000)"); shouldNotThrow("context.createBuffer(1, 1, 192000)");
// Invalid number of frames: NotSupportedError // Invalid number of frames: NotSupportedError
shouldThrow("context.createBuffer(1, 0, context.sampleRate)"); shouldThrow("context.createBuffer(1, 0, context.sampleRate)");
// Invalid ArrayBuffer (unspecified error) // 2-arg createBuffer not allowed.
shouldThrow("context.createBuffer(new ArrayBuffer(100), true)"); shouldThrow("context.createBuffer(new ArrayBuffer(100), true)");
// Invalid ArrayBuffer (unspecified error) // Invalid ArrayBuffer (unspecified error)
shouldThrow("context.decodeAudioData(null, function() {}, function () {})"); shouldThrow("context.decodeAudioData(null, function() {}, function () {})");
......
...@@ -15,20 +15,20 @@ BufferLoader.prototype.loadBuffer = function(url, index) { ...@@ -15,20 +15,20 @@ BufferLoader.prototype.loadBuffer = function(url, index) {
var loader = this; var loader = this;
request.onload = function() { request.onload = function() {
var buffer; loader.context.decodeAudioData(
try { request.response,
buffer = loader.context.createBuffer(request.response, false); function (decodedAudio) {
} catch(e) { try {
alert('error decoding file data: ' + url); loader.bufferList[index] = decodedAudio;
} if (++loader.loadCount == loader.urlList.length)
loader.onload(loader.bufferList);
try { } catch(e) {
loader.bufferList[index] = buffer; alert('BufferLoader: unable to load buffer' + index);
if (++loader.loadCount == loader.urlList.length) }
loader.onload(loader.bufferList); },
} catch(e) { function () {
alert('BufferLoader: callback problem'); alert('error decoding file data: ' + url);
} });
} }
request.onerror = function() { request.onerror = function() {
......
...@@ -305,27 +305,6 @@ PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, si ...@@ -305,27 +305,6 @@ PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, si
return audioBuffer; return audioBuffer;
} }
PassRefPtr<AudioBuffer> AudioContext::createBuffer(ArrayBuffer* arrayBuffer, bool mixToMono, ExceptionState& exceptionState)
{
ASSERT(arrayBuffer);
if (!arrayBuffer) {
exceptionState.throwDOMException(
SyntaxError,
"invalid ArrayBuffer.");
return nullptr;
}
RefPtr<AudioBuffer> audioBuffer = AudioBuffer::createFromAudioFileData(arrayBuffer->data(), arrayBuffer->byteLength(), mixToMono, sampleRate());
if (!audioBuffer.get()) {
exceptionState.throwDOMException(
SyntaxError,
"invalid audio data in ArrayBuffer.");
return nullptr;
}
return audioBuffer;
}
void AudioContext::decodeAudioData(ArrayBuffer* audioData, PassOwnPtr<AudioBufferCallback> successCallback, PassOwnPtr<AudioBufferCallback> errorCallback, ExceptionState& exceptionState) void AudioContext::decodeAudioData(ArrayBuffer* audioData, PassOwnPtr<AudioBufferCallback> successCallback, PassOwnPtr<AudioBufferCallback> errorCallback, ExceptionState& exceptionState)
{ {
if (!audioData) { if (!audioData) {
......
...@@ -97,7 +97,6 @@ public: ...@@ -97,7 +97,6 @@ public:
float sampleRate() const { return m_destinationNode->sampleRate(); } float sampleRate() const { return m_destinationNode->sampleRate(); }
PassRefPtr<AudioBuffer> createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&); PassRefPtr<AudioBuffer> createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&);
PassRefPtr<AudioBuffer> createBuffer(ArrayBuffer*, bool mixToMono, ExceptionState&);
// Asynchronous audio file data decoding. // Asynchronous audio file data decoding.
void decodeAudioData(ArrayBuffer*, PassOwnPtr<AudioBufferCallback>, PassOwnPtr<AudioBufferCallback>, ExceptionState&); void decodeAudioData(ArrayBuffer*, PassOwnPtr<AudioBufferCallback>, PassOwnPtr<AudioBufferCallback>, ExceptionState&);
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
readonly attribute AudioListener listener; readonly attribute AudioListener listener;
[RaisesException] AudioBuffer createBuffer(unsigned long numberOfChannels, unsigned long numberOfFrames, float sampleRate); [RaisesException] AudioBuffer createBuffer(unsigned long numberOfChannels, unsigned long numberOfFrames, float sampleRate);
[RaisesException] AudioBuffer createBuffer(ArrayBuffer? buffer, boolean mixToMono);
// Asynchronous audio file data decoding. // Asynchronous audio file data decoding.
[RaisesException] void decodeAudioData(ArrayBuffer audioData, AudioBufferCallback successCallback, optional AudioBufferCallback errorCallback); [RaisesException] void decodeAudioData(ArrayBuffer audioData, AudioBufferCallback successCallback, optional AudioBufferCallback errorCallback);
......
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