Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
64 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Contents
 Introduction
 Direct Sound
 DMA
 Putting it all
 together


 Source code
 Printable version
 Discuss this article

Putting it all together

We now have all the information we need to play a single sample on either of the Direct Sound channels. A high-level overview of the steps would go something like this:

  • Enable the sound hardware by setting REG_SOUNDCNT_X.
  • Set up the Direct Sound playback parameters in register REG_SOUNDCNT_H.
  • Set the appropriate Timer to overflow according to the frequency (sampling rate) of the sample(s).
  • Set up and enable a DMA of the audio data to the appropriate FIFO.
  • Stop the sound using whatever method you are comfortable with.

I have created a demo program that plays back two different samples (mapped to the GBA buttons A and B), along with the commented source. It should look pretty straightforward after all we have covered. The only thing in there that I haven't discussed yet is the SAMPLE structure, which is used to store attributes of the sample and reference the raw audio data. It looks like this:

typedef struct _sample
{
    s8  *pData;             // a pointer to the raw sound data (which
                            // is essentially a large array of signed
                            // chars)
    u32 length;             // the length of the sample in bytes
                            // (padded to 1/60th of a second)

} SAMPLE;

I would advise you to play around with the demo and make sure you understand what's going on under the hood. Go ahead and tinker with some of the values. I have also included a utility program called Simon that reads raw PCM files and outputs the audio information in the form of C header files that you can include in the project workspace (note that this utility will automatically pad a sample with silence to a 1/60th of a second boundary). A couple of good learning exercises might be:

  • Switching the program to use Direct Sound channel B instead of channel A.
  • Adjusting the frequency to produce faster/slower playback.
  • Creating and playing your own samples using the included utility.

Make sure you're boned up for next time when we take what we've learned in this session, tear it all apart and rebuild it into a real, functional, multi-channel sound effects mixer!

Resources

If you're interested in learning more about the Gameboy Advance and how it works, I recommend checking out the sites below. They have been a tremendous help to me in writing this article and should provide you with a much better understanding of this remarkable little machine.

GBA Development From the Ground Up at Gamedev.net
The Pern Project
The Audio Advance
GBADev.org
GameBoy Advance Dev'rs
Unofficial GameBoy Advance Software Development Kit
GBADev at Yahoo Groups

Feedback

If you have any questions, comments, or constructive criticisms about this article, feel free to contact me at Anarcrothe@hotmail.com.