Welcome! Log In Create A New Profile

Advanced

Playing Sounds

Posted by profetylen 
Playing Sounds
June 08, 2009 12:30PM
What way to play sounds do you recommend?
Re: Playing Sounds
June 08, 2009 02:50PM
I prefer a way where I can control the full audio path. No magical things that plays stuff without telling you how and so on. But I don't think that there exists such an alternative. At least not anything that I can recommend, not even my own defunct library.

The main alternative is to use the asnd library, it uses dsp accelerated mixing. However, it has a maximum channel count and it only plays pcm memory buffers. And the decoder libraries are not very good either, they plain can not be used for more than one channel at any time, and they also only does memory buffers.

If you want advanced sound, you might want to look at the AI API, it's what you have to use to get the sound out.



Edited 1 time(s). Last edit at 06/08/2009 02:51PM by henke37.
Re: Playing Sounds
June 08, 2009 06:06PM
Libogc has a very basic set of MP3 Playing functions. I've spent a lot of time with them and have had very limited success. They also don't seem to be very stable. In other words, I can't really recommend using them. But I also don't know of any alternatives for .mp3 files except converting them to a different format and playing the different format.

I don't if that was what you were looking for, but I hoped it at least helped somewhat. If nothing else, you now know libogc has .mp3 playing functionality :P



Edited 1 time(s). Last edit at 06/08/2009 06:08PM by Arikado.
Re: Playing Sounds
June 08, 2009 08:27PM
Okay!

Thanks for the info :)
Re: Playing Sounds
June 09, 2009 07:04AM
Your best bet is ogg, see what's in libwiigui and snes9x gx as examples
Re: Playing Sounds
June 09, 2009 09:34PM
@Arikado

I've never had any issues with the mp3 functions. I've used them in several projects.
Re: Playing Sounds
June 09, 2009 11:35PM
You can't have been crossfading using those then.
Re: Playing Sounds
June 11, 2009 03:02PM
Ok! I am gonna go with the oggplayer.c (found in the libwiigui example).

However since I don't use the libwiibui library and use GRRLIB instead I figured I'd only use the oggplayer.c to play my sounds. The tricky part is, however, how can I load the sound files to the memory? I'm not really into this makefile stuff. Do I have to modify the makefile?
Re: Playing Sounds
June 12, 2009 11:06AM
Quote
profetylen
Do I have to modify the makefile?

You'll need to add the lib to the makefile, which I can't remember exactly what it is offhand. Also, you'll need to add the following to the bottom of your makefile in order to compile the .ogg sound files:
#---------------------------------------------------------------------------------
# This rule links in binary data with the .ogg extension
#---------------------------------------------------------------------------------
%.ogg.o :	%.ogg
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)
	
-include $(DEPENDS)
Re: Playing Sounds
June 12, 2009 11:42AM
I wouldn't call that compile per see. But in any case, not that many advocate doing it like that if there is an alternative, like reading from a file instead.
Re: Playing Sounds
June 12, 2009 07:44PM
@RazorChrist Ok! Where can I find the information about what lib should be added?

@henke37 Ok, but I think I prefer it the other way to make everything "cleaner", but thanks anyway for the advice! :)
Re: Playing Sounds
June 13, 2009 09:16AM
Quote
profetylen
@RazorChrist Ok! Where can I find the information about what lib should be added?

Someone can correct me if I'm wrong, but I believe the ASND lib can do .ogg the same as it does .mp3. The libs to add to your makefile are as follows:
LIBS	:= -lasnd -lmad
I think....can't remember. That's just the two sound libs that are in my project. Then again, I'm using .mp3. Try adding those, and if anyone else has more info, or if I come across more detailed info, I'll post it.
Re: Playing Sounds
June 13, 2009 09:34AM
No, the code for doing ogg isn't in libogc. There's an oggplayer (tremor wrapper) written for ASND though, I'm using it in my projects. See oggplayer.c from [code.google.com] as an example.
Re: Playing Sounds
June 14, 2009 01:39PM
Ok! I think I have understodd everything except how I do get the sound file to be stored in an array, like bg_music_ogg[] and it's size in bg_music_ogg_size.

I have added this makefile rule:

#---------------------------------------------------------------------------------
# This rule links in binary data with the .ogg extension
#---------------------------------------------------------------------------------
%.ogg.o :	%.ogg
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)
	
-include $(DEPENDS)
But, as I mentioned, I don't know how to get access to the sound buffer (or what it is...).
Re: Playing Sounds
June 14, 2009 07:59PM
If your makefile is set up right, then myfile.ogg will be automatically included, and you just need to access it with:

extern const u8 myfile_ogg[];
extern const u32 myfile_ogg_size;

function myFunction()
{
// use the variables here
}
Re: Playing Sounds
June 14, 2009 08:33PM
OK!

I have got the file inside folder_of_the_app\sfx

It doesn't just show up in programmers notepad and can't be accessed through extern const u8 myfile_ogg[] or size...
What might be wrong then?

My makefile looks like this:

#---------------------------------------------------------------------------------
# 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/GRRLIB
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 -lfat -lwiiuse -lbte -lfat -logc -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS	:= $(CURDIR)/$(GRRLIB)

#---------------------------------------------------------------------------------
# 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):
	@[ -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

#---------------------------------------------------------------------------------
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 with the .ogg extension
#---------------------------------------------------------------------------------
%.ogg.o :	%.ogg
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)
	
-include $(DEPENDS)

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

And I get this error when I try to compile:

> "make"
main.cpp
c:/Projects/wii/akruve/source/main.cpp: In function 'int main(int, char**)':
c:/Projects/wii/akruve/source/main.cpp:31: error: invalid use of array with unspecified bounds
make[1]: *** [main.o] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:01



Edited 1 time(s). Last edit at 06/14/2009 08:35PM by profetylen.
Re: Playing Sounds
June 14, 2009 11:17PM
Just include the auto generated headerfile and get the right defentions for free.
Re: Playing Sounds
June 15, 2009 01:20AM
It is not becoming auto genereted. I have checked the build folder and it's not there.
I can't even see it in the sfx folder in programmers notepad, and I have checked it really is there.

I "cheated" and borrowed the bg_music_ogg.h from the libwiigui example and then I could not use the PlayOgg(...) function.
I used it as it is being used in the libwiigui example. That is, as far as I can understand, like this:

PlayOgg(mem_open((char *)bg_music_ogg,bg_music_ogg.length), 0, OGG_INFINITE_TIME);

And got an error like this:

> "make"
main.cpp
c:/Projects/wii/akruve/source/main.cpp: In function 'int main(int, char**)':
c:/Projects/wii/akruve/source/main.cpp:29: error: invalid use of array with unspecified bounds
make[1]: *** [main.o] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:00



My 2 questions are:

What do I exactly have to do to make my program auto generate a bg_music_ogg.h?

and

How do I properly use the function PlayOgg(...) from oggplayer.c?
Re: Playing Sounds
June 15, 2009 11:53AM
add this after BINFILES:

OGGFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ogg)))

This will automatically look for ogg files in the given directory.
Be sure to put your ogg files in the /data directory.
If you got the idea you can put them elsewhere and modify the Makefile in regard.

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

into

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

This will automatically generate the .o and .h files for each OGG.


About your error:

PlayOgg(mem_open((char *)bg_music_ogg,C), 0, OGG_INFINITE_TIME);

should be

PlayOgg(mem_open((char *)bg_music_ogg,bg_music_ogg_size), 0, OGG_INFINITE_TIME);

bg_music_ogg is not a structure, it is a buffer
the buffer length is declared as another variable wich is xxxxx_og_size.
where does this bg_music_ogg.length idea comes from ?

PS: as a general advice, pay good attention to the compiler warnings/errors and try to understand what they mean, it's good learning practice



Edited 4 time(s). Last edit at 06/15/2009 12:02PM by ekeeke.
Re: Playing Sounds
June 15, 2009 06:39PM
i became very frustrated with the loading ogg from source, so i decided to start using the FAT system for SD Cards:

just add the "fat.h" header
add fatInitDefault(); to source code


btw< in the posted makefile you have 2 occurances or "-lfat"
Sorry, only registered users may post in this forum.

Click here to login