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.
  • SylverReZ @ SylverReZ:
    @Jayro, I don't see whats so special about the DS ML, its just a DS lite in a phat shell. At least the phat model had louder speakers, whereas the lite has a much better screen.
    +1
  • SylverReZ @ SylverReZ:
    They probably said "Hey, why not we combine the two together and make a 'new' DS to sell".
  • Veho @ Veho:
    It's a DS Lite in a slightly bigger DS Lite shell.
    +1
  • Veho @ Veho:
    It's not a Nintendo / iQue official product, it's a 3rd party custom.
    +1
  • Veho @ Veho:
    Nothing special about it other than it's more comfortable than the Lite
    for people with beefy hands.
    +1
  • Jayro @ Jayro:
    I have yaoi anime hands, very lorge but slender.
  • Jayro @ Jayro:
    I'm Slenderman.
  • Veho @ Veho:
    I have hands.
  • BakerMan @ BakerMan:
    imagine not having hands, cringe
    +1
  • AncientBoi @ AncientBoi:
    ESPECIALLY for things I do to myself :sad:.. :tpi::rofl2: Or others :shy::blush::evil:
    +1
  • The Real Jdbye @ The Real Jdbye:
    @SylverReZ if you could find a v5 DS ML you would have the best of both worlds since the v5 units had the same backlight brightness levels as the DS Lite unlockable with flashme
  • The Real Jdbye @ The Real Jdbye:
    but that's a long shot
  • The Real Jdbye @ The Real Jdbye:
    i think only the red mario kart edition phat was v5
  • BigOnYa @ BigOnYa:
    A woman with no arms and no legs was sitting on a beach. A man comes along and the woman says, "I've never been hugged before." So the man feels bad and hugs her. She says "Well i've also never been kissed before." So he gives her a kiss on the cheek. She says "Well I've also never been fucked before." So the man picks her up, and throws her in the ocean and says "Now you're fucked."
    +2
  • BakerMan @ BakerMan:
    lmao
  • BakerMan @ BakerMan:
    anyways, we need to re-normalize physical media

    if i didn't want my games to be permanent, then i'd rent them
    +1
  • BigOnYa @ BigOnYa:
    Agreed, that why I try to buy all my games on disc, Xbox anyways. Switch games (which I pirate tbh) don't matter much, I stay offline 24/7 anyways.
  • AncientBoi @ AncientBoi:
    I don't pirate them, I Use Them :mellow:. Like I do @BigOnYa 's couch :tpi::evil::rofl2:
    +1
  • cearp @ cearp:
    @BakerMan - you can still "own" digital media, arguably easier and better than physical since you can make copies and backups, as much as you like.

    The issue is DRM
  • cearp @ cearp:
    You can buy drm free games / music / ebooks, and if you keep backups of your data (like documents and family photos etc), then you shouldn't lose the game. but with a disk, your toddler could put it in the toaster and there goes your $60

    :rofl2:
  • cearp @ cearp:
    still, I agree physical media is nice to have. just pointing out the issue is drm
  • rqkaiju2 @ rqkaiju2:
    i like physical media because it actually feels like you own it. thats why i plan on burning music to cds
  • cearp @ cearp:
    It's nice to not have to have a lot of physical things though, saves space
    +1
    cearp @ cearp: It's nice to not have to have a lot of physical things though, saves space +1