Hey i have a problem about file copying. I have a source file opened with fstream and a destination file opened with FILE*...im trying to copy a chunk of the source file into the destination (the function receives as parameters the start second on the source file in which we should start "recording" and the duration of the file to generate from the copy). It seems to be copying the bytes correctly (at least it generates the file, with something in it), but when i try with several different media players the file is impossible to open.
void Mp3::writeFrame(const Frame& f, FILE * dst, long start, long dur)
{
fstream file(this->name, ios::in || ios::binary);
int btr = (f.getBitrate() * 1000);
int currpos = f.get_start();
int start_byte = (currpos + (start * (btr/8)));
int finish_byte = ((dur * (btr/8)) + start_byte);
int memblock = (finish_byte - start_byte);
char * block = new char[memblock];
cout<<dec<<start_byte<<'\t'<<dec<<finish_byte<<'\n';
cout<<dec<<currpos<<'\t'<<dec<<memblock<<'\n';
cout<<dec<<start<<'\t'<<dec<<dur<<'\n';
cout<<dec<<btr<<'\t'<<'\n';
file.seekg(start_byte, ios::beg);
file.read(block,memblock);
cout<<hex<<block[0]<<'\t'<<hex<<block[1]<<'\n';
fwrite(block,memblock,1,dst);
}
Can anyone help me here? what am i doing wrong? the FILE* is already opened in main in binary mode.
Thanks