decodeAudioData returning "given encoding not supported" on small wav file
Categories
(Core :: Web Audio, defect, P2)
Tracking
()
People
(Reporter: github, Unassigned)
Details
Attachments
(1 file)
35.43 KB,
audio/wav
|
Details |
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0
Steps to reproduce:
I'm calling audioContext.decodeAudioData and getting the error
"The buffer passed to decodeAudioData contains invalid content which cannot be decoded successfully.
EncodingError: The given encoding is not supported."
The file is a small wav file (just over 0.1 of a second long) and I'm wondering if this small size is what is upsetting it.
The file was creating using Audacity which I've used for creating other samples which have worked fine.
Any insight welcome at this point.
Actual results:
decodeAudioData failed
Expected results:
decodeAudioData succeeded
Updated•6 years ago
|
Okay, so I reduced the sample from stereo to mono (again in Audacity) and firefox was quite happy about the new file.
But I don't know why the original file didn't work (other players I could lay my hands on played it okay) and there was not enough information to know what was upsetting it.
Comment 2•6 years ago
|
||
Would you like to post the code sample that you are using to test the file, or a link to a page that reproduces the error?
Here you go. Works with every other wav file I've produced using audacity, just not this one.
<html>
<head>
<title>Test</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script>
(function ($) {
/**
* https://gist.githubusercontent.com/SaneMethod/7548768/raw/ae22b1fa2e6f56ae6c87ad0d7fbae8fd511e781f/jquery-ajax-blob-arraybuffer.js
*
* Register ajax transports for blob send/recieve and array buffer send/receive via XMLHttpRequest Level 2
* within the comfortable framework of the jquery ajax request, with full support for promises.
*
* Notice the +* in the dataType string? The + indicates we want this transport to be prepended to the list
* of potential transports (so it gets first dibs if the request passes the conditions within to provide the
* ajax transport, preventing the standard transport from hogging the request), and the * indicates that
* potentially any request with any dataType might want to use the transports provided herein.
*
* Remember to specify 'processData:false' in the ajax options when attempting to send a blob or arraybuffer -
* otherwise jquery will try (and fail) to convert the blob or buffer into a query string.
*
* This revision now includes sending headers, resolves the stack overflow in abort(), and sets the status text
* into the response if the request is unsuccessful.
*/
$.ajaxTransport("+*", function (options, originalOptions, jqXhr) {
"use strict";
// Test for the conditions that mean we can/want to send/receive blobs or arraybuffers - we need XMLHttpRequest
// level 2 (so feature-detect against window.FormData), feature detect against window.Blob or window.ArrayBuffer,
// and then check to see if the dataType is blob/arraybuffer or the data itself is a Blob/ArrayBuffer
if (!window.FormData || (!options.dataType || options.dataType !== "blob" && options.dataType !== "arraybuffer")
&& (!options.data || (!window.Blob || !(options.data instanceof Blob))
&& (!window.ArrayBuffer || !(options.data instanceof ArrayBuffer))))
return undefined;
var xhr;
return {
/**
* This callback type is called `completeCallback` and is displayed as a global symbol.
*
* @callback completeCallback
*/
/**
* Return a transport capable of sending and/or receiving blobs - in this case, we instantiate
* a new XMLHttpRequest and use it to actually perform the request, and funnel the result back
* into the jquery complete callback (such as the success function, done blocks, etc.)
*
* @param {string} headers - headers
* @param {completeCallback} completeCallback - completeCallback
*/
send: function (headers, completeCallback) {
const url = options.url || window.location.href;
const type = options.type || "GET";
var dataType = options.dataType || "text";
const data = options.data || null;
const async = options.async || true;
xhr = new XMLHttpRequest();
xhr.addEventListener("load", function () {
const res = {};
const success = xhr.status >= 200 && xhr.status < 300 || xhr.status === 304;
if (success) {
res[dataType] = xhr.response;
} else {
res.text = xhr.statusText;
}
completeCallback(xhr.status, xhr.statusText, res, xhr.getAllResponseHeaders());
});
xhr.addEventListener("error", function () {
const res = {
text: xhr.statusText
};
completeCallback(xhr.status, xhr.statusText, res, xhr.getAllResponseHeaders());
});
xhr.addEventListener("timeout", function () {
const res = {
text: xhr.statusText
};
completeCallback(xhr.status, xhr.statusText, res, xhr.getAllResponseHeaders());
});
xhr.open(type, url, async);
xhr.responseType = dataType;
for (var key in headers) {
if (headers.hasOwnProperty(key)) {
xhr.setRequestHeader(key, headers[key]);
}
}
xhr.send(data);
},
abort: function () {
if (xhr) {
xhr.abort();
}
}
};
});
})(jQuery);
</script>
<script>
</script>
</head>
<body>
<input id="pressMe" type="button" value="Press Me"/>
<script>
$(function () {
$("#pressMe").click(async function () {
try {
var wavData = await $.get({
url: "tick.wav",
dataType: "arraybuffer"
});
const audioContext = new AudioContext();
const decodedData = await audioContext.decodeAudioData(wavData);
const bufferSource = audioContext.createBufferSource();
bufferSource.buffer = decodedData;
bufferSource.connect(audioContext.destination);
bufferSource.start();
} catch (error) {
alert(error);
}
});
});
</script>
</body>
</html>
Updated•6 years ago
|
Comment 4•6 years ago
|
||
This file has float32 samples (instead of the more common int16 samples), and Firefox does not support it. In Audacity, selecting an integer 8, 16 or 24 sample type will produce a file that works everywhere.
Thanks for looking into this. It looks to me like Audacity is being misleading, because whatever file I open, it seems to be saying that it contains 32-bit float samples. Oddly enough it's trusty old Wimamp to the rescue which accurately reports the sample type.
Perhaps adding support for 32-bit float samples could be a future enhancement for firefox as it seems to be a real exception in not being able to use such files. In the meantime, the error message could be made more specific as to the problem.
Description
•