在项目的源文件中包含dsound.h头文件,分别定义DirectSound接口和主、辅助缓冲区接口的全局变量,以及保存WAV音频格式的文件头结构。
声明代码如下:
//--D3D用的头文件
#include <d3d9.h>
#include <d3dx9.h>
#include <stdio.h>
#include <dsound.h>
LPDIRECTSOUND8 g_pDirectSound = NULL; //DirectSound接口
LPDIRECTSOUNDBUFFER g_pPrimaryBuffer = NULL;//主缓冲接口
LPDIRECTSOUNDBUFFER8 g_pSecondaryBuffer = NULL;//辅助缓冲接口
WAV文件的文件头定义如下:
struct WAVE_HEADER
{
char riff_sig[4]; //RIFF
long waveform_chunk_size; //8
char wave_sig[4]; //WAVE
char format_sig[4]; //FMT
long format_chunk_size; //16
short format_tag; //WAVE_FORMAT_PCM
short channels; //声道数
long sample_rate; //采用频率
long bytes_per_sec; //播放速度 字节/秒
short block_align; //sample block alignment
short bits_per_sample; //位/秒
char data_sig[4]; //data
long data_size; //音频数据大小
};