Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixes for JEplayer #2445

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

Merged
merged 9 commits into from
Jan 8, 2020
Merged

Fixes for JEplayer #2445

merged 9 commits into from
Jan 8, 2020

Conversation

jepler
Copy link

@jepler jepler commented Jan 2, 2020

This

  • fixes DMA hangs by taking an upstream update
  • makes MP3File objects reusable, eliminating out of memory errors
  • adds an "rms_level" property so we can animate some neopixels

This enables jeplayer to allocate just one MP3File at startup, rather
than have to make repeated large allocations while the application is
running.

The buffers have to be allocated their theoretical maximum, but that
doesn't matter much as all the real-life MP3 files I checked needed
that much allocation anyway.
After adding the ability to change files in an existing MP3File object,
it became apparent that at the beginning of a track some part of an
existing buffer was playing first.

I noticed that in get_buffer, the just-populated buffer wasn't being
returned, but the other one was.  But still after fixing this, I heard
wrong audio at the beginning of a track, so I took the heavy duty approach
and zeroed the buffers out.  That means there's a remaining bug to chase,
which is merely hidden by the memset()s.
This lets a music player show it vu-meter style
@jepler jepler requested a review from tannewt January 3, 2020 14:29
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why allow changing the filename? Can't you avoid OOM by passing in a shared bytearray buffer into the constructor?

@jepler
Copy link
Author

jepler commented Jan 3, 2020

Yes, I could, but it would ultimately be more finicky. There are a BUNCH of separate memory allocations, and writing a mini-allocator to make them come out of a passed in block didn't seem like a good use of time.

  • disk I/O buffer
  • sample buffers
  • main mp3 decoder object
  • 7 internal pointers in mp3 decoder object

@tannewt
Copy link
Member

tannewt commented Jan 3, 2020

You don't need to allocate everything out of that block, you just need to allocate the things that are hard to reallocate.

I'm wary of this change because it breaks the mental model of one MP3File per file. It'd be more of a MP3Decoder at that point. That may be ok but I feel like there may be a way to make the allocations more reliable instead.

@jepler
Copy link
Author

jepler commented Jan 3, 2020

There are at least 5 allocations each bigger than 1kB, the biggest is over 8kB. What threshold would you consider for being "hard to allocate"?

@jepler
Copy link
Author

jepler commented Jan 3, 2020

fwiw in arudino, where of course it is a compile-time decision whether to use MP3 or not, they found it was reasonable to just statically allocate 1 playback object rather than do the allocations dynamically.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! Thank you!

@tannewt tannewt merged commit a10cd85 into adafruit:master Jan 8, 2020
@jepler jepler deleted the mp3-jeplayer-fixes branch November 3, 2021 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants