书呆子的专栏

掘弃傲慢,放下偏见,平凡的心态创造未来~

一个简单的写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文件头图解:


阅读更多
文章标签: c wave
个人分类: C++
上一篇安装和卸载指定apk的批处理文件
下一篇推荐一个Android下的自动测试框架robotium
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭