一个简单的写wave文件头的c函数

void write_wave_head(FILE* wav_file, LPCWAVEFORMATEX pcfxFormat, int s_size){
	uint32_t size;

    fwrite("RIFF", 1, 4, wav_file);
    size = s_size+44;
    fwrite(&size, 1,  4, wav_file);
    fwrite("WAVE", 1, 4, wav_file);
    /* write fmt  subchunk */
    fwrite("fmt ", 1, 4, wav_file);
	size = 16;//sizeof(WAVEFORMATEX)
    fwrite(&size, 1,  4, wav_file);
 	fwrite(pcfxFormat, 1, 16, wav_file);
    /* write data subchunk */
    fwrite("data", 1, 4, wav_file);
	size = s_size;
    fwrite(&size, 1,  4, wav_file);
}
用法:
///seek to begin, rewrite wave head
fseek(file_wave, 0, SEEK_SET);
write_wave_head(file_wave, &wfx, buffer_size);
/// seek to end, write new wave data
fseek(file_wave, 0, SEEK_END);
fwrite(wavebuffer, buffer_size, 1, file_wave);

wave文件头图解:

一个简单的写wave文件头的c函数_第1张图片

你可能感兴趣的:(c,Wave)