Now that we have all of the audio data stored in memory, we are ready to begin playing the sound. In order to do so we must essentially take each of the values stored in the data array, and send them in order to the audio card (in our case, using the callback method that we created earlier).
If the format, sampling rate, and number of channels in the audio data are the same as the output, then this process is as simple as copying values from one array to another. However, the process becomes significantly more complicated if they differ in any way, in particular:
If our audio data has a different sampling rate from the output, we need to resample the data so that it matches the sampling rate of the output, or the sound will play at a different rate than we expect. This operation is not trivial, and is beyond the scope of this chapter.
If our audio data is in a different format from the output, we need to convert the data to the new format first. For example, we may need to convert...