Low-level audio function under Windows
Under Windows, the audio function has a variety of types, such as MCI, multimedia OLE control, advanced audio, etc., and how easy usage is relatively simple. But if you want to write a more powerful audio handler, you must use the low audio function and the multimedia file I / O to control the input and output of the audio device. Because low-level audio functions can be directly interactively interact with audio drivers, manage audio data blocks and playback, control is very flexible. Important, the low-level audio function provides us with an unrelated interface.
Playing digital audio
Before using the audio device, you must open the device driver. For a reliability, the ability to determine the system audio device before playing and recording audio. The audio device must be turned off after running. The specific process is as follows:
1. Query the number of devices and capabilities
Use WaveOutGetNumDevs and WaveOutgetDevCaps to get the number and capabilities of the waveform output device. The device can be opened only after the device exists.
2. Open waveform output device
Use Waveoutopen to open a specific waveform device for playback operations. This function opens the device associated with the specified device ID and returns the handle of the open waveform device to give the method of the specified memory handle.
When there are multiple waveform output devices, it is recommended to use Wave_Mapper constants as device IDs, which allows the Waveoutopen function to automatically select devices that best conform to play a given data format.
3. Prepare audio data block
Prepare the audio data block before the waveform replay. Replay the data block to the device driver. The function used is WaveoutperPareHeader. After using the data block, you must use the WaveoutUnPrepareHeader function to clear the preparation for the waveform data block.
4. Send audio data block
After successfully opening the waveform output device, the waveform playback can be performed, and the WaveoutWrite function can be used. After calling the function, you must wait until the device driver uses the full audio data block to release the data block.
5. Manage waveform playback
When playing audio using a low-level audio function, the application must constantly provide data blocks to the device driver until the playback is over. Windows provides two ways to manage waveform playback: First, use window message management, and the other is to manage it using low-level callback functions. In addition, you will be paused by using WaveoutPause, WaveoutRestart, and WaveoutreSet, restart and stop playback.
6. Turn off the waveform device
After using the device, you must call the WaveoutClose function to turn off the waveform output device so that other programs can use the device.
Record digital audio
The method of recording digital audio is basically the same playback process, and the different is not provided during the recording, such as pause and resumption. The functions that are used include: WaveIngetDevcaps, WaveinOpen, WaveinPreparehead, Waveinunprepareheader, WaveinAddbuffer, WaveinReset, WaveInstart, WaveInstop, WaveInClose, etc.