Putting it all togetherWe 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:
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:
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! ResourcesIf 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
FeedbackIf you have any questions, comments, or constructive criticisms about this article, feel free to contact me at Anarcrothe@hotmail.com. |