Repository navigation
feat(OpusEncoder): add encodeFloat and decodeFloat - #232
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
Expose opus_encode_float and opus_decode_float so audio can be handled as 32-bit floating point PCM instead of signed 16-bit integers. - encodeFloat() accepts a Buffer or Float32Array of interleaved samples. The samples are copied into an aligned scratch vector first, since Buffers (e.g. pooled ones) aren't guaranteed to be 4-byte aligned, and oversized inputs are rejected before copying. - decodeFloat() decodes into a lazily allocated float buffer, so encoders that never use it don't pay for the extra memory, and returns a Buffer of little-endian float32 samples. - Both methods validate their input and report libopus errors the same way as encode() and decode(). Adds tests, typings and a README example. close discordjs#171
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
encodeFloat()anddecodeFloat()toOpusEncoder, exposingopus_encode_floatandopus_decode_floatso audio can be processed as 32-bit floating point PCM instead of 16-bit integers.encodeFloat(buf)takes aBufferorFloat32Arrayof interleaved samples and returns the Opus packet. The samples are copied into an aligned scratch vector before encoding, because Buffers (e.g. pooled ones) aren't guaranteed to be 4-byte aligned, and inputs longer than the maximum Opus frame are rejected before copying.decodeFloat(buf)returns aBufferof little-endian float32 samples. The output buffer is allocated lazily on first use, so encoders that only use the 16-bit API don't pay for the extra memory.encode()/decode().encode()/decode()behaviour is unchanged.Tests, typings and a README example are included. The tests check that the float output matches the 16-bit output to within one 16-bit step, that
Float32Arrayand unalignedBufferinputs work, and that the error paths throw.Fixes #171