-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DecodeAudioData doesn't work on partial content #337
Comments
I believe that is the intent for decodeAudioData. If you want to stream data to WebAudio, you can use a MediaElementAudioSourceNode. |
Hello, Thanks for your reply. Through a MediaElementSource, I have to go through a JavaScriptNode to recover audiobuffer in real time. I did not find an other way to do that without JavascriptNode. |
-Jer |
I'm a bit late to this one but I can't see how the decoding of partial content could be done automatically with decodeAudioData(). File formats such as OGG Vorbis (and MP3 if I remember correctly) store the information required to decode the audio in the file header. The decoder could store that information somewhere but it would have no idea if N number of calls to decodeAudioData() were sequential and/or partial chunks from the same source file. Also, the structure of the source file needs to be considered, some formats can only be decoded in chunks (frames) of specific sizes. It's actually possible to "stream" audio now using decodeAudioData() if the programmer understands the format of a particular audio file. I managed to do this with OGG Vorbis (load and decode it in chunks) a while ago by storing the required decoding information and prepending it to the beginning of each chunk prior to decoding. The data loading and splicing can be done in a worker and then transferred (zero-op) to the main thread for decoding. That being said, the existing media elements do all of this already so you would need a really good reason to not use them for streaming, IHMO :) |
I think we made the decision to push more powerful decoding API to v.next? |
That's what I remember as well. |
Add a new class, AudioStreamParser, modeled on the SourceBuffer from the Media Source Extensions <http://w3c.github.io/media-source/> specification, which allows for encoded audio data to be progressively appended to the object, resulting in one or more AudioBuffers. resolves WebAudio#337
Based on the comments in #337 (comment) and #337 (comment), I think we've decided to move this to v.next. Adding Needs WG review for a final decision. |
+1 Posted a question here |
Discussed at today's Working Group call and agreed to move to v.next, along with issue #30. |
At Soundtrap, we have custom codecs using web assembly compiled ogg/vorbis. These are exposed in async streaming js apis to allow you to decode audio data in chunks. You specify the offset and number of frames and get an audio buffer back. This, in in turn can be used to skip or loop. It can run in its own js worker. This streamed data is currently scheduled in 1s chunks in back-to-back AudioBufferSourceNodes to emulate an audio queue with gapless playback. While it works (and is fun!), I'm really looking forward to replacing that with a streaming decode audio buffer api and audio worklets. If anyone in the working group is interested, I'd be happy to demo the whole use case and the code to better illustrate the problem we're trying to solve and the api's we ended up writing. |
Someone asked me to explain a bit more about the Soundtrap javascript audio codec library we use internally. The audio codec library is written in dart / javascript / web assembly. It does not handle any networking aspect of the decoding / encoding, but it works on typed arrays (e.g. Float32Array and UInt8Array). These could come from the network, from memory or from indexed db, so they work in a variety of use cases. There are some abstractions in the api to allow for flexibility in implementation, pluggability and the language used. AudioCodec It acts as a pluggable registry so we can implement and register codecs in AudioCodec independently of any client code asking to use the codecs. AudioDecoder and StreamingAudioDecoder Implementations AudioEncoder and StreamingAudioEncoder As can be seen from the example above, the returned decoder is searchable, since you can specify offset and length for the decodeChunk(). This allows us to loop audio while playing back in a gapless fashion. A limitation of the example above is that all encoded data is passed in the constructor, which prevents streaming from the network, and leads to waste of memory. A future version will replace the "bytes" argument with something like the Streams API, agnostic of memory / network / disk, where the encoded data stream can be searched and read in order to support the decodeChunk() call. e.g. |
@nums I'm writing a demo and providing code examples for decoding audio in chunks with Streams. This started as a proof of concept to bypass the current limitation of @bjornm I took your advice and started with WAV decoding since it's easier and this is my first experience coding with audio. Good foresight. |
Here's a JavaScript Ogg Opus decoder that uses Wasm and |
This will now be handled by https://discourse.wicg.io/t/webcodecs-proposal/3662 |
This comment was marked as off-topic.
This comment was marked as off-topic.
Almost certainly. The argument for implementing it directly within decodeAudioData() would be the significant performance benefit you'd get, relative to implementing stream filtering based upon certain file stream tags, with repeated calls to decodeAudioData() to achieve the same effect.
We used the same approach to achieve streaming (partial download) segmented decoding of MP3 files, but network performance variability rendered any buffering that can be implemented at the JS level, insufficient, to achieve reliable audio playback without drops and other artifacts. As such, it need to be implemented at a lower level, within the API, where more reliable buffering can be achieved. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Please have this discussion elsewhere, thanks. |
This comment was marked as off-topic.
This comment was marked as off-topic.
New feature requests go in the v2 repo. New feature requests about audio decoding and encoding go in the Web Codecs repo, but this is use-case has been handled from day one there. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I still don't understand how to decode partial audio data. Can someone help? |
You can't with You will have to do it yourself. WebCodecs will help here, I think. |
Tried to use WebCodecs today to do this with WebCodecs (unfortunately failing so far), and posted w3c/webcodecs#366 about my findings so far. Any help there would be appreciated! |
Hello,
When we want to use it for audio streaming like media source api : https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html
The DecodeAudioData does not work when trying to decode a partial content while the audio tag play very well this content.
example : http://dashif.org/reference/players/javascript/0.2.0/index.html
The text was updated successfully, but these errors were encountered: