主程序:
#include "Wave.h"
// WaveHeader.c
//void main(int argc, char **argv)
void main()
{
FILE *fp=NULL;
unsigned long size;
wav_pcm_header44 hwav;
short *data;
int i;
/*
* Get wave header information
*/
//fpWav = fopen(argv[1], "rb");
//fp = fopen("music_source.wav", "rb+");
//fpWav = fopen("abc.txt","r+");
// printf("Channel number: %d\n",fpWav);
if ((fp = fopen("News Item 1.wav","rb"))!=NULL)
{
fread(&hwav,sizeof(wav_pcm_header44),1,fp);
// fread(&hwav, 44,1,fp);
/* Check wave header */
if ( (0==memcmp(hwav.ChunkID, "RIFF", 4)) &&(0==memcmp(hwav.Format, "WAVE", 4)) &&
(0==memcmp(hwav.SubChunk1ID, "fmt ", 4)) &&(0==memcmp(hwav.SubChunk2ID, "data", 4)) &&(1==hwav.AudioFormat))
{
printf("Wave audio data format:\n");
printf("Channel number: %d\n", hwav.NumChannels);
printf("SampleRate: %dHz\n", hwav.SampleRate);
printf("BitsPerSample: %dbits\n", hwav.BitsPerSample);
printf("Audio data size:%d\n", hwav.SubChun2Size);
}
//printf("hwav.SubChun2Size:%d\n",hwav.ChunkID);
/*
* Get wave data
*/
data=(short*)malloc(sizeof(short)*hwav.SubChun2Size);
for (i=0;i<hwav.SubChun2Size;i++)
{
fread(&data,sizeof(wav_pcm_header44),1,fp);
}
// printf("DATA:%d\n", (&data);
fclose(fp);
fp = NULL;
}
else
{
//printf("Open wave file %s failed!\n", argv[1]);
printf("Open wave file %s failed!\n");
}
}
|