Skip to content

Commit aee66b2

Browse files
committed
espressif: use custom allocator for MP3Decoder data
1 parent 7af2a13 commit aee66b2

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2024 Jeff Epler for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <stdlib.h>
28+
#include "py/mpprint.h"
29+
#include "esp_heap_caps.h"
30+
#include "shared-module/audiomp3/__init__.h"
31+
#include "supervisor/port_heap.h"
32+
33+
void *mp3_alloc(size_t sz) {
34+
void *ptr = heap_caps_malloc(sz, MALLOC_CAP_8BIT);
35+
mp_printf(&mp_plat_print, "alloc(%d) -> %ptr\n", (int)sz, ptr);
36+
return ptr;
37+
}
38+
39+
void mp3_free(void *ptr) {
40+
mp_printf(&mp_plat_print, "free(%p)\n", ptr);
41+
heap_caps_free(ptr);
42+
}

ports/espressif/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,6 @@ USB_NUM_IN_ENDPOINTS = 5
179179
# Usually lots of flash space available
180180
CIRCUITPY_MESSAGE_COMPRESSION_LEVEL ?= 1
181181

182+
# Don't enable mp3 by default but DO allocate it to on-chip RAM if enabled
182183
CIRCUITPY_AUDIOMP3 ?= 0
184+
CIRCUITPY_AUDIOMP3_USE_PORT_ALLOCATOR ?= 1

0 commit comments

Comments
 (0)