wav文件头读取
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
struct WAV_Format {
uint32_t ChunkID;
uint32_t ChunkSize;
uint32_t Format;
uint32_t Subchunk1ID;
uint32_t Subchunk1Size;
uint16_t AudioFormat;
uint16_t NumChannels;
uint32_t SampleRate;
uint32_t ByteRate;
uint16_t BlockAlign;
uint16_t BitsPerSample;
uint32_t Subchunk2ID;
uint32_t Subchunk2Size;
};
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;
}