User:Henke37/Sound on a Wii
Sound on a Wii, a mini tutorial
Once you have the final samples to play, playing sound on a Wii isn't hard at all. It is basically a simple callback system. First you start the system by calling AUDIO_Init(), this will get the thin wrapper around the hardware initialized. Next, you need to tell it the sample rate, don't worry about choosing it, you don't have many options, either it's 48 KHz or it's 32 KHz. It will be stereo, you are not able to chose mono. It is not encoded either, it's plain samples. Next, you need to set the callback function. The callback will be called when the sound buffer is done. The callback is just a void function. The callback needs to do 3 things, first, stop the DMA system so that you can give it a new order, then you order it to start from the buffer beginning again. It is recommended that you double buffer the sound so that you can freely write to it without strange noises while you are doing that. Then you turn the DMA system back on to let the new command start running.
Btw, don't forget to flush the sound buffer before starting the DMA, it's not fun when the caching is in the way. And you probably shouldn't compute the buffer during the callback, do it some other time. There is a neat trick you can do to save cpu time with generating the buffer, make the generating thread block when the buffer is full until the DMA starts using the buffer. This also prevents it from running way too far and over writing the old generated data. You can probably use the condition based thread blocking system that's already in libogc for that.