-
Notifications
You must be signed in to change notification settings - Fork 18
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
Is there a way to output Float32Array
instead of UInt16Array
?
#12
Comments
The decoder isn't actually doing any conversion here, and that's the issue you're running into. You're getting a Uint16Array because your original data was 16-bit. Pass in, for instance, and Opus file and you'll get 32-bit floats; you'll get different data types depending on your input format. To get libav to give you an arbitrary format of your choosing, you need to filter it. See, for instance
|
Oh, by the way, I think the reason you were losing information with your simple conversion is that whatever your input format was was in unsigned int, so you would actually want (inputArray[i] - 32768) / 32768, but letting libav do the filter itself is still usually the better way. |
@Yahweasel Thank you so much for the help 🥹! Using the However, it was interleaved data instead of planar data, but isolating the two channels was easy enough 😁💪
|
You can, in fact, have libav deinterleave as well. Use FLTP instead of FLT, and it'll be a Float32Array[] instead of a Float32Array. By sheer coincidence, I recently had to write some code that does the same thing, so if you'd like another example, here's one: https://github.com/ennuicastr/rtennui/blob/f3b5167cba63fc546d318773752bfe13aa2325d1/src/audio-capture.ts#L364 |
I'm using the
decode
function from this test.It seems like
ret.data
(ret
being aLibAVJS.Frame
) always generates someUInt16Array
. I think this is causing my data to have a distorted bass, which can be caused by the loss of low-frequency information when converting fromUInt16Array
toFloat32Array
😶I'm using this snippet I found for conversion:
Is there a way to tell the lib to output
[Float32Array, Float32Array]
forret.data
?The lib seems to have this constant
AV_SAMPLE_FMT_FLT: number;
, but I'm unsure if it's useful or where to use it 😁Thanks in advance for any guidance you might provide 😊🙏
Edit 1
I need
Float32Array
because apparently, that's what the Web Audio API expects (e.g. channel data for anAudioBuffer
)The text was updated successfully, but these errors were encountered: