#include <windows.h>
#include <mmsystem.h>
#include <iostream>
#include <fstream>
#include "stdafx.h"
using namespace std;
int endWithError(char *msg,int error =0)
{
cout<< msg << endl;
while(cin.get() != 10)
return error;
}
int _tmain(int argc, _TCHAR* argv[])
{
FILE *fp= NULL;
fp=fopen("test.wav","r");
if(!fp)
{
endWithError("Error : File Not Open");
}
char type[4];
DWORD size,chunkSize;
short formatType, channels;
DWORD sampleRate, avgBytesPerSec;
short bytesPerSample, bitsPerSample;
DWORD dataSize;
fread(type, sizeof(char), 4, fp);
if(!strcmp(type,"RIFF"))
{
return endWithError("Error : NOT RIFF EORMAT");
}
fread(&size, sizeof(DWORD), 1, fp);
fread(type, sizeof(char), 4, fp);
if(!strcmp(type,"WAVE"))
{
endWithError("Error : Not Wave Format");
}
fread(type, sizeof(char), 4,fp);
if(!strcmp(type,"fmt"))
{
endWithError("Error : Not Fmt ");
}
fread(&chunkSize, sizeof(DWORD), 1, fp);
fread(&formatType, sizeof(short), 1, fp);
fread(&channels, sizeof(short), 1, fp);
fread(&sampleRate, sizeof(DWORD), 1, fp);
fread(&avgBytesPerSec, sizeof(DWORD), 1, fp);
fread(&bytesPerSample, sizeof(short), 1, fp);
fread(&bitsPerSample, sizeof(short), 1, fp);
fread(type, sizeof(char), 4,fp);
if(!strcmp(type,"data"))
{
endWithError("Error : Error Missing Data");
}
fread(&dataSize, sizeof(DWORD), 1, fp);
cout << "chunk Size: " << chunkSize << endl;
cout <<"Format Type: "<< formatType <<endl;
cout <<"Channels: "<< channels <<endl;
cout <<"Sample Rate: "<< sampleRate <<endl;
cout <<"Average Bytes Per Sec: "<< avgBytesPerSec <<endl;
cout <<"Bytes Per Sample: "<< bytesPerSample <<endl;
cout <<"Bits Per Sample: "<< bitsPerSample <<endl;
cout <<"Press Enter To End"<< endl;
while(cin.get() != 10);
return 0;
}