Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Consider using static buffers?#8

Answeredbypschatzmann
stevstrong asked this question inQ&A
Discussion options

In my applications I always prefer to use static buffers instead of dynamically allocate them.
This has the advantage of having a clear memory map from the beginning, and avoid possible crashes during runtime due to fragmented heap.

In particular, it wold be possible to declare the buffers statically in the header files.

In a similar way, the buffers inlibelix-mp3/buffers.c could be also statically declared, so no need to callmalloc whenallocateBuffers() is called.

Furthermore, one could also simplify the functions maxFrameSize() andmaxPCMSize(), because themax_frame_size andmax_pcm_size could be initialized at the time the MP3 instance is created, so the check if they are 0 could be avoided.

You must be logged in to vote

I opened the discussion folder since you are posting questions which are not really bugs.

Static buffers have their merits, if you have an application that is supposed to to this one thing.
However I prefer to have the flexibility to play and support multiple audio files fromdifferent decoders and then it is more important to be able to release the memory again.

It is also a question of what processors you are working with. Todays ESP32 and RP2040 have enough RAM that we can afford not to bother too much about this

Replies: 3 comments

Comment options

I opened the discussion folder since you are posting questions which are not really bugs.

Static buffers have their merits, if you have an application that is supposed to to this one thing.
However I prefer to have the flexibility to play and support multiple audio files fromdifferent decoders and then it is more important to be able to release the memory again.

It is also a question of what processors you are working with. Todays ESP32 and RP2040 have enough RAM that we can afford not to bother too much about this

You must be logged in to vote
0 replies
Answer selected bypschatzmann
Comment options

I can follow you, using different decoders at different times would eventually benefit from dynamic allocation.

The question is how often you create an object and then destroy it. If yo do it often, well, then the heap can become de-fragmented quickly.

Supposing you have a music player which has to support several audio types. Then you select one file and play it. You will then create a different instance each time you play a file, and then destroy that instance after playback has finished. And maybe other instances from other libs have been also created meanwhile. Playback 20 files and your heap can already suffer...

On the other hand there are not so many differentcommon audio file types supported. Maybe 4 (MP3, AAC, WAV, OGG)? Then in worst case you have statically allocated buffers for all 4 formats. No problem, also because, as you pointed out, modern MCUs have enough RAM.
Nevertheless, most people want to playback only MP3 (because of their reduced size on portable mediums), and/or eventually AAC.

The largest buffers are anyway those involved to stream out the PCM data to I2S or over SPI (preferably via DMA).

I ran several times into memory issues dues to "new" usage. Most INO examples of Arduino libraries will work, you run that simple example and think everything is fine. Then you build an application around it, create several times an instance in the background, destroy it in the background (and you don't know about it), and after a time (minutes, hours) your app will crash, and wonder why...

And I didn't even mention yet RTOSes.

You must be logged in to vote
0 replies
Comment options

As you can see mylist of supported encoders and decoders and is quite big.

But feel free to provide a pull request with some additional compile options.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@stevstrong@pschatzmann
Converted from issue

This discussion was converted from issue #7 on February 23, 2024 14:27.


[8]ページ先頭

©2009-2025 Movatter.jp