هذا الكود بالسى بلس ارجو ان تجد فيه الفائده فحاول ان تجعله يعمل على فى بى اذا استطعت .....تحياتى
/*
This program is a C++ implementation of the C code you have.
All what the original code does, is that it reads a binary
sound file of type (.wav) and writes a textual representation of
the raw bytes of that file.
Enjoy
the input file consists of the following parts:
header: 44 bytes.
sound: the rest of the file.
*/
#include <iostream>
#include <fstream>
#include <string>
#include <exception>
std:
treamsize fileSize( const char* filePath ){ ///////////////////////
std::fstream::pos_type fsize = 0;
std::ifstream file( filePath, std::ios::binary );
fsize = file.tellg();
file.seekg( 0, std::ios::end );
fsize = file.tellg() - fsize;
file.close();
return fsize;
}
std:
tring byte_to_string(unsigned char byte)
{
const size_t byteBits = 8;
std:
tring byteString(byteBits, '0');
byteString[0] = (byte & 1) ? '1' : '0';
byteString[1] = (byte & 2) ? '1' : '0';
byteString[2] = (byte & 4) ? '1' : '0';
byteString[3] = (byte & 8) ? '1' : '0';
byteString[4] = (byte & 16) ? '1' : '0';
byteString[5] = (byte & 32) ? '1' : '0';
byteString[6] = (byte & 64) ? '1' : '0';
byteString[7] = (byte & 128) ? '1' : '0';
return byteString;
}
int main()
{
using namespace std;
const string soundFileName = "test.wav"; // input file
const string outputFileName = "test.txt"; // output file
const streamsize headerSize = 44;
const streamsize inputFileDataSize = fileSize(soundFileName.c_str()) - headerSize;
streamsize input_i = 0; // input file data pointer
ifstream inputFile(soundFileName.c_str(), ios::binary);
ofstream outputFile(outputFileName.c_str(), ios::trunc);
unsigned char byte;
// Discard the header, because we are interested in converting
// the raw bytes of the sound file only.
inputFile.seekg(headerSize, ios::beg);
while( input_i++ < inputFileDataSize )
{
inputFile.read(reinterpret_cast<char*>(&byte), sizeof(byte));
outputFile << byte_to_string(byte);
}
}