gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Whats the process of getting sound to run gba?

#176909 - blessingta@hotmail.co.uk - Tue Oct 18, 2011 6:44 pm

hi

I was looking as the audio samples proided by devkitpro found out that there wasn't an project aranged for the files (unlike the graphics section which had projects that I could copy from and rewrite).

How does the whole process of getting sound on screen work?

#176910 - Dwedit - Tue Oct 18, 2011 8:06 pm

This is from memory, sorry if I get some details wrong or missing...

First, set whatever sound registers are needed to enable sound, and enable the dma sound channels.

Prepare a buffer to play sound from, synthesize your wave.
Set the first timer to the rate you want sound to play at.
Set the next timer to operate in "count up" mode, give it your buffer size (negative), so it triggers an interrupt when the play buffer has finished.
Write the first 4 bytes manually to the sound FIFO register.
Set one of the DMA channels to Timer DRQ mode, have it use your audio buffer as the source, and the sound FIFO register as the destination.
Enable the first timer. Now it's spitting out bytes to the sound FIFO register whenever the first timer expires. Then it increments the second timer to indicate that it has played that word.
When the second timer expires (counts up to max), you need to get it to play at the beginning of the buffer again, otherwise it will just keep playing more sound beyond the end of the buffer. You also reset the second timer, so it gets ready to let you know for the next time. Also you need to fill the buffer with your new wave to play. So it's best to divide your sound buffer in two, and have one half of your sound buffer "Filling" and the other half "playing".

You can also use Maxmod as your sound engine if you'd rather do that.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#176922 - blessingta@hotmail.co.uk - Fri Oct 21, 2011 10:42 am

could you post me a code sample with comments?

else am I guranteed that it will work if I try to mod the devkitpro examples? All I can do at the moment is compiling those examples, because of the make file provided; but at the sametime there isn't even a project with the sound files.

#176935 - wintermute - Sat Oct 29, 2011 12:21 pm

If you mean the .pnproj file then just copy the one from the gba template example. It's a magic folder setup so it automatically picks up the source files.

If you're looking to do something a bit more low level then http://belogic.com/gba/ is worth a look but their code will need a bit of tweaking since it was originally written in the days of devkitadv.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#176948 - blessingta@hotmail.co.uk - Thu Nov 03, 2011 6:41 pm

Ok, in the devkit project file the main issue I've been having is with actually loading a wave file it self. And in this I've spent all day trying to find where the audio files: "Audio" "Boom" and "FlatOutLies" are read in and converted to something gba friendly as I would presume.

But all I seem to notice is that there appear to be a magic blackbox that extracting the sound files but I can't even tell where they are. Plus does the magic box you are talking about actually automatically convert the sound files so long as they are in the appropriate folder?

#176949 - Dwedit - Thu Nov 03, 2011 7:48 pm

The "Magic" is in the makefile:

Code:

MUSIC      :=  maxmod_data
 - snip -
export AUDIOFILES   :=   $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))
 - snip -
#---------------------------------------------------------------------------------
# rule to build soundbank from music files
#---------------------------------------------------------------------------------
soundbank.bin : $(AUDIOFILES)
#---------------------------------------------------------------------------------
   @mmutil $^ -osoundbank.bin -hsoundbank.h

It calls a program called mmutil (MaxMod utility) to create a sound bank file out of all the mod files. You end up with "soundbank.bin" then "soundbank.bin.o" sitting in the build folder, then that can be linked into the program.

Then you use the maxmod library to play music.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."