-
Notifications
You must be signed in to change notification settings - Fork 0
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
Async encode/decode, and encoding an AudioBuffer #1
Comments
For the async question, and about loading the library from a worker, it looks like I'm thinking in the right direction.
So it sounds useful if there's an async and non-blocking wrapper for the library, as long as the data being passed to and from the worker is a transferable object like ArrayBuffer. The library wasm-audio-decoders mentioned earlier actually has both sync/async APIs.
|
About the sample rate, I found the answer in the Opus codec manual.
That makes sense why |
Hello, thank you for creating this library. I had some questions about how to use it.
From what I understand in
wasm/index.js
, the encode/decode functions are synchronous and they block the main thread in browser/node. Is that true?If so, is it possible to load this library from a worker, to make it async/non-blocking? I'll see if I can achieve it and report back here if successful.
Looking at other similar libraries, wasm-media-encoders, wasm-audio-decoders, and opusscript, I see their API is synchronous and blocking also. ffmpeg.wasm and lame-wasm are async.
That's interesting because I would have expected, for most purposes, async encode/decode is preferred for both browser and server side, so as not to block the main thread. For example, how
AudioContext.decodeAudioData()
works.Currently, I'm encountering some difficulties trying to encode (and decode back) an instance of AudioBuffer.
First, I noticed that if the sample rate is
44100
, the Encoder/Decoder constructor throws an error,opus: invalid argument
.If I force it to
48000
, it doesn't throw.Next, I learned how to extract PCM data from an AudioBuffer using
getChannelData()
.When I pass a channel's data to
encode()
, it throwsRangeError: source array is too long
.The error is from the first line of
RawEncoder.encode()
in@evan/wasm/target/opus/deno.js
...So I should convert my
Float32Array
to anUint8Array
before passing it to encode. Is that correct?The conversion seems to work, but still results in the same error,
RangeError: source array is too long
.EDIT: I'm guessing it's because I set the wrong sample rate when instantiating the encoder. And probably it's impossible (or unwise, haha) to try to up-scale from 44.1 to 48 kHz.
Well, I'll try to figure out these questions on my own, but if you have any thoughts, I'd appreciate it.
The text was updated successfully, but these errors were encountered: