#include #include
/**
* Convert PCM raw data to WAVE format
* @param pcmpath Input PCM file.
* @param channels Channel number of PCM file.
* @param sample_rate Sample rate of PCM file.
* @param wavepath Output WAVE file.*/
int transform_pcm_to_wave(const char *pcmpath, int channels, int sample_rate, const char *wavepath)
{
typedefstructWAVE_HEADER{char fccID[4]; //内容为"RIFF"
unsigned int dwSize; //最后填写,WAVE格式音频的大小
char fccType[4]; //内容为"WAVE"
}WAVE_HEADER;
typedefstructWAVE_FMT{char fccID[4]; //内容为"fmt "
unsigned int dwSize; //内容为WAVE_FMT占的字节数,为16
short int wFormatTag; //如果为PCM,改值为 1
short int wChannels; //通道数,单通道=1,双通道=2
unsigned int dwSamplesPerSec;//采样频率
unsigned int dwAvgBytesPerSec;/*==dwSam