在windows上使用Core Audio的接口来进行pcm音频文件的播放,有个很重要的参数一定要设置正确,就是下面这个结构体的属性
/*
* extended waveform format structure used for all non-PCM formats. this
* structure is common to all non-PCM formats.
*/
typedef struct tWAVEFORMATEX
{
WORD wFormatTag; /* format type */
WORD nChannels; /* number of channels (i.e. mono, stereo...) */
DWORD nSamplesPerSec; /* sample rate */
DWORD nAvgBytesPerSec; /* for buffer estimation */
WORD nBlockAlign; /* block size of data */
WORD wBitsPerSample; /* number of bits per sample of mono data */
WORD cbSize; /* the count in bytes of the size of */
/* extra information (after cbSize) */
} WAVEFORMATEX, *PWAVEFORMATEX, NEAR *NPWAVEFORMATEX, FAR *LPWAVEFORMATEX;
对于PCM文件来说,上面这个结构体的属性设置跟当初生成PCM使用的参数有关,如果每个样本使用32,则wBitsPerSample是32,
其他可用
nBlockAlign = 8;
wFormatTag = 65534;
cbSize = 22;
如果wBitsPerSample是16,
nBlockAlign = 4;
wFormatTag = 1;
cbSize = 0;
设置不正确可能导致播放出现噪音。如果对样本进行重采样,则根据重采样的采样率和样本大小重新设置。