Skip to content

Commit

Permalink
Merge pull request #37 from helloimmatt/master
Browse files Browse the repository at this point in the history
More efficient and *faster* way of reading the whole file.
  • Loading branch information
adamstark authored Jan 23, 2021
2 parents 0e91c86 + adf81af commit 628219a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions AudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,25 @@ bool AudioFile<T>::load (std::string filePath)
return false;
}

file.unsetf (std::ios::skipws);
std::istream_iterator<uint8_t> begin (file), end;
std::vector<uint8_t> fileData (begin, end);
std::vector<uint8_t> fileData;

file.unsetf(std::ios::skipws);

file.seekg(0, std::ios::end);
size_t length = file.tellg();
file.seekg(0, std::ios::beg);

// allocate
fileData.resize(length);

file.read(reinterpret_cast<char*>(fileData.data()), length);
file.close();

if (file.gcount() != length)
{
reportError("ERROR: Couldn't read entire file\n" + filePath);
return false;
}

// get audio file format
audioFileFormat = determineAudioFileFormat (fileData);
Expand Down

0 comments on commit 628219a

Please sign in to comment.