// LoadWavHeader.cpp : main project file. #include #include #include #include using namespace std; class WavHeader { public: char RIFF[4]; /* RIFF Header */ //Magic header uint32_t fileSize; /* RIFF Chunk Size */ char WAVE[4]; /* WAVE Header */ char fmt[4]; /* FMT header */ uint32_t chunkSize; /* Size of the fmt chunk */ uint16_t audioFormat; /* Audio format 1=PCM,6=mulaw,7=alaw, 257=IBM Mu-Law, 258=IBM A-Law, 259=ADPCM */ uint16_t numOfChan; /* Number of channels 1=Mono 2=Sterio */ uint32_t samplesPerSec; /* Sampling Frequency in Hz */ uint32_t bytesPerSec; /* bytes per second */ uint16_t blockAlign; /* 2=16-bit mono, 4=16-bit stereo */ uint16_t bitsPerSample; /* Number of bits per sample */ char subchunk2ID[4]; /* "data" string */ uint32_t subchunk2Size; /* Sampled data length */ }; int errormessage(const char* msg, int error = 0) { cout << msg << endl; while(cin.get() != 10); return error; } int main() { FILE *fp = NULL; fp = fopen("test.wav", "r"); if(!fp) { return errormessage("Error: Cannot Open File"); } WavHeader header; fread(&header, sizeof(WavHeader), 1, fp); if(!strcmp(header.RIFF, "RIFF")) { errormessage("Error: Not RIFF Format!"); } if(!strcmp(header.WAVE, "WAVE")) { return errormessage("Error: File Is Not .Wav"); } if(!strcmp(header.fmt, "fmt ")) { return errormessage("Error: 'fmt ' Error"); } cout << "File Size: " << header.fileSize << endl; cout << "Chunk Size: " << header.chunkSize << endl; cout << "Format Type: " << header.audioFormat << endl; cout << "Channels: " << header.numOfChan << endl; cout << "Sample Rate: " << header.samplesPerSec << endl; cout << "Bytes Per Sec: " << header.bytesPerSec << endl; cout << "Press Enter To End"; while(cin.get() != 10); return 0; }