Normally digital audio is played at a sampling rate that is preset before playback begins. This cannot easily be changed while audio is actually playing. But sometimes it's desirable to change the playback rate while audio is running. This can be useful for doing effects such as an airplane engine variable RPMs that is produced from only a small looping DMA buffer.
The easiest method of changing the playback rate is by carefully using the Sound Blaster DSP commands. This also depends on which Sound Blaster card and mode is used to play digital audio. There are several different modes from programming digital effects from Direct mode to HighSpeed mode. Most of these mode are available on all the Sound Blaster cards, but some modes depend on the DSP version.
The first method of changing the sampling rate during audio playback is to send a halt to the DSP so that it will accept DSP commands. While the playback is halted, write out the new sampling rate to the DSP, then send a continue command to the DSP to resume the playback with the modified sampling rate. The following method is for the Sound Blaster and Sound Blaster Pro cards:
mov al,D0h ; DSP Halt call WriteDSP ; Write command to DSP mov al, 40H ; Set Sampling Rate Command call WriteDSP ; Write command to DSP mov al,_SamplingRate ; Get Time Constant call WriteDSP ; Write command to DSP mov al, D4h ; DSP Continue call WriteDSP ; Write command to DSP
The second method is identical to the first method except it does not require a halt before setting the new sampling rate. The only requirement is to send the new sampling rate to the DSP, then send a DSP continue. This will change the sampling rate without interrupting the DMA transfer. The following method is only for SB16/SB AWE32 family cards:
mov al, 40H ; Set Sampling Rate Command mov al,_SamplingRate ; Get Time Constant call WriteDSP ; Write command to DSP mov al, D4h ; DSP Continue call WriteDSP ; Write command to DSP