wav文件头读取

wav文件头读取

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
 
struct WAV_Format {
	uint32_t ChunkID;	/* "RIFF" */
	uint32_t ChunkSize;	/* 36 + Subchunk2Size */
	uint32_t Format;	/* "WAVE" */
 
	/* sub-chunk "fmt" */
	uint32_t Subchunk1ID;	/* "fmt " */
	uint32_t Subchunk1Size;	/* 16 for PCM */
	uint16_t AudioFormat;	/* PCM = 1*/
	uint16_t NumChannels;	/* Mono = 1, Stereo = 2, etc. */
	uint32_t SampleRate;	/* 8000, 44100, etc. */
	uint32_t ByteRate;	/* = SampleRate * NumChannels * BitsPerSample/8 */
	uint16_t BlockAlign;	/* = NumChannels * BitsPerSample/8 */	
	uint16_t BitsPerSample;	/* 8bits, 16bits, etc. */
 
	/* sub-chunk "data" */
	uint32_t Subchunk2ID;	/* "data" */
	uint32_t Subchunk2Size;	/* data size */
}; 
 
int main(void)
{
	FILE *fp = NULL;
	struct WAV_Format wav;
 
	fp = fopen("test.wav", "rb");
	if (!fp) {
		printf("can't open audio file\n");
		return -1;
	}
 
	fread(&wav, 1, sizeof(struct WAV_Format), fp);
 
	printf("ChunkID \t%x\n", wav.ChunkID);
	printf("ChunkSize \t%d\n", wav.ChunkSize);
	printf("Format \t\t%x\n", wav.Format);
	printf("Subchunk1ID \t%x\n", wav.Subchunk1ID);
	printf("Subchunk1Size \t%d\n", wav.Subchunk1Size);
	printf("AudioFormat \t%d\n", wav.AudioFormat);
	printf("NumChannels \t%d\n", wav.NumChannels);
	printf("SampleRate \t%d\n", wav.SampleRate);
	printf("ByteRate \t%d\n", wav.ByteRate);
	printf("BlockAlign \t%d\n", wav.BlockAlign);
	printf("BitsPerSample \t%d\n", wav.BitsPerSample);
	printf("Subchunk2ID \t%x\n", wav.Subchunk2ID);
	printf("Subchunk2Size \t%d\n", wav.Subchunk2Size);
 
	fclose(fp);
 
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值