Welcome! Log In Create A New Profile

Advanced

How to Play Sound and Video Files

Posted by Nicholas_Roge 
How to Play Sound and Video Files
June 11, 2009 06:27PM
I apologize if this has already been posted and replied to (if it has, I couldn't find it), but how would one go about playing .mp3's, .wav's, .avi's, .mov, etc... using homebrew? Also, rather than making a new thread, I have another (rather random) question. Is declaring
char characterVariable[20];
the same thing as calling
char characterVariable;
characterVariable=malloc(20*sizeof(char));
I'm a complete noob when it comes to pointers and memory management, so this probably isn't right.
Re: How to Play Sound and Video Files
June 11, 2009 06:56PM
Quote
Nicholas_Roge
I apologize if this has already been posted and replied to (if it has, I couldn't find it), but how would one go about playing .mp3's, .wav's, .avi's, .mov, etc... using homebrew? Also, rather than making a new thread, I have another (rather random) question. Is declaring
char characterVariable[20];
the same thing as calling
char characterVariable;
characterVariable=malloc(20*sizeof(char));
I'm a complete noob when it comes to pointers and memory management, so this probably isn't right.


char characterVariable;
characterVariable=malloc(20*sizeof(char));

characterVariable needs to be a pointer and there's no reason to multiply by size of char as it's 1. So the allocation needs to be.

char* characterVariable;
characterVariable = (char*)malloc(20);

both the char characterVariable[20] and malloc create storage for 20 bytes. the first allocates on the stack the malloc allocates onto the heap.


.mp3's, .wav's are supported by libogc. (Well PCM sound, which is a wav without the file header). Look at the asndlib.h and mp3player.h header files under the libogc directory.

I'm not sure about AVI's and MOV's are probably Apple's IP.
Re: How to Play Sound and Video Files
June 12, 2009 12:39AM
I recently spent hours trying to get libogc's mp3 player functions to work. If you have any problems, I'll check back and post if they're similar to the ones I had.

Seriously, when sounds finally came out, it was like that bit in Die Hard where they get the vault open.



Edited 1 time(s). Last edit at 06/12/2009 12:40AM by alainvey.
Re: How to Play Sound and Video Files
June 12, 2009 05:41AM
Well... An explanation of the functions, and what to pass to them would be nice, if you wouldn't mind... An example would be even better though.



Edited 1 time(s). Last edit at 06/12/2009 05:42AM by Nicholas_Roge.
Re: How to Play Sound and Video Files
June 12, 2009 10:10AM
Ok, I recommend reading the asndlib.h and mp3player.h files as scanff suggested, for a more complete listing of the available functions.

To get an mp3 working, just do this (this is from buffer only, search this subforum for "sound" to find tips of loading from SD/Fat):

Makefile:

include libs in the right order - my makefile has this, but you might not need all of these (png and jpeg, for example, though I think -lmad is the mp3 decoder, so keep that):

-lpng -ljpeg -lz -lwiiuse -lmodplay -lmad -lasnd -lbte -lfat -logc -lm


Then, add this to the end of your makefile:

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

-include $(DEPENDS)

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

That will make your compiler link the necessary files into object files.

Now, put the mp3 you wish to play into a "Data" folder in the root of your project (i.e same level as makefile and the folder, "source"). I will call it "song.mp3" for clarity.

add to your includes in your main app:
#include 
#include 
#include "song_mp3.h" //yes, the _mp3 is necessary.  This file is generated by the compiler.

I recommend just starting with the Hello World template until this works.

In your main function, add the following (after video init, if present in main function, and before wpad init - if not present in template, just put it after the Initialise(); call in the main function):

ASND_Init();
MP3Player_Init();

That initialises the sound functionality.

To play the file from buffer, then add this:

MP3Player_PlayBuffer (song_mp3, song_mp3_size, NULL); //just type exactly this.

If you used the Hello World template, the main function should now go round and round the while(1) loop until you press Home. The file will play until finished.

To stop it, call MP3Player_Stop();

Once you've got this working, then start playing around to call the function under the conditions you actually want. MP3Player_IsPlaying is a boolean value which you can use to check if an mp3 is playing or not (not a bad idea to do this before you call the PlayBuffer function).

If this doesn't work, let me know.



Edited 2 time(s). Last edit at 06/12/2009 10:12AM by alainvey.
Re: How to Play Sound and Video Files
June 12, 2009 03:18PM
how can i play files that are not buffers though?



Edited 2 time(s). Last edit at 06/12/2009 06:12PM by Arikado.
Re: How to Play Sound and Video Files
June 12, 2009 03:57PM
Quote
alainvey
(this is from buffer only, search this subforum for "sound" to find tips of loading from SD/Fat)

I'm not so sure, but during my searches last week I found several topics related to this. Try searching for "MP3" also. I encountered these posts originally by Googling "play mp3 devkitpro".
Re: How to Play Sound and Video Files
June 12, 2009 05:09PM
I found a post on the matter. But I am running into a problem. It's compiling with no errors or warnings, but when I go to load it, my television screen becomes a fuzzy green for a split second, and continues to the media player I'm working on. And my play button shows that the song is stopped.

Edit: I also seem to be getting consistant memory dumps after exiting.



Edited 1 time(s). Last edit at 06/12/2009 05:21PM by Nicholas_Roge.
Re: How to Play Sound and Video Files
June 12, 2009 06:11PM
MP3Player_PlayFile() can play external files.

Also, alainvey, AFAIK you dont need to call ASND_Init() or even include the asnd library at all to use mp3player.h.



Edited 1 time(s). Last edit at 06/12/2009 06:12PM by Arikado.
Re: How to Play Sound and Video Files
June 12, 2009 06:14PM
Quote
Arikado
MP3Player_PlayFile() can play external files.

Also, alainvey, AFAIK you dont need to call ASND_Init() or even include the asnd library at all to use mp3player.h.

But you should so that ASND is used :)

ASND is DSP accelerated.
Re: How to Play Sound and Video Files
June 12, 2009 07:06PM
I was just being overzealous with my includes, perhaps. Whatever had an unknown purpose I left in.

Speaking of Tantric, check out his libwiigui library. You can probably just hack a media player together from the template program, but if you'd find that unsatisfying then it still includes some decent media libraries.
Re: How to Play Sound and Video Files
June 12, 2009 07:31PM
Here's a really simple example of playing an mp3 from a file.

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

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
FILE* the_file = 0;


s32 reader_callback(void *fp,void *dat, s32 size)
{
	return fread(dat,  size, 1, the_file);
}

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

	fatInitDefault();
	
	// Initialise the video system
	VIDEO_Init();
	
	// This function initialises the attached controllers
	WPAD_Init();
	
	// Obtain the preferred video mode from the system
	// This will correspond to the settings in the Wii menu
	rmode = VIDEO_GetPreferredMode(NULL);

	// Allocate memory for the display in the uncached region
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	
	// Initialise the console, required for printf
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	
	// Set up the video registers with the chosen mode
	VIDEO_Configure(rmode);
	
	// Tell the video hardware where our display memory is
	VIDEO_SetNextFramebuffer(xfb);
	
	// Make the display visible
	VIDEO_SetBlack(FALSE);

	// Flush the video register changes to the hardware
	VIDEO_Flush();

	// Wait for Video setup to complete
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
	
	
    ASND_Init();
    MP3Player_Init();
	MP3Player_Volume(255);
	
	the_file = fopen("sd:/apps/test/1.mp3","r");
	if (!the_file) exit(0);
	
	MP3Player_PlayFile(the_file, reader_callback, 0);

	bool running = true;
	
	while(running) {

		// Call WPAD_ScanPads each loop, this reads the latest controller states
		WPAD_ScanPads();

		// WPAD_ButtonsDown tells us which buttons were pressed in this loop
		// this is a "one shot" state which will not fire again until the button has been released
		u32 pressed = WPAD_ButtonsDown(0);

		// We return to the launcher application via exit
		if ( pressed & WPAD_BUTTON_HOME ) running = false;

		// Wait for the next frame
		VIDEO_WaitVSync();
		
		
	}
	MP3Player_Stop();
	fclose(the_file);
	return 0;
}

Re: How to Play Sound and Video Files
June 12, 2009 11:16PM
I am ALMOST there. I've just got two more problems. I ran the mp3 in my program, and compiled the source you just posted verbatim (with the exception of changing the file location). The two problems I ran into, with both cases, is that it would act like it's playing the sound, but you couldn't hear anything. the second problem I ran into, is that in my program, when I pushed the A button anywhere, it would freeze the system, and the home button in your program did the same thing.
Re: How to Play Sound and Video Files
June 13, 2009 04:32AM
Make sure to call ASND_Pause(0); just in case, that turns on ASND
Re: How to Play Sound and Video Files
June 13, 2009 06:03AM
Here's my complete source (It still doesn't work):

main.c
#include "../../grrlib/GRRLIB/GRRLIB.h"

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <wiiuse/wpad.h>
#include <dirent.h>
#include <fat.h>

#include "gfx/console.h"
#include "gfx/cursor.h"
#include "colors.h"
#include "properties.h"
#include "additionalFunctions.h"
#include "asndlib.h"
#include "mp3player.h"

//char **artists.name;

Mtx GXmodelView2D;
ir_t ir;

DIR *pdir;
struct dirent *pent;
struct stat statbuf;

int centerTab(tab temp){
	return ((temp.width/2)-((strlen(temp.text)*(8*temp.fontSize))/2));
}
int centerChar(char temp[], int bGObjectWidth, int fontSize){
	return ((bGObjectWidth/2)-(((strlen(temp)*(8*fontSize))/2)));
}
int centerToScreenH(int widthOfObject){
	return (320-(widthOfObject/2));
}
int centerToScreenV(int heightOfObject){
	return (240-(heightOfObject/2));
}


void initializeArtists(){
	int index;
	char dir[40];

	pdir=opendir("SD:/MUSIC");
	
	while (((pent=readdir(pdir))!=NULL)&& artists.output<=(20*artists.page)) {
	    if(artists.output==0){
			strcpy(artists.name[artists.output],"All");
			artists.output++;
		}
		
		if(artists.output==20){
			strcpy(artists.name[artists.output],"<-- - or + -->");
			break;
		}
		
		stat(pent->d_name,&statbuf);
	    if(strcmp(".", pent->d_name) == 0 || strcmp("..", pent->d_name) == 0){
	        continue;
	    }else if(S_ISDIR(statbuf.st_mode)){
			if(strlen(pent->d_name)>40){
				for(index=0;index<=36;index++){
					dir[index]=pent->d_name[index];
				}
				for(;index<=39;index++){
					dir[index]='.';
				}
			}else{
				strcpy(dir,pent->d_name);
			}
			strcpy(artists.name[artists.output],dir);
	        artists.output++;
		}else if(!(S_ISDIR(statbuf.st_mode))){
	        continue;
		}
	}
	
	closedir(pdir);
}

void drawArtists(int leftMenuX, GRRLIB_texImg tex_console){
	int artistTitleHeight=150;
	int index;
	
	/*Selection Box*/
	
	for(index=0,artistTitleHeight=150;index<=20;index++,artistTitleHeight+=10){
		if(index==20){
			artistTitleHeight+=10;
		}
		GRRLIB_Printf(40+leftMenuX,artistTitleHeight, tex_console, black, 1, artists.name[index]);
	}
	/*pdir=opendir("SD:/MUSIC");
	while ((pent=readdir(pdir))!=NULL) {
	    stat(pent->d_name,&statbuf);
		
	    if(strcmp(".", pent->d_name) == 0 || strcmp("..", pent->d_name) == 0){
	        continue;
		}else if(S_ISDIR(statbuf.st_mode)){
	        GRRLIB_Printf(40+leftMenuX,artistTitleHeight, tex_console, black, 1, pent->d_name);//strcpy(artists.name,pent->d_name);
		}else if(!(S_ISDIR(statbuf.st_mode))){
	        continue;
		}
		
		artistTitleHeight+=10;
	}
	closedir(pdir);*/
}

void menuExit(int exitMenuSelection, GRRLIB_texImg tex_console){

	GRRLIB_Rectangle(centerToScreenH(500),centerToScreenV(340),500, 340, black, 1);
	GRRLIB_Rectangle(centerToScreenH(498),centerToScreenV(338),498, 338, grey, 1);
	
	GRRLIB_Printf(centerChar("Do you really want to Exit?", 640, 2),100,tex_console,black,2,"Do you really want to Exit?");
	
	GRRLIB_Rectangle(centerToScreenH(72), 127+exitMenuSelection, 72, 32, black, 1);
	GRRLIB_Rectangle(centerToScreenH(70), 128+exitMenuSelection, 70, 30, white, 1);
	
	GRRLIB_Printf(centerChar("YES", 640, 2), 140, tex_console, black, 2, "YES");
	GRRLIB_Printf(centerChar("NO", 640, 2), 170, tex_console, black, 2, "NO");	
}	

void mainMenu(){
	int i;
	int leftMenuX=-360;
	int exitMenuSelection=0;
	
	char title[]="Wii Media Player";
	char musicDir[]="SD:/MUSIC/";
	char other[]="Three Days Grace/One X/Never Too Late.mp3";
	char songLocation[1000];
	
	bool leftMenuOpen=false;
	bool exitMenuVisible=false;
	
    u32 buttonDown;
	u32 buttonHeld;
	u32 buttonUp;
	u32 playColor=white;
	
	sprintf(songLocation,"%s%s",musicDir,other);
	
	filepointer=fopen("SD:/MUSIC/Three Days Grace/One X/Never Too Late.mp3","r");
	if(!filepointer){
		exit(0);
	}
		
    // Load the text
    GRRLIB_texImg tex_console = GRRLIB_LoadTexture(console); //Note:  Is an 8x8 font
    GRRLIB_InitTileSet(&tex_console, 8, 8, 0);
	
	//Load Cursor
	GRRLIB_texImg tex_cursor = GRRLIB_LoadTexture(cursor);
	WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
	
	//MP3Player_PlayBuffer (song_mp3, song_mp3_size, NULL);
	MP3Player_Volume(255);
	
	MP3Player_PlayFile(filepointer,reader_callback,0);
	
	ASND_Pause(0);
	
	while(1) {
		WPAD_SetVRes(0, 640, 480);
        WPAD_ScanPads();
        buttonDown = WPAD_ButtonsDown(0);
		buttonHeld = WPAD_ButtonsHeld(0);
		buttonUp = WPAD_ButtonsUp(0);
		WPAD_IR(0, &ir);
		
		/*Catch control events*/
		if(leftMenuOpen && artists.isActive && (buttonDown && WPAD_BUTTON_DOWN)){
			artists.selection+=10;
		}
		if(leftMenuOpen && (buttonDown & WPAD_BUTTON_RIGHT)){
			if(artists.isActive){
				artists.isActive=false;
				albums.isActive=true;
				songs.isActive=false;
			}else if(albums.isActive){
				artists.isActive=false;
				albums.isActive=false;
				songs.isActive=true;
			}
		}
		if(leftMenuOpen && (buttonDown & WPAD_BUTTON_LEFT)){
			if(songs.isActive){
				artists.isActive=false;
				albums.isActive=true;
				songs.isActive=false;
			}else if(albums.isActive){
				artists.isActive=true;
				albums.isActive=false;
				songs.isActive=false;
			}
		}
		if(exitMenuVisible && (buttonDown & WPAD_BUTTON_DOWN)){
			exitMenuSelection=30;
		}
		if(exitMenuVisible && (buttonDown & WPAD_BUTTON_UP)){
			exitMenuSelection=0;
		}
		if(exitMenuVisible && (buttonDown & WPAD_BUTTON_A)){
			if(exitMenuSelection==0){
				break;
			}else if (exitMenuSelection==30){
				exitMenuVisible=false;
			}
		}
		if(!exitMenuVisible && !leftMenuOpen && (buttonHeld & WPAD_BUTTON_A)){
			playColor=mediumDarkGrey;
		}
		if(!exitMenuVisible && !leftMenuOpen && (buttonUp & WPAD_BUTTON_A)){
			playColor=white;
			if(MP3Player_IsPlaying()){
				MP3Player_Stop();
			}else if(!MP3Player_IsPlaying()){
				
			}
		}
		if(leftMenuOpen && (buttonDown & WPAD_BUTTON_PLUS)){
			artists.page++;
		}
		if(leftMenuOpen && artists.page!=0 && (buttonDown & WPAD_BUTTON_MINUS)){
			artists.page++;
		}
		if(buttonDown & WPAD_BUTTON_HOME) {
			exitMenuVisible=true;
        }
		/*--------------------*/
		
        GRRLIB_FillScreen(white);
		
        GRRLIB_Printf(centerChar(title, 640, 3), 60, tex_console, black, 3, title);
		
		/*Draw the frame*/
		GRRLIB_Rectangle(0, 100, 640, 1, black, 0);//Top horizontal bar
		GRRLIB_Rectangle(leftMenuX+380, 101, 1, 379, black, 0);//Left vertical bar
		/*--------------*/
		
		GRRLIB_Rectangle(leftMenuX, 102, 380, 378, grey, 1);//Left menu backgrond
		
		/*Create the play controls*/
		GRRLIB_Rectangle(0, 430, 640, 3, black, 1);//Bottom horizontal bar
		rectangleWithBorder(centerToScreenH(50),395,50,50,black,2,playColor);//Play button
		if(!MP3Player_IsPlaying()){
			for(i=0;i<20;i+=1){
				GRRLIB_Rectangle(310+i,399+i,1,40-(i*2),black, 1);
			}
		}else if(MP3Player_IsPlaying()){
			GRRLIB_Rectangle(305,403,10,35,black,1);
			GRRLIB_Rectangle(324,403,10,35,black,1);
		}
		
		/*Start rollover events*/
		//To open Left Menu
		if(ir.sx<=leftMenuX+380&&ir.sy>=100){
			leftMenuOpen=true;
			if(leftMenuX!=0){
				leftMenuX+=20;
			}
		}else{
			leftMenuOpen=false;
			if(leftMenuX!=-360){
				leftMenuX-=20;
			}
		}
		/*---------------------*/
		
		/*Begin outputting tabs*/
		//Artists tab
		if(artists.isActive){
			artists.fillColor=grey;
		}else{
			artists.fillColor=mediumDarkGrey;
		}
		GRRLIB_Rectangle(leftMenuX+artists.x, artists.y, artists.width, artists.height, artists.borderColor, 0);
		GRRLIB_Rectangle(leftMenuX+artists.x+1, artists.y+1, artists.width-1, artists.height, artists.fillColor, 1);
		if(artists.isActive){
			GRRLIB_Line(leftMenuX+artists.x, artists.y+artists.height, leftMenuX+artists.x+artists.width, artists.y+artists.height, grey);
		}else{
			GRRLIB_Line(leftMenuX+artists.x, artists.y+artists.height, leftMenuX+artists.x+artists.width, artists.y+artists.height, black);
		}
		GRRLIB_Printf(leftMenuX+artists.x+centerTab(artists), artists.y+7, tex_console, black, artists.fontSize, artists.text);
		
		//Albums tab
		if(albums.isActive){
			albums.fillColor=grey;
		}else{
			albums.fillColor=mediumDarkGrey;
		}
		GRRLIB_Rectangle(leftMenuX+albums.x, albums.y, albums.width, albums.height, albums.borderColor, 0);
		GRRLIB_Rectangle(leftMenuX+albums.x+1, albums.y+1, albums.width-1, albums.height, albums.fillColor, 1);
		if(albums.isActive){
			GRRLIB_Line(leftMenuX+albums.x, albums.y+albums.height, leftMenuX+albums.x+albums.width, albums.y+albums.height, grey);
		}else{
			GRRLIB_Line(leftMenuX+albums.x, albums.y+albums.height, leftMenuX+albums.x+albums.width, albums.y+albums.height, black);
		}
		GRRLIB_Printf(leftMenuX+albums.x+centerTab(albums), albums.y+7, tex_console, black, albums.fontSize, albums.text);
		
		//Songs tab
		if(songs.isActive){
			songs.fillColor=grey;
		}else{
			songs.fillColor=mediumDarkGrey;
		}
		GRRLIB_Rectangle(leftMenuX+songs.x, songs.y, songs.width, songs.height, songs.borderColor, 0);
		GRRLIB_Rectangle(leftMenuX+songs.x+1, songs.y+1, songs.width-1, songs.height, songs.fillColor, 1);
		if(songs.isActive){
			GRRLIB_Line(leftMenuX+songs.x, songs.y+songs.height, leftMenuX+songs.x+songs.width, songs.y+songs.height, grey);
		}else{
			GRRLIB_Line(leftMenuX+songs.x, songs.y+songs.height, leftMenuX+songs.x+songs.width, songs.y+songs.height, black);
		}
		GRRLIB_Printf(leftMenuX+songs.x+centerTab(songs), songs.y+7, tex_console, black, songs.fontSize, songs.text);
		/*---------------------*/
		
		/*Begin outputting left menu info*/
		if(artists.isActive){
			drawArtists(leftMenuX, tex_console);
		}/*else if(albums.isActive){
			drawAlbums();
		}else if(songs.isActive){
			drawSongs();
		}*/
		/*---------------------*/
		
		if(exitMenuVisible){
			menuExit(exitMenuSelection, tex_console);
		}
		
		GRRLIB_DrawImg(ir.sx, ir.sy, tex_cursor, 0, 1, 1, 0xFFFFFFFF);
		
        GRRLIB_Render();
    }
	
	// Be a good boy, clear the memory allocated by GRRLIB
    GRRLIB_Exit(); 
    free(tex_console.data);
	free(tex_cursor.data);
	MP3Player_Stop();
	fclose(filepointer);
}

int main() {
    GRRLIB_Init();
    WPAD_Init();
	fatInitDefault();
	ASND_Init();
	MP3Player_Init();
	
	setProperties();
	initializeArtists();
	mainMenu();
	
	exit(0);
	
    return 0;
}


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
#---------------------------------------------------------------------------------
GRRLIB        :=    source
TARGET        :=    $(notdir $(CURDIR))
BUILD        :=    build
SOURCES        :=    source source/gfx $(GRRLIB)/GRRLIB $(GRRLIB)/lib/libpng/pngu
DATA        :=    data  
INCLUDES    :=

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

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

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

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS	:=	-lpng -ljpeg -lz -lwiiuse -lmodplay -lmad -lasnd -lbte -lfat -logc -lm
#---------------------------------------------------------------------------------
# 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), -iquote $(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):
	@echo cleaning...
	@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
	@echo Building...
	@[ -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)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .jpg extension
#---------------------------------------------------------------------------------
%.jpg.o	:	%.jpg
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
# This rule links in binary data with the .mp3 extension
#---------------------------------------------------------------------------------
%.mp3.o :       %.mp3
#---------------------------------------------------------------------------------

	@echo $(notdir $<)
	$(bin2o)

-include $(DEPENDS)

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

Just ask if you need to see any of the custom includes (IE properties.h, colors.h, etc...). Also, if you see anything that can be improved, mention it to me.



Edited 1 time(s). Last edit at 06/13/2009 06:05AM by Nicholas_Roge.
Re: How to Play Sound and Video Files
June 13, 2009 09:56AM
Try adding a check for MP3Player_IsPlaying before stopping playback. This is a guess, of course, but I had a similar problem: I've found that if you ask MP3Player to stop when it is not playing, then the program will hang. That, or some other unknown thing fixed my bug.
Re: How to Play Sound and Video Files
June 13, 2009 11:01AM
Btw, about video playback, that is one thing that is ok to not use the GX api for, just dump the pixels onto the framebuffer instead.
Re: How to Play Sound and Video Files
June 14, 2009 05:57PM
Quote
alainvey
Try adding a check for MP3Player_IsPlaying before stopping playback. This is a guess, of course, but I had a similar problem: I've found that if you ask MP3Player to stop when it is not playing, then the program will hang. That, or some other unknown thing fixed my bug.

I added one at the bottom, but the one that tells it to stop when you push A already has a check for that on it. And even when I add that to the bottom, it still freezes.

Quote
henke37
Btw, about video playback, that is one thing that is ok to not use the GX api for, just dump the pixels onto the framebuffer instead.

the GX api? I'm not sure what you mean.
Re: How to Play Sound and Video Files
June 14, 2009 11:15PM
If you don't know what GX is, then you are clearly not the right person to try to not use it.
Re: How to Play Sound and Video Files
June 17, 2009 10:13PM
So, any help on this issue?

Edit: And just because I've never heard of this GX api doesn't mean I can't use it.



Edited 1 time(s). Last edit at 06/17/2009 10:16PM by Nicholas_Roge.
Sorry, only registered users may post in this forum.

Click here to login