修改部分调试打印代码

This commit is contained in:
wangyz1997 2024-04-10 16:29:48 +08:00
parent fafa916aca
commit a315492cc2
5 changed files with 52 additions and 42 deletions

View File

@ -9,16 +9,6 @@ add_subdirectory(Third_Party/fatfs)
add_subdirectory(Third_Party/dr_libs) add_subdirectory(Third_Party/dr_libs)
add_subdirectory(Third_Party/tlsf) add_subdirectory(Third_Party/tlsf)
#
# target_compile_options(FLAC PRIVATE
# -Wformat=0
# -Wno-incompatible-pointer-types
# )
# target_compile_options(grabbag PRIVATE
# -Wformat=0
# )
# target_compile_options(lvgl_demos PRIVATE # target_compile_options(lvgl_demos PRIVATE
# -Wformat=0 # -Wformat=0
# ) # )

View File

@ -13,11 +13,11 @@ const static char *TAG = "audio_flac";
static size_t flac_read(void* pUserData, void* pBufferOut, size_t bytesToRead) static size_t flac_read(void* pUserData, void* pBufferOut, size_t bytesToRead)
{ {
HAL_GPIO_TogglePin(LED_Y_GPIO_Port, LED_Y_Pin);
UINT br; UINT br;
FRESULT f_result = f_read(pUserData, pBufferOut, bytesToRead, &br); //从文件中读取新的内容 FRESULT f_result = f_read(pUserData, pBufferOut, bytesToRead, &br); //从文件中读取新的内容
HAL_GPIO_TogglePin(LED_Y_GPIO_Port, LED_Y_Pin);
if (f_result != FR_OK) { if (f_result != FR_OK) {
elog_error(TAG, "file read error"); elog_error(TAG, "file read error");
return 0; return 0;
@ -62,12 +62,17 @@ static void* flac_malloc(size_t sz, void* pUserData)
{ {
UNUSED(pUserData); UNUSED(pUserData);
if (sz == 0) {
return NULL;
}
void *ptr = malloc(sz); void *ptr = malloc(sz);
// tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics(); tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics();
// tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics(); tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics();
// elog_debug(TAG, "flac_malloc: allocated %d bytes memory @%p, free memory: AXI %d bytes, AHB %d bytes", elog_debug(TAG, "flac_malloc: allocated %d bytes memory @%p, free memory: AXI %d bytes, AHB %d bytes",
// sz, ptr, axi_heap_statistics->free_size, ahb_heap_statistics->free_size); sz, ptr, axi_heap_statistics->free_size, ahb_heap_statistics->free_size);
if (ptr == NULL) { if (ptr == NULL) {
elog_error(TAG, "flac_malloc: error while allocating %d bytes of memory", sz); elog_error(TAG, "flac_malloc: error while allocating %d bytes of memory", sz);
} }
@ -81,6 +86,11 @@ static void* flac_realloc(void* p, size_t sz, void* pUserData)
void *ptr = realloc(p, sz); void *ptr = realloc(p, sz);
tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics();
tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics();
elog_debug(TAG, "flac_realloc: allocated %d bytes new memory @%p, free memory: AXI %d bytes, AHB %d bytes",
sz, ptr, axi_heap_statistics->free_size, ahb_heap_statistics->free_size);
if (ptr == NULL) { if (ptr == NULL) {
elog_error(TAG, "flac_realloc: error while allocating %d bytes of new memory", sz); elog_error(TAG, "flac_realloc: error while allocating %d bytes of new memory", sz);
} }
@ -92,10 +102,14 @@ static void flac_free(void* p, void* pUserData)
{ {
UNUSED(pUserData); UNUSED(pUserData);
// tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics(); if (p == NULL) {
// tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics(); return;
// elog_debug(TAG, "flac_free: memory freed @%p, free memory: AXI %d bytes, AHB %d bytes", }
// p, axi_heap_statistics->free_size, ahb_heap_statistics->free_size);
tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics();
tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics();
elog_debug(TAG, "flac_free: memory freed @%p, free memory: AXI %d bytes, AHB %d bytes",
p, axi_heap_statistics->free_size, ahb_heap_statistics->free_size);
free(p); free(p);
} }

View File

@ -9,7 +9,7 @@
static const char *TAG = "audio_hal"; static const char *TAG = "audio_hal";
typedef struct { typedef struct {
void *buffer_ptr; const void *buffer_ptr;
uint32_t buffer_size; uint32_t buffer_size;
} audio_sample_t; } audio_sample_t;
@ -86,7 +86,7 @@ void audio_hal_stop(void)
audio_buffer = NULL; audio_buffer = NULL;
} }
void audio_hal_write(void *buffer_ptr, uint32_t buffer_size) void audio_hal_write(const void *buffer_ptr, uint32_t buffer_size)
{ {
if (buffer_size == 0) { if (buffer_size == 0) {
return; return;

View File

@ -7,6 +7,6 @@
void audio_hal_start(uint32_t sample_count, uint8_t sample_size); void audio_hal_start(uint32_t sample_count, uint8_t sample_size);
void audio_hal_stop(void); void audio_hal_stop(void);
void audio_hal_write(void *buffer, uint32_t sample_count); void audio_hal_write(const void *buffer, uint32_t sample_count);
#endif #endif

View File

@ -12,11 +12,11 @@ const static char *TAG = "player_mp3";
static size_t mp3_read(void* pUserData, void* pBufferOut, size_t bytesToRead) static size_t mp3_read(void* pUserData, void* pBufferOut, size_t bytesToRead)
{ {
HAL_GPIO_TogglePin(LED_Y_GPIO_Port, LED_Y_Pin);
UINT br; UINT br;
FRESULT f_result = f_read(pUserData, pBufferOut, bytesToRead, &br); //从文件中读取新的内容 FRESULT f_result = f_read(pUserData, pBufferOut, bytesToRead, &br); //从文件中读取新的内容
HAL_GPIO_TogglePin(LED_Y_GPIO_Port, LED_Y_Pin);
if (f_result != FR_OK) { if (f_result != FR_OK) {
elog_error(TAG, "file read error"); elog_error(TAG, "file read error");
return 0; return 0;
@ -62,12 +62,17 @@ static void* mp3_malloc(size_t sz, void* pUserData)
{ {
UNUSED(pUserData); UNUSED(pUserData);
if (sz == 0) {
return NULL;
}
void *ptr = malloc(sz); void *ptr = malloc(sz);
// tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics(); tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics();
// tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics(); tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics();
// elog_debug(TAG, "mp3_malloc: allocated %d bytes memory @%p, free memory: AXI %d bytes, AHB %d bytes", elog_debug(TAG, "mp3_malloc: allocated %d bytes memory @%p, free memory: AXI %d bytes, AHB %d bytes",
// sz, ptr, axi_heap_statistics->free_size, ahb_heap_statistics->free_size); sz, ptr, axi_heap_statistics->free_size, ahb_heap_statistics->free_size);
if (ptr == NULL) { if (ptr == NULL) {
elog_error(TAG, "mp3_malloc: error while allocating %d bytes of memory", sz); elog_error(TAG, "mp3_malloc: error while allocating %d bytes of memory", sz);
} }
@ -81,6 +86,11 @@ static void* mp3_realloc(void* p, size_t sz, void* pUserData)
void *ptr = realloc(p, sz); void *ptr = realloc(p, sz);
tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics();
tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics();
elog_debug(TAG, "mp3_realloc: allocated %d bytes new memory @%p, free memory: AXI %d bytes, AHB %d bytes",
sz, ptr, axi_heap_statistics->free_size, ahb_heap_statistics->free_size);
if (ptr == NULL) { if (ptr == NULL) {
elog_error(TAG, "mp3_realloc: error while allocating %d bytes of new memory", sz); elog_error(TAG, "mp3_realloc: error while allocating %d bytes of new memory", sz);
} }
@ -92,10 +102,14 @@ static void mp3_free(void* p, void* pUserData)
{ {
UNUSED(pUserData); UNUSED(pUserData);
// tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics(); if (p == NULL) {
// tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics(); return;
// elog_debug(TAG, "mp3_free: memory freed @%p, free memory: AXI %d bytes, AHB %d bytes", }
// p, axi_heap_statistics->free_size, ahb_heap_statistics->free_size);
tlsf_pool_statistics *axi_heap_statistics = get_axi_heap_statistics();
tlsf_pool_statistics *ahb_heap_statistics = get_ahb_heap_statistics();
elog_debug(TAG, "mp3_free: memory freed @%p, free memory: AXI %d bytes, AHB %d bytes",
p, axi_heap_statistics->free_size, ahb_heap_statistics->free_size);
free(p); free(p);
} }
@ -107,14 +121,6 @@ static const drmp3_allocation_callbacks mp3_allocation_cbs = {
.pUserData = NULL .pUserData = NULL
}; };
/**
* @brief MP3文件
*
* @param file_name
* @return esp_err_t
*
* @note 25600
*/
void music_mp3_play(const char *file_name) void music_mp3_play(const char *file_name)
{ {
FIL *file = malloc(sizeof(FIL)); FIL *file = malloc(sizeof(FIL));
@ -154,7 +160,7 @@ void music_mp3_play(const char *file_name)
uint32_t sample_count = drmp3_read_pcm_frames_s16(&mp3, DRMP3_MAX_PCM_FRAMES_PER_MP3_FRAME, pcm_sample); //解码新一帧MP3数据 uint32_t sample_count = drmp3_read_pcm_frames_s16(&mp3, DRMP3_MAX_PCM_FRAMES_PER_MP3_FRAME, pcm_sample); //解码新一帧MP3数据
if (sample_count != 0) { if (sample_count != 0) {
audio_hal_write(pcm_sample, DRMP3_MAX_SAMPLES_PER_FRAME * sizeof(drmp3_int16)); ///将解码后的PCM数据写入SAI audio_hal_write(pcm_sample, DRMP3_MAX_SAMPLES_PER_FRAME * sizeof(drmp3_int16)); //将解码后的PCM数据写入SAI
} else { } else {
free(pcm_sample); free(pcm_sample);
elog_info(TAG, "play done"); elog_info(TAG, "play done");