minimp3-rs icon indicating copy to clipboard operation
minimp3-rs copied to clipboard

Support re-use of a single preallocated pcm buffer

Open udoprog opened this issue 3 years ago • 1 comments

This adds the following structures and methods:

  • Pcm which is a user provided collection allocated to the size of MAX_SAMPLES_PER_FRAME that dereferences to its stored pcm data &[i16].
  • FrameInfo which just contains the frame header parts of the frame, excluding the data.
  • next_frame_with_pcm which allows for decoding the frame data in-place a previously allocated Pcm structure.
  • next_frame_with_pcm_future async version of next_frame_into.

This allows a caller to preallocate and re-use a single pcm buffer so it doesn't have to be allocated on each call to next_frame to avoid its allocation overhead.

The naming is preliminary, suggestions are welcome!

udoprog avatar Mar 25 '21 03:03 udoprog

Thanks. I was not a fan of allocating on every single frame either. I'll take a look :smiley:

germangb avatar Mar 25 '21 10:03 germangb