Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <string>
- #include <iostream>
- struct WaveHeader
- {
- char ChunkID_ [4];
- int ChunkDataSize_;
- char Format_ [4];
- char SubChunk1ID_ [4];
- int SubChunk1Size_;
- short int AudioFormat_;
- short int NumChannels_;
- int SampleRate_;
- int ByteRate_;
- short int BlockAlign_;
- short int BitsPerSample_;
- char SubChank2ID_ [4];
- int SubChank2Size_;
- };
- int main()
- {
- std::ifstream input_file;
- int length = 0;
- WaveHeader header;
- input_file.open("c:\\1.wav", std::fstream::binary);
- input_file.seekg (0, std::ios::end);
- length = input_file.tellg();
- std::cout << sizeof(int) << " " << sizeof(short int) << std::endl;
- std::cout << length << std::endl;
- if (length > sizeof(WaveHeader))
- {
- input_file.seekg (0, std::ios::beg);
- input_file.read(reinterpret_cast<char*>(&header), sizeof(WaveHeader));
- std::cout << input_file.gcount() << std::endl;
- std::cout << header.SubChank2Size_ << std::endl;
- std::cout << std::boolalpha << ( header.SubChank2Size_ == length - sizeof(WaveHeader) ) << std::endl;
- char* wav_buffer = new char[length - sizeof(WaveHeader)];
- input_file.read(wav_buffer, length - sizeof(WaveHeader));
- std::cout << input_file.gcount() << std::endl;
- delete[] wav_buffer;
- }
- input_file.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment