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
  • No one is chatting at the moment.
  • BakerMan @ BakerMan:
    i said i was sleeping...
  • BakerMan @ BakerMan:
    sleeping with uremum
  • K3Nv2 @ K3Nv2:
    Even my mum slept on that uremum
  • TwoSpikedHands @ TwoSpikedHands:
    yall im torn... ive been hacking away at tales of phantasia GBA (the USA version) and have so many documents of reverse engineering i've done
  • TwoSpikedHands @ TwoSpikedHands:
    I just found out that the EU version is better in literally every way, better sound quality, better lighting, and there's even a patch someone made to make the text look nicer
  • TwoSpikedHands @ TwoSpikedHands:
    Do I restart now using what i've learned on the EU version since it's a better overall experience? or do I continue with the US version since that is what ive been using, and if someone decides to play my hack, it would most likely be that version?
  • Sicklyboy @ Sicklyboy:
    @TwoSpikedHands, I'll preface this with the fact that I know nothing about the game, but, I think it depends on what your goals are. Are you trying to make a definitive version of the game? You may want to refocus your efforts on the EU version then. Or, are you trying to make a better US version? In which case, the only way to make a better US version is to keep on plugging away at that one ;)
  • Sicklyboy @ Sicklyboy:
    I'm not familiar with the technicalities of the differences between the two versions, but I'm wondering if at least some of those differences are things that you could port over to the US version in your patch without having to include copyrighted assets from the EU version
  • TwoSpikedHands @ TwoSpikedHands:
    @Sicklyboy I am wanting to fully change the game and bend it to my will lol. I would like to eventually have the ability to add more characters, enemies, even have a completely different story if i wanted. I already have the ability to change the tilemaps in the US version, so I can basically make my own map and warp to it in game - so I'm pretty far into it!
  • TwoSpikedHands @ TwoSpikedHands:
    I really would like to make a hack that I would enjoy playing, and maybe other people would too. swapping to the EU version would also mean my US friends could not legally play it
  • TwoSpikedHands @ TwoSpikedHands:
    I am definitely considering porting over some of the EU features without using the actual ROM itself, tbh that would probably be the best way to go about it... but i'm sad that the voice acting is so.... not good on the US version. May not be a way around that though
  • TwoSpikedHands @ TwoSpikedHands:
    I appreciate the insight!
  • The Real Jdbye @ The Real Jdbye:
    @TwoSpikedHands just switch, all the knowledge you learned still applies and most of the code and assets should be the same anyway
  • The Real Jdbye @ The Real Jdbye:
    and realistically they wouldn't

    be able to play it legally anyway since they need a ROM and they probably don't have the means to dump it themselves
  • The Real Jdbye @ The Real Jdbye:
    why the shit does the shitbox randomly insert newlines in my messages
  • Veho @ Veho:
    It does that when I edit a post.
  • Veho @ Veho:
    It inserts a newline in a random spot.
  • The Real Jdbye @ The Real Jdbye:
    never had that i don't think
  • Karma177 @ Karma177:
    do y'all think having an sd card that has a write speed of 700kb/s is a bad idea?
    trying to restore emunand rn but it's taking ages... (also when I finished the first time hekate decided to delete all my fucking files :wacko:)
  • The Real Jdbye @ The Real Jdbye:
    @Karma177 that sd card is 100% faulty so yes, its a bad idea
  • The Real Jdbye @ The Real Jdbye:
    even the slowest non-sdhc sd cards are a few MB/s
  • Karma177 @ Karma177:
    @The Real Jdbye it hasn't given me any error trying to write things on it so I don't really think it's faulty (pasted 40/50gb+ folders and no write errors)
  • DinohScene @ DinohScene:
    run h2testw on it
  • DinohScene @ DinohScene:
    when SD cards/microSD write speeds drop below a meg a sec, they're usually on the verge of dying
    DinohScene @ DinohScene: when SD cards/microSD write speeds drop below a meg a sec, they're usually on the verge of dying