The game freezes when mp3 audios need to be loaded

batboil

Member
OP
Newcomer
Joined
Feb 16, 2023
Messages
6
Trophies
0
Age
21
Location
Zagreb
XP
28
Country
Croatia
I made a simple pong clone that uses grrlib for graphics and font rendering and all I'm left with is the sound which after hours of fiddling with it finally worked... except the game froze every time the sound was supposed to be heard. I'm just a beginner when it comes to Wii programming so it's probably some stupid mistake I can't find.

Here is the code in c : //include/define #include <grrlib.h> #include <ogcsys.h> #include <gccore.h> #include <stdlib.h> #include <wiiuse/wpad.h> #include <stdio.h> #include "FreeMonoBold_ttf.h" #include "pong_mp3.h" #include <gcmodplay.h> #include <asndlib.h> #include <mp3player.h> #define WHITE 0xFFFFFFFF #define BLACK 0x000000FF #define MAROON 0x800000FF #define GREEN 0x008000FF #define OLIVE 0x808000FF #define NAVY 0x000080FF #define PURPLE 0x800080FF #define EAL 0x008080FF #define GRAY 0x808080FF #define SILVER 0xC0C0C0FF #define RED 0xFF0000FF #define LIME 0x00FF00FF #define YELLOW 0xFFFF00FF #define BLUE 0x0000FFFF #define FUCHSIA 0xFF00FFFF #define AQUA 0x00FFFFFF #define scrwidth 640 //screen width #define scrhight 528 //screen hight #define rectwidth 5 //rectangle width #define recthight 50 //rectangle hight #define rectspacing 5 //rectangle spacing (space between rectangles and borders) #define rectspeed 5 //speed of rectangles #define ballwidth 30 //width of ball int main(int argc, char **argv) { GRRLIB_Init(); WPAD_Init(); ASND_Init(); MP3Player_Init(); GRRLIB_SetBackgroundColour(255,255,255,255); GRRLIB_ttfFont *myFont = GRRLIB_LoadTTF(FreeMonoBold_ttf, FreeMonoBold_ttf_size); int p1y=scrhight/2-recthight/2; int p1points=0; int p2y=scrhight/2-recthight/2; int p2points=0; int lasttouchx=1; int lasttouchy=1; int bx=scrwidth/2-ballwidth/2; int by=scrhight/2-ballwidth/2; char p1pointst[255]; char p2pointst[255]; char debug[255]; int ballspeedy = 3; int ballspeedx =3; int onerepeat=0; int playsound=0; while(1) { if(onerepeat==0){ ballspeedy++; ballspeedx++; onerepeat++; } WPAD_ScanPads(); u16 buttonsdown = WPAD_ButtonsHeld(0); if (buttonsdown & WPAD_BUTTON_HOME) break; GRRLIB_Rectangle(rectspacing,p1y,rectwidth,recthight,GRAY,255); GRRLIB_Rectangle(scrwidth-(rectwidth+rectspacing),p2y,rectwidth,recthight,GRAY,255); GRRLIB_Rectangle(bx,by,ballwidth,ballwidth,GRAY,255); if ((buttonsdown & WPAD_BUTTON_RIGHT) && p1y<scrhight-(recthight*2)-rectspacing) p1y+=rectspeed; if ((buttonsdown & WPAD_BUTTON_LEFT) && p1y>rectspacing) p1y-=rectspeed; //move player 1 up when left button is pressed if ((buttonsdown & WPAD_BUTTON_PLUS) && p2y<scrhight-(recthight*2)-rectspacing) p2y+=rectspeed; if ((buttonsdown & WPAD_BUTTON_MINUS) && p2y>rectspacing) p2y-=rectspeed; if(GRRLIB_RectOnRect(rectspacing,p1y,rectwidth,recthight,bx,by,ballwidth,ballwidth)==true){ lasttouchx=1; ballspeedy=rand() % 6; if(ballspeedy<1){ while (ballspeedy<1) { ballspeedy=rand() % 6; } } ballspeedx=rand() % 10; if(ballspeedx<3){ while (ballspeedx<3) { ballspeedx=rand() % 10; } } playsound=1; } if(GRRLIB_RectOnRect(scrwidth-(rectwidth+rectspacing),p2y,rectwidth,recthight,bx,by,ballwidth,ballwidth)==true){ lasttouchx=0; ballspeedy=rand() % 6; if(ballspeedy<1){ while (ballspeedy<1) { ballspeedy=rand() % 6; } } ballspeedx=rand() % 10; if(ballspeedx<3){ while (ballspeedx<3) { ballspeedx=rand() % 10; } } playsound=1; } if(by>scrhight-(ballwidth*2.5)){ lasttouchy=0; } if(by<0){ lasttouchy=1; } if(lasttouchy==1) by+=ballspeedy; if(lasttouchy==0) by-=ballspeedy; if(lasttouchx==1){ bx+=ballspeedx; } if(lasttouchx==0){ bx-=ballspeedx; } if(bx+ballwidth>=scrwidth){ bx=scrwidth/2-ballwidth/2; by=scrhight/2-ballwidth/2; p1points++; lasttouchx=0; ballspeedx=3; ballspeedy=0; } if(bx<=0){ bx=scrwidth/2-ballwidth/2; by=scrhight/2-ballwidth/2; p2points++; lasttouchx=1; ballspeedx=3; ballspeedy=0; } snprintf(p1pointst, sizeof(p1pointst), "PLAYER ONE:%d", p1points); GRRLIB_PrintfTTF(scrwidth/2-123, 5, myFont, p1pointst, 12, BLACK); snprintf(p2pointst, sizeof(p2pointst), "PLAYER TWO:%d", p2points); GRRLIB_PrintfTTF(scrwidth/2+30, 5, myFont, p2pointst, 12, BLACK); snprintf(debug, sizeof(debug), "debug:%d", MP3Player_IsPlaying()); GRRLIB_PrintfTTF(scrwidth/2-300, 5, myFont, debug, 12, BLACK); if(playsound==1){ while(MP3Player_IsPlaying()==0){ MP3Player_PlayBuffer(pong_mp3,pong_mp3_size,NULL); } playsound=0; } GRRLIB_Render(); } GRRLIB_Exit(); ASND_End(); exit(0); } //end


and a makefile: #--------------------------------------------------------------------------------- # Clear the implicit built in rules #--------------------------------------------------------------------------------- .SUFFIXES: #--------------------------------------------------------------------------------- ifeq ($(strip $(DEVKITPPC)),) $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>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 source/gfx DATA := data INCLUDES := #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) CXXFLAGS = $(CFLAGS) #LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--section-start,.init=0x81000000 #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- LIBS := -lgrrlib -lfreetype -lbz2 -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lmodplay -lmad -lbte -lasnd -logc -lm -lgrrlib #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- LIBDIRS := $(CURDIR)/$(GRRLIB) $(PORTLIBS) #--------------------------------------------------------------------------------- # 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_BIN := $(addsuffix .o,$(BINFILES)) export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) #--------------------------------------------------------------------------------- # build a list of include paths #--------------------------------------------------------------------------------- export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ -I$(CURDIR)/$(BUILD) \ -I$(LIBOGC_INC) #--------------------------------------------------------------------------------- # build a list of library paths #--------------------------------------------------------------------------------- export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/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: wiiload $(TARGET).dol #--------------------------------------------------------------------------------- else DEPENDS := $(OFILES:.o=.d) #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- $(OUTPUT).dol: $(OUTPUT).elf $(OUTPUT).elf: $(OFILES) $(OFILES_SOURCES) : $(HFILES) #--------------------------------------------------------------------------------- # This rule links in binary data with the .png extension #--------------------------------------------------------------------------------- %.png.o : %.png #--------------------------------------------------------------------------------- @echo $(notdir $<) $(bin2o) #--------------------------------------------------------------------------------- # This rule links in binary data with the .ttf extension #--------------------------------------------------------------------------------- %.ttf.o : %.ttf #--------------------------------------------------------------------------------- @echo $(notdir $<) $(bin2o) #--------------------------------------------------------------------------------- # This rule links in binary data with the .ogg extension #--------------------------------------------------------------------------------- %.ogg.o %_ogg.h : %.ogg #--------------------------------------------------------------------------------- @echo $(notdir $<) $(bin2o) #--------------------------------------------------------------------------------- # This rule links in binary data with the .mp3 extension #--------------------------------------------------------------------------------- %.mp3.o %_mp3.h : %.mp3 @echo $(notdir $<) $(bin2o) #--------------------------------------------------------------------------------- -include $(DEPENDS) #--------------------------------------------------------------------------------- endif #---------------------------------------------------------------------------------
 

batboil

Member
OP
Newcomer
Joined
Feb 16, 2023
Messages
6
Trophies
0
Age
21
Location
Zagreb
XP
28
Country
Croatia
so after a lot of research I think the problem is that the mp3 sounds are too compressed so the wii should stop and take its time before playing the sound. Of course, this could all be wrong, but that's how I understood it. I also found sources that state that the ogg file alternative is better. as far as I understand, it is necessary to install the tremor that I found when I started the oggplayer example in devkitpro and it threw out the pacman command that needed to be started in the command prompt, and after that I started the oggplayer example and it worked perfectly well. now i'm working on implementing the ogg player in my pong project so wish me luck! ;)
Post automatically merged:

update:

IT WORKSSSSSSSS!!!! after suffering so much for an ordinary sound!!! I will post the source code with comments and the app itself after my mental health improves!
Post automatically merged:

Here is the app and the source code in google drive: click here
 
Last edited by batboil,
  • Like
Reactions: CMDreamer

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: @ShantaeFan123, ken is just being ken