Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ESP32-audioI2S
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ESP32-audioI2S
Commits
bdace928
Unverified
Commit
bdace928
authored
Feb 14, 2022
by
Wolle
Committed by
GitHub
Feb 14, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #283 from seife/devel
mp3_decoder: make sure data ends up in internal RAM
parents
cda882a9
3c3a5757
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
40 deletions
+16
-40
src/mp3_decoder/mp3_decoder.cpp
src/mp3_decoder/mp3_decoder.cpp
+16
-40
No files found.
src/mp3_decoder/mp3_decoder.cpp
View file @
bdace928
...
...
@@ -1490,8 +1490,6 @@ int MP3Decode( unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize)
*
* Return: none
*
* Notes: if one or more mallocs fail, function frees any buffers already
* allocated before returning
**********************************************************************************************************************/
void
MP3Decoder_ClearBuffer
(
void
)
{
...
...
@@ -1525,54 +1523,32 @@ void MP3Decoder_ClearBuffer(void) {
* Return: pointer to MP3DecInfo structure (initialized with pointers to all
* the internal buffers needed for decoding)
*
* Notes: if one or more mallocs fail, function frees any buffers already
* allocated before returning
*
**********************************************************************************************************************/
/* the default is to allocate everything over 4k preferably in PSRAM, see components/heap/heap_caps.c in esp-idf
* but we prefer internal RAM as it is faster */
#define __malloc_heap_psram(size) \
heap_caps_malloc_prefer
(
size
,
2
,
MALLOC_CAP_DEFAULT
|
MALLOC_CAP_INTERNAL
,
MALLOC_CAP_DEFAULT
|
MALLOC_CAP_SPIRAM
)
bool
MP3Decoder_AllocateBuffers
(
void
)
{
// try first SRAM because its faster than PSRAM
if
(
!
m_MP3DecInfo
)
{
m_MP3DecInfo
=
(
MP3DecInfo_t
*
)
malloc
(
sizeof
(
MP3DecInfo_t
)
);}
if
(
!
m_FrameHeader
)
{
m_FrameHeader
=
(
FrameHeader_t
*
)
malloc
(
sizeof
(
FrameHeader_t
)
);}
if
(
!
m_SideInfo
)
{
m_SideInfo
=
(
SideInfo_t
*
)
malloc
(
sizeof
(
SideInfo_t
)
);}
if
(
!
m_ScaleFactorJS
)
{
m_ScaleFactorJS
=
(
ScaleFactorJS_t
*
)
malloc
(
sizeof
(
ScaleFactorJS_t
));}
if
(
!
m_HuffmanInfo
)
{
m_HuffmanInfo
=
(
HuffmanInfo_t
*
)
malloc
(
sizeof
(
HuffmanInfo_t
)
);}
if
(
!
m_DequantInfo
)
{
m_DequantInfo
=
(
DequantInfo_t
*
)
malloc
(
sizeof
(
DequantInfo_t
)
);}
if
(
!
m_IMDCTInfo
)
{
m_IMDCTInfo
=
(
IMDCTInfo_t
*
)
malloc
(
sizeof
(
IMDCTInfo_t
)
);}
if
(
!
m_SubbandInfo
)
{
m_SubbandInfo
=
(
SubbandInfo_t
*
)
malloc
(
sizeof
(
SubbandInfo_t
)
);}
if
(
!
m_MP3FrameInfo
)
{
m_MP3FrameInfo
=
(
MP3FrameInfo_t
*
)
malloc
(
sizeof
(
MP3FrameInfo_t
)
);}
if
(
!
m_MP3DecInfo
)
{
m_MP3DecInfo
=
(
MP3DecInfo_t
*
)
__malloc_heap_psram
(
sizeof
(
MP3DecInfo_t
)
);}
if
(
!
m_FrameHeader
)
{
m_FrameHeader
=
(
FrameHeader_t
*
)
__malloc_heap_psram
(
sizeof
(
FrameHeader_t
)
);}
if
(
!
m_SideInfo
)
{
m_SideInfo
=
(
SideInfo_t
*
)
__malloc_heap_psram
(
sizeof
(
SideInfo_t
)
);}
if
(
!
m_ScaleFactorJS
)
{
m_ScaleFactorJS
=
(
ScaleFactorJS_t
*
)
__malloc_heap_psram
(
sizeof
(
ScaleFactorJS_t
));}
if
(
!
m_HuffmanInfo
)
{
m_HuffmanInfo
=
(
HuffmanInfo_t
*
)
__malloc_heap_psram
(
sizeof
(
HuffmanInfo_t
)
);}
if
(
!
m_DequantInfo
)
{
m_DequantInfo
=
(
DequantInfo_t
*
)
__malloc_heap_psram
(
sizeof
(
DequantInfo_t
)
);}
if
(
!
m_IMDCTInfo
)
{
m_IMDCTInfo
=
(
IMDCTInfo_t
*
)
__malloc_heap_psram
(
sizeof
(
IMDCTInfo_t
)
);}
if
(
!
m_SubbandInfo
)
{
m_SubbandInfo
=
(
SubbandInfo_t
*
)
__malloc_heap_psram
(
sizeof
(
SubbandInfo_t
)
);}
if
(
!
m_MP3FrameInfo
)
{
m_MP3FrameInfo
=
(
MP3FrameInfo_t
*
)
__malloc_heap_psram
(
sizeof
(
MP3FrameInfo_t
)
);}
if
(
!
m_MP3DecInfo
||
!
m_FrameHeader
||
!
m_SideInfo
||
!
m_ScaleFactorJS
||
!
m_HuffmanInfo
||
!
m_DequantInfo
||
!
m_IMDCTInfo
||
!
m_SubbandInfo
||
!
m_MP3FrameInfo
)
{
log_i
(
"heap is too small, try PSRAM"
);
MP3Decoder_FreeBuffers
();
}
else
{
MP3Decoder_ClearBuffer
();
return
true
;
// success, all buffers allocated in SRAM (Heap)
}
if
(
psramFound
())
{
// PSRAM found, Buffer will be allocated in PSRAM
if
(
!
m_MP3DecInfo
)
{
m_MP3DecInfo
=
(
MP3DecInfo_t
*
)
ps_calloc
(
sizeof
(
MP3DecInfo_t
)
,
sizeof
(
uint8_t
));}
if
(
!
m_FrameHeader
)
{
m_FrameHeader
=
(
FrameHeader_t
*
)
ps_calloc
(
sizeof
(
FrameHeader_t
)
,
sizeof
(
uint8_t
));}
if
(
!
m_SideInfo
)
{
m_SideInfo
=
(
SideInfo_t
*
)
ps_calloc
(
sizeof
(
SideInfo_t
)
,
sizeof
(
uint8_t
));}
if
(
!
m_ScaleFactorJS
)
{
m_ScaleFactorJS
=
(
ScaleFactorJS_t
*
)
ps_calloc
(
sizeof
(
ScaleFactorJS_t
),
sizeof
(
uint8_t
));}
if
(
!
m_HuffmanInfo
)
{
m_HuffmanInfo
=
(
HuffmanInfo_t
*
)
ps_calloc
(
sizeof
(
HuffmanInfo_t
)
,
sizeof
(
uint8_t
));}
if
(
!
m_DequantInfo
)
{
m_DequantInfo
=
(
DequantInfo_t
*
)
ps_calloc
(
sizeof
(
DequantInfo_t
)
,
sizeof
(
uint8_t
));}
if
(
!
m_IMDCTInfo
)
{
m_IMDCTInfo
=
(
IMDCTInfo_t
*
)
ps_calloc
(
sizeof
(
IMDCTInfo_t
)
,
sizeof
(
uint8_t
));}
if
(
!
m_SubbandInfo
)
{
m_SubbandInfo
=
(
SubbandInfo_t
*
)
ps_calloc
(
sizeof
(
SubbandInfo_t
)
,
sizeof
(
uint8_t
));}
if
(
!
m_MP3FrameInfo
)
{
m_MP3FrameInfo
=
(
MP3FrameInfo_t
*
)
ps_calloc
(
sizeof
(
MP3FrameInfo_t
)
,
sizeof
(
uint8_t
));}
}
else
{
log_e
(
"not enough memory to allocate mp3decoder buffers"
);
return
false
;
}
if
(
!
m_MP3DecInfo
||
!
m_FrameHeader
||
!
m_SideInfo
||
!
m_ScaleFactorJS
||
!
m_HuffmanInfo
||
!
m_DequantInfo
||
!
m_IMDCTInfo
||
!
m_SubbandInfo
||
!
m_MP3FrameInfo
)
{
log_e
(
"not enough memory to allocate mp3decoder buffers in PSRAM"
);
return
false
;
}
MP3Decoder_ClearBuffer
();
return
true
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment