Get the App
SLTechnology News&Howtos  ›  Development  › 

How does C++ read the header data of WAV audio files?

Shulou Source: shulou.com Published: 2022-05-31 22:47:59 09月15日 Update

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

Tags: Headers data files audio clips learning methods more help practicality next code articles theories knowledge articles websites materials follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info Redmi Xiaomi Shulou Information