How does C++ read the header data of WAV audio files?
This article mainly introduces "how C++ reads the header data of WAV audio files". In daily operation, I believe many people have doubts about how C++ reads the header data of WAV audio files. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how C++ reads the header data of WAV audio files". Next, please follow the editor to study!
The realization method of C++ reading the header data of WAV audio file
Implementation code:
# include # include # include using namespace std;using std::string;using std::fstream; typedef struct WAV_HEADER {char RIFF [4]; / / RIFF Header Magic header unsigned long ChunkSize; / / RIFF ChunkSize char WAVE [4]; / / WAVE Header char fmt [4]; / / FMT header unsigned long Subchunk1Size; / / Size of the fmt chunk unsigned short AudioFormat / / Audio format 1 century PCM string unsigned long Subchunk2Size 6 years MulawMagol 7 4=16-bit stereo unsigned short bitsPerSample; alaw, 257=IBM Mu-Law, 258=IBM A-Law, 259=ADPCM unsigned short NumOfChan; / / Number of channels 1=Mono 2=Sterio unsigned long SamplesPerSec; / / Sampling Frequency in Hz unsigned long bytesPerSec; / / bytes per second unsigned short blockAlign; / / 2=16-bit mono, 4=16-bit stereo unsigned short bitsPerSample; / / Number of bits per sample char Subchunk2ID [4]; / / "data" string unsigned long Subchunk2Size / / Sampled data length} wav_hdr; / / Function prototypes int getFileSize (FILE * inFile); int main (int argc,char * argv []) {wav_hdr wavHeader; FILE * wavFile; int headerSize = sizeof (wav_hdr), filelength = 0; string answer; do {string input; string answer; const char* filePath; cout > input; cin.get (); cout