Coder Social home page Coder Social logo

Byte slice to int16 slice. about opus HOT 2 CLOSED

hraban avatar hraban commented on July 20, 2024
Byte slice to int16 slice.

from opus.

Comments (2)

hraban avatar hraban commented on July 20, 2024

Hi @Lighty0410 :)

I'm surprised by that API. PCM data is not bytes, it's (signed) int16 or float32. I don't know this lib, but I did some digging, and it casts the char * pcm buffer to a INT_PCM * type array here: https://github.com/winlinvip/go-fdkaac/blob/2654f5a0cc2e3e9584a0c7f5ccae9d64f3bf957d/fdkaac/dec.go#L127

If you look at the backing C library, it defines INT_PCM as a SHORT here: https://github.com/mstorsjo/fdk-aac/blob/f285813ec15e7c6f8e4839c9eb4f6b0cd2da1990/libSYS/include/machine_type.h#L226 , which is a "Data type representing 2 byte signed integer on all supported".

Basically, this is a raw pointer cast without checking the byte order. I don't think this is safe, and even if it were, it's unnecessary, because they could just accept an int16[] instead of a byte[] to begin with and do away with the cast.

Honestly you're probably best off forking this lib, fixing the API and removing that cast. You can always submit a PR, see if they want it.

While you're at it, I would advise removing the allocation of the pcm buffer in the wrapper lib. You want the user of the lib to pass their buffer to your decoder (like the underlying C library does, and io.Reader, and this lib). This allows you to allocate once and reuse that buffer over and over again. See https://github.com/winlinvip/go-fdkaac/blob/2654f5a0cc2e3e9584a0c7f5ccae9d64f3bf957d/fdkaac/dec.go#L361 .

Good luck!

from opus.

hraban avatar hraban commented on July 20, 2024

Closing this ticket.

from opus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.