Skip to content

Commit

Permalink
audiolite/worker/mp3dec: Support Kconfig options to build mp3dec worker
Browse files Browse the repository at this point in the history
Make building mp3dec worker option be selected in Kconfig option.
And add debug message by using worker printf.
  • Loading branch information
SPRESENSE committed Nov 5, 2024
1 parent 52ff862 commit 88a5fbf
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 47 deletions.
40 changes: 38 additions & 2 deletions sdk/modules/audiolite/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,46 @@ config AIDO_LITE_MP3DEC_SUBCORE_ELFNAME
set "/mnt/sd0/mp3dec".
To enable this option, needs to enable EXTERNALS_CMSIS, ASMP and ASMP_WORKER_LIBC

endif # end of if AUDIO_LITE_MP3DEC

endif # AUDIO_LITE_MP3DEC_SUBCORE_ELF

if AUDIO_LITE_MP3DEC_SUBCORE_SPK

config AUDIO_LITE_MP3DEC_SUBCORE_SPK_BUILD
bool "Build mp3dec spk"
default n
---help---
Enable build SPK file named "mp3dec.spk" in sdk/modules/audiolite/worker/mp3dec directory.
If you want to use your built mp3dec.spk, you need flash it like
$ ./tools/flash.sh modules/audiolite/worker/mp3dec/mp3dec.spk

endif # AUDIO_LITE_MP3DEC_SUBCORE_SPK

if AUDIO_LITE_MP3DEC_SUBCORE_ELF || AUDIO_LITE_MP3DEC_SUBCORE_SPK_BUILD

config AUDIO_LITE_MP3DEC_SUBCORE_DEBUG
bool "Enable Debug print in mo3dec Worker"
default n
---help---
Enable display debug message from mp3dec worker. This debug message pass to UART1.
And it is expected that the HW initialization has finished by main core.
If you want to change it from UART1 to others, modify it in a source code.
This makes that the worker takes long time to print information. So realtime playing
will be stopped.

if AUDIO_LITE_MP3DEC_SUBCORE_DEBUG

config AUDIO_LITE_MP3DEC_SUBCORE_DEBUG_DETAIL
bool "Enable print detail information of mo3dec Worker"
default n
---help---
Enable display buffer status and pointer.

endif # AUDIO_LITE_MP3DEC_SUBCORE_DEBUG

endif # AUDIO_LITE_MP3DEC_SUBCORE_ELF || AUDIO_LITE_MP3DEC_SUBCORE_SPK_BUILD

endif # end of if AUDIO_LITE_MP3DEC

endmenu # MP3 Decorder Component

endif # end of if AUDIO_LITE
Expand Down
8 changes: 3 additions & 5 deletions sdk/modules/audiolite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

# Set 1 FORACE_WORKER_BUILD when you want to make spk

FORCE_WORKER_BUILD =

MODNAME = audiolite
CXXEXT = .cxx

Expand Down Expand Up @@ -66,20 +64,20 @@ CXXFLAGS += -I include -DBUILD_TGT_SUPERVISOR

ifneq ($(CONFIG_AUDIO_LITE_MP3DEC_SUBCORE_ELF),)
CSRCS += dummy.c
else ifeq ($(FORCE_WORKER_BUILD),1)
else ifeq ($(CONFIG_AUDIO_LITE_MP3DEC_SUBCORE_SPK_BUILD),y)
CSRCS += dummy.c
endif

include $(SDKDIR)/modules/Module.mk

.PHONY: build_mp3dec
build_mp3dec:
@$(MAKE) -C worker/mp3dec TOPDIR="$(TOPDIR)" SDKDIR="$(SDKDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) FORCE_BUILD=$(FORCE_WORKER_BUILD)
@$(MAKE) -C worker/mp3dec TOPDIR="$(TOPDIR)" SDKDIR="$(SDKDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV)

dummy.c: build_mp3dec

clean_mp3dec:
@$(MAKE) -C worker/mp3dec TOPDIR="$(TOPDIR)" SDKDIR="$(SDKDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) FORCE_BUILD=$(FORCE_WORKER_BUILD) clean
@$(MAKE) -C worker/mp3dec TOPDIR="$(TOPDIR)" SDKDIR="$(SDKDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) clean

clean:: clean_mp3dec

4 changes: 3 additions & 1 deletion sdk/modules/audiolite/worker/common/alworker_comm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* modules/audiolite/worker/mp3dec/al_comm_comm.c
* modules/audiolite/worker/common/alworker_comm.c
*
* Copyright 2023 Sony Semiconductor Solutions Corporation
*
Expand Down Expand Up @@ -81,7 +81,9 @@ void *alworker_addr_convert(void *a)

int initialize_alworker(al_wtask_t *inst, const char *dspfname, bool is_spk)
{
#ifndef BUILD_TGT_ASMPWORKER
int ret;
#endif
key_t key = AL_COMM_MQ_NAMESEND;
cpuid_t cid = 0;

Expand Down
38 changes: 37 additions & 1 deletion sdk/modules/audiolite/worker/mp3dec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include $(APPDIR)/Make.defs

ifeq ($(CONFIG_AUDIO_LITE_MP3DEC_SUBCORE_ELF),y)
BUILD_EXECUTE = 1
else ifeq ($(FORCE_BUILD),1)
else ifeq ($(CONFIG_AUDIO_LITE_MP3DEC_SUBCORE_SPK_BUILD),y)
BUILD_EXECUTE = 1
else
BUILD_EXECUTE = 0
Expand All @@ -47,7 +47,22 @@ endif
ifeq ($(BUILD_EXECUTE),1)

BIN = mp3dec
SPK = $(BIN).spk

ifeq ($(CONFIG_AUDIO_LITE_MP3DEC_SUBCORE_ELF),y)
all: depend $(BIN)
endif

ifeq ($(CONFIG_AUDIO_LITE_MP3DEC_SUBCORE_SPK_BUILD),y)
all: depend $(SPK)
endif

# For SPK tools

MKSPK_TOOLDIR = $(TOPDIR)/tools/cxd56
MKSPK_MKFILE = $(MKSPK_TOOLDIR)/Makefile.host
MKSPK_TOOL = $(MKSPK_TOOLDIR)/mkspk
MKSPK_TOOL_OPT = -c 2

# Setup to build and linking worker support library

Expand All @@ -73,6 +88,7 @@ MINIMP3_DIR = ../ext_libs/minimp3
SPEEXDSP_DIR = ../ext_libs/speexdsp_resample

CSRCS = entry.c mp3dec_main.c
CSRCS += sprmp3_debug.c
CSRCS += sprmp3_msghandler.c
CSRCS += sprmp3_sendback.c
CSRCS += alworker_comm.c
Expand All @@ -81,11 +97,21 @@ CSRCS += minimp3_ex.c
CSRCS += resample.c
CFLAGS += -DUSE_CMSIS -DBUILD_TGT_ASMPWORKER

ifneq ($(CONFIG_AUDIO_LITE_MP3DEC_SUBCORE_DEBUG),)
CFLAGS += -DSPRMP3_DEBUG
ifneq ($(CONFIG_AUDIO_LITE_MP3DEC_SUBCORE_DEBUG_DETAIL),)
CFLAGS += -DSPRMP3_DEBUG_DETAIL
endif
endif

VPATH = $(COMMON_DIR) $(MINIMP3_DIR) $(SPEEXDSP_DIR)

DELTGT_FILES = $(CSRCS:.c=.o)

ARCHSRCDIR = $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src

INCDIRS = $(COMMON_DIR) $(MINIMP3_DIR) $(SPEEXDSP_DIR) $(AUDIOLITE_DIR)/../include
INCDIRS += $(ARCHSRCDIR)$(DELIM)chip $(ARCHSRCDIR)$(DELIM)common

CFLAGS += -O3
ifeq ($(WINTOOL),y)
Expand Down Expand Up @@ -116,10 +142,20 @@ $(BIN): $(COBJS) $(AOBJS) | $(WORKER_LIB) $(CMSIS_DSP_LIB)
$(Q) cp $(BIN) $(BIN).debug.elf
$(Q) $(STRIP) -d $(BIN)

$(MKSPK_TOOL):
@$(MAKE) -C $(MKSPK_TOOLDIR) -f $(MKSPK_MKFILE) TOPDIR="$(TOPDIR)"

# SDKDIR="$(SDKDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV)

$(SPK): $(MKSPK_TOOL) $(BIN)
@echo "MKSPK: $@"
$(MKSPK_TOOL) $(MKSPK_TOOL_OPT) $(BIN) $(BIN) $(SPK)

clean:
$(call DELFILE, $(BIN))
$(call DELFILE, $(BIN).debug.elf)
$(call DELFILE, $(DELTGT_FILES))
$(call DELFILE, $(SPK))
$(call CLEAN)

ROOTDEPPATH = --dep-path . $(foreach d,$(INCDIRS), --dep-path $(d))
Expand Down
23 changes: 2 additions & 21 deletions sdk/modules/audiolite/worker/mp3dec/mp3dec_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
#include "sprmp3_msghandler.h"
#include "sprmp3_sendback.h"

#ifdef SPRMP3_DEBUG
#include "sprmp3_debug.h"
#endif

#ifdef ENABME_PERFORMANCE
#include <stdio.h>
Expand Down Expand Up @@ -431,20 +429,16 @@ static int initialize_framecache(sprmp3_t *inst)

if (fill_tagsize(inst) == 0)
{
#ifdef SPRMP3_DEBUG
sprmp3_dprintf("fill_tagsize() error\n");
#endif
return SPRMP3_STATE_ERROR;
}

memset(&inst->frame_info, 0, sizeof(inst->frame_info));

if (inst->fcache.fillsize != MINIMP3_ID3_DETECT_SIZE)
{
#ifdef SPRMP3_DEBUG
sprmp3_dprintf("fillsize is not equal ID3 SIZE : %d\n",
inst->fcache.fillsize);
#endif
return SPRMP3_STATE_ERROR;
}

Expand Down Expand Up @@ -857,9 +851,7 @@ static int exec_decodestate(sprmp3_t *inst, sprmp3_outmemqueue_t *outq)
inst->tgtcache.decsize = inst->tgtcache.remofst;
outq->done |= SPRMP3_OUTDONE(inst);
inst->omem_wofst = 0;
#ifdef SPRMP3_DEBUG
sprmp3_dprintf("Force the decode finish.\n");
#endif
return SPRMP3_STATE_ENDING;
}
else
Expand Down Expand Up @@ -1198,47 +1190,36 @@ int mp3dec_main(void)
dbg_init_compare();
#endif

#ifdef SPRMP3_DEBUG
print_status(&g_sys);
#endif

send_bootmsg();
send_bootmsg(NULL);

while (g_sys.system_state != SPRMP3_SYSSTATE_TERM)
{
#ifdef SPRMP3_DEBUG
sprmp3_dprintf("\n::::::::: Start Loop ::::::::::\n");
#endif
print_status(&g_sys);
if (g_sys.system_state == SPRMP3_SYSSTATE_STOP)
{
sprmp3_pollmessage(&g_sys, 1);
}
else
{
sprmp3_pollmessage(&g_sys, 0);
#ifdef SPRMP3_DEBUG
print_status(&g_sys);
print_buffer_status(&g_sys);
#endif
if (g_sys.system_state != SPRMP3_SYSSTATE_TERM)
{
exec_playing(&g_sys);
#ifdef SPRMP3_DEBUG
print_buffer_status(&g_sys);
#endif
if (g_sys.system_state == SPRMP3_SYSSTATE_PAUSE ||
!exist_playing(g_sys.insts))
{
#ifdef SPRMP3_DEBUG
sprmp3_dprintf("Just Deliver PCM..\n");
#endif
deliver_outpcm(&g_sys.outqueue);
}
else
{
#ifdef SPRMP3_DEBUG
sprmp3_dprintf("Deliver PCM if possible..\n");
#endif
deliver_decodedpcm(g_sys.insts,
&g_sys.outqueue,
&g_sys.sys_gain,
Expand Down
19 changes: 13 additions & 6 deletions sdk/modules/audiolite/worker/mp3dec/sprmp3_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
* Included Files
****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#ifdef BUILD_TGT_ASMPWORKER
# include <asmp/stdio.h>
#else
# include <stdio.h>
#endif

#include "sprmp3_debug.h"

Expand All @@ -49,6 +52,8 @@
#ifdef SPRMP3_DEBUG

#ifdef SPRMP3_DEBUG_COMPARE
#include <stdlib.h>

static int dbg_framesz;
static int dbg_frame_ofst;
static unsigned char *dbg_mp3framemem;
Expand Down Expand Up @@ -102,7 +107,8 @@ int dbg_init_compare(void)
}
#endif

const char *inststatelog(int state)
#ifdef SPRMP3_DEBUG_DETAIL
static const char *inststatelog(int state)
{
switch (state)
{
Expand All @@ -120,7 +126,7 @@ const char *inststatelog(int state)
return "Unknown";
}

const char *statelog(int state)
static const char *statelog(int state)
{
switch (state)
{
Expand All @@ -142,13 +148,13 @@ void print_status(sprmp3_sys_t *sys)
inst = &sys->insts[0];

printf("==== System State : %s =====\n", statelog(sys->system_state));
printf(" OutQueue: Free:%ld, Queued:%ld\n",
printf(" OutQueue: Free:%d, Queued:%d \n",
sq_count(&sys->outqueue.free),
sq_count(&sys->outqueue.queued));

for (i = 0; i < SPRMP3_MAX_INSTANCE; i++)
{
printf(" Inst:%d Status:%s, Queue:<Free:%ld, Queued:%ld>,"
printf(" Inst:%d Status:%s, Queue:<Free:%d, Queued:%d>,"
" Gain:%f\n",
inst->id, inststatelog(inst->state),
sq_count(&inst->fqueue.free),
Expand Down Expand Up @@ -201,5 +207,6 @@ void print_buffer_status(sprmp3_sys_t *sys)
inst++;
}
}
#endif /* SPRMP3_DEBUG_DETAIL */

#endif /* SPRMP3_DEBUG */
30 changes: 26 additions & 4 deletions sdk/modules/audiolite/worker/mp3dec/sprmp3_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,29 @@
* Included Files
****************************************************************************/

#include <stdio.h>
#ifdef BUILD_TGT_ASMPWORKER
# include <asmp/stdio.h>
#else
# include <stdio.h>
#endif

#include "minimp3_spresense.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define sprmp3_dprintf(...) printf(__VA_ARGS__)
#ifdef SPRMP3_DEBUG
# define sprmp3_dprintf(...) printf(__VA_ARGS__)
# ifndef SPRMP3_DEBUG_DETAIL
# define print_status(s)
# define print_buffer_status(s)
# endif
#else
# define sprmp3_dprintf(...)
# define print_status(s)
# define print_buffer_status(s)
#endif

/****************************************************************************
* Public Function Prototypes
Expand All @@ -58,11 +73,18 @@ extern "C"
{
#endif /* __cplusplus */

#ifdef SPRMP3_DEBUG

#ifdef SPRMP3_DEBUG_COMPARE
int dbg_load_mp3frame(const char *fname, unsigned char **fmem);
const char *inststatelog(int state);
const char *statelog(int state);
#endif

#ifdef SPRMP3_DEBUG_DETAIL
void print_status(sprmp3_sys_t *sys);
void print_buffer_status(sprmp3_sys_t *sys);
#endif

#endif

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 88a5fbf

Please sign in to comment.