Giter Club home page Giter Club logo

rinimp3's Introduction

rinimp3

An attempt to make a port of lieff's minimp3 to Rust. The goal is basically to make the minimp3-rs crate, bindings to the C library, unnecessary.

<<<<<<< HEAD There is a write-up of the translation process here.

First step is to just duplicate it as closely as possible, including passing its tests and fuzzing. Next step would be to smooth its API out and make it more Rusty; https://github.com/germangb/minimp3-rs might be useful for inspiration.

First step is to just duplicate it as closely as possible, including passing its tests and fuzzing. https://wiki.alopex.li/PortingCToRust comments on the conversion. Next step would be to smooth its API out and make it more Rusty; https://github.com/germangb/minimp3-rs might be useful for inspiration.

e2500fd001aaf5ba07ed0acad3e3d41144a65ff1

Current status: about 90% translated, but there's still some panics lurking in the test cases. I need to find a nice few days and just finish it off.

Differences from minimp3:

  • i16 output only
  • No SIMD
  • No conditional compilation -- basically should operate as if the following flags are defined:
  • #define MINIMP3_NO_SIMD
  • #define MINIMP3_NONSTANDARD_BUT_LOGICAL???

rinimp3's People

Contributors

boomshroom avatar icefoxen avatar mestake avatar skierpage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rinimp3's Issues

merge with alternative port

hello @icefoxen,
I read your blog post when it appeared on Reddit a while back, and decided to also try to port minimp3.
The result is here.

I have no long term plans for maintaining it, since it was more of a learning experience. However, I saw your crate on crates.io, so I decided to see if you want to merge our ports.

This isn't a pull request since the repositories don't share any common base, but I am willing to help if you need any.

impossible borrows in `l3_restore_reservoir`

From boomshroom, reported here: https://www.reddit.com/r/rust/comments/9mioiv/porting_c_to_rust_a_case_study_minimp3/

I've run into a major problem in l3_restore_reservoir. While moving some functions into methods, I noticed one last unsafe I hadn't caught in mp3dec_decode_frame that was trying to subvert the borrow checker for for a Mp3DecScratch. You noticed there was a problem both by the fact that you had to use unsafe, and also the fact that you noticed something fishy with the lifetimes in the function signature.
What's going on here is that Mp3DecScratch contains a Bs, which itself contains a slice reference. In l3_restore_reservoir, you initialize the maindata array in Mp3DecScratch and then pass a reference to that to a new Bs which then gets stored in Mp3DecScratch. Long story short, Mp3DecScratch contains a reference to another field of itself.
This might not seem like much, but it's a huge deal in Rust for several reasons. For one, since maindata is being borrowed by the Bs, that spreads to the rest of the struct, making the entire struct immutable until it dies. Since l3_restore_reservoir takes it by a mutable reference, the compiler doesn't know that that field is no longer being modified and instead locks down the struct entirely.
There's also a separate issue in that normally, structs are allowed to be moved anywhere they please. You can move a value from the stack onto the heap and back again for instance. Since Mp3DecScratch contains a reference to one of its fields, a simple move like this would fail to update the reference and would instead point at the old location. The solution to this would unfortunately require heap allocation, so the array doesn't move with the struct, or the unstable Pin api, which allows you to specify that the struct isn't allowed to move at all. The big issue with that is that it requires the nightly compiler. If you want this to be available without std, then heap allocation isn't available at all without the alloc crate, which is also nightly exclusive.

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.