Welcome! Log In Create A New Profile

Advanced

MP3 Player

Posted by Keeley 
MP3 Player
September 07, 2009 07:22PM
Hey Guys, this is my first time trying to code an MP3 Player following a tut and I've ran into a couple problems that I can't seem to fix.
( I'm a complete noob when it comes to coding but I wanna be a coder as a occupation so mind as well start early )

Here's my main.c:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
	
	MP3Player_Init();
	
	VIDEO_Init();

	WPAD_Init();

	rmode = VIDEO_GetPreferredMode(NULL);

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

	VIDEO_Configure(rmode);

	VIDEO_SetNextFramebuffer(xfb);

	VIDEO_SetBlack(FALSE);

	VIDEO_Flush();

	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 


	FILE *BGM = 0;//This will store an MP3 on the SD Card
	long lSize;//This will store the size of the FILE BGM
	char * buffer;//This is our buffer that will take the place of the external MP3
	size_t result;//This is the size of the buffer
	bool mp3isready = false;//This keeps the music from trying to loop before the buffer is made
	
	void LoopTheMP3();
	
	mp3isready = false;//Keeps LoopTheMP3() from working before the buffer is ready

	BGM = fopen("sd:/MUSIC/bgm.mp3", "rb");
	
	fseek (BGM , 0 , SEEK_END);
	lSize = ftell (BGM);
	rewind (BGM);//Return to the beginning of the MP3 for good measure

	buffer = (char*) malloc (sizeof(char)*lSize);//Allocate memory to contain the whole file
	result = fread (buffer,1,lSize,BGM);//Copy the file into the buffer
	
	fclose(BGM);//Since we no longer need BGM, get rid of it
	MP3Player_PlayBuffer(buffer, lSize, NULL);//Play the buffer
	mp3isready = true;//Let LoopTheMP3() know it can start working
	
	free(buffer);
	
	void LoopTheMP3() {

	if(mp3isready && !MP3Player_IsPlaying())
	MP3Player_PlayBuffer(buffer, lSize, NULL);

}
 
    printf("MP3Player/n");
	printf("First Attempt/n");

	while(1) {
	
	WPAD_ScanPads();
	
	u32 ButtonsDown = WPAD_ButtonsDown(0);
	
	if (ButtonsDown & WPAD_BUTTON_HOME) {
			exit(0);
		}
	}
 
	return 0;
}

And here's my Makefile:

#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC)
endif

include $(DEVKITPPC)/wii_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET		:=	$(notdir $(CURDIR))
BUILD		:=	build
SOURCES		:=	source
DATA		:=	data  
INCLUDES	:=	include

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------

CFLAGS	= -g -O2 -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS	=	$(CFLAGS)

LDFLAGS	=	-g $(MACHDEP) -Wl,-Map,$(notdir $@).map

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS	:=	-lwiiuse -lbte -logc -lm -lmad

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS	:=

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT	:=	$(CURDIR)/$(TARGET)

export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
					$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR	:=	$(CURDIR)/$(BUILD)

#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
	export LD	:=	$(CC)
else
	export LD	:=	$(CXX)
endif

export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
					$(sFILES:.s=.o) $(SFILES:.S=.o)

#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
					-I$(CURDIR)/$(BUILD) \
					-I$(LIBOGC_INC)

#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
					-L$(LIBOGC_LIB)

export OUTPUT	:=	$(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
	@[ -d $@ ] || mkdir -p $@
	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
	@echo clean ...
	@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol

#---------------------------------------------------------------------------------
run:
	psoload $(TARGET).dol

#---------------------------------------------------------------------------------
reload:
	psoload -r $(TARGET).dol


#---------------------------------------------------------------------------------
else

DEPENDS	:=	$(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .jpg extension
#---------------------------------------------------------------------------------
%.jpg.o	:	%.jpg
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
# This rule links in binary data
#---------------------------------------------------------------------------------
%.bin.o	:	%.bin
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	@$(bin2o)

%.mod.o	:	%.mod
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	@$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

So when I try to compile it I get the following errors,

> "make"
main.c
c:/devkitPro/examples/wii/MP3/source/main.c: In function 'main':
c:/devkitPro/examples/wii/MP3/source/main.c:66: error: static declaration of 'LoopTheMP3' follows non-static declaration
c:/devkitPro/examples/wii/MP3/source/main.c:47: error: previous declaration of 'LoopTheMP3' was here
make[1]: *** [main.o] Error 1
"make": *** [build] Error 2

I hope you guys can help me fix them!
Re: MP3 Player
September 07, 2009 08:35PM
couple problems that i can see...

	void LoopTheMP3() {

	if(mp3isready && !MP3Player_IsPlaying())
	MP3Player_PlayBuffer(buffer, lSize, NULL);

}

needs to be above all the times you call for it... so put it above int main() {

then remove this line:

void LoopTheMP3();

and make it:

LoopTheMP3();

and it probably needs to go inside the while loop for it to do what you want it to do.
Re: MP3 Player
September 07, 2009 08:37PM
Why is void LoopTheMP3() inside main() ?

There are a ton of issues with your code. I really don't know where to start. Are you learning C right now? If so I would start out with something a little easier. BTW the mp3 functions don't work all that well and I'd not recommend you start with trying to make an mp3 player on Wii.
Re: MP3 Player
September 07, 2009 08:42PM
yeah there are a lot more issues than what i noted...

you'll hvae to move the definition of all those variables above the void LoopTheMP3 function.... and i don't see how the mp3isready switches from false to true properly. You just set it true with no condition for it to have to meet before it IS true...
Re: MP3 Player
September 08, 2009 03:59AM
Oh wow thanks guys for the fast replies I'm gonna try it out

@scanff

Yeah I just started as you and mdbrim noted there are many problems :p maybe I should start something easier...



Edited 1 time(s). Last edit at 09/08/2009 04:07AM by Keeley.
Re: MP3 Player
September 08, 2009 05:08AM
Hello World

:D
Re: MP3 Player
September 08, 2009 06:00AM
I got that down now, following to Codemii tuts on Tut 4 now ( so confusing xD ) :p while following cplusplus.com,

Hey is there any what to make the text a different font?



Edited 1 time(s). Last edit at 09/08/2009 06:02AM by Keeley.
Re: MP3 Player
September 08, 2009 11:00PM
Quote
scanff
BTW the mp3 functions don't work all that well and I'd not recommend you start with trying to make an mp3 player on Wii.
Yes, the only repeatedly reliable method (that I know of) to play external MP3s is here: [arikadosblog.blogspot.com]
Re: MP3 Player
September 09, 2009 08:30PM
Quote

Hey is there any what to make the text a different font?

Not that I know of using the console. Usually you'll use a bitmap font or a TTF library to change fonts.
Sorry, only registered users may post in this forum.

Click here to login