MCPcopy Create free account
hub / github.com/adamstark/AudioFile / load

Method load

AudioFile.h:481–523  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479//=============================================================
480template <class T>
481bool AudioFile<T>::load (const std::string& filePath)
482{
483 std::ifstream file (filePath, std::ios::binary);
484
485 // check the file exists
486 if (! file.good())
487 {
488 reportError ("ERROR: File doesn't exist or otherwise can't load file\n" + filePath);
489 return false;
490 }
491
492 std::vector<uint8_t> fileData;
493
494 file.unsetf (std::ios::skipws);
495
496 file.seekg (0, std::ios::end);
497 size_t length = file.tellg();
498 file.seekg (0, std::ios::beg);
499
500 // allocate
501 fileData.resize (length);
502
503 file.read(reinterpret_cast<char*> (fileData.data()), length);
504 file.close();
505
506 if (file.gcount() != length)
507 {
508 reportError ("ERROR: Couldn't read entire file\n" + filePath);
509 return false;
510 }
511
512 // Handle very small files that will break our attempt to read the
513 // first header info from them
514 if (fileData.size() < 12)
515 {
516 reportError ("ERROR: File is not a valid audio file\n" + filePath);
517 return false;
518 }
519 else
520 {
521 return loadFromMemory (fileData);
522 }
523}
524
525//=============================================================
526template <class T>

Callers 14

writeTestAudioFileFunction · 0.80
test8Bit44100WithIntegerFunction · 0.80
test8Bit44100WithIntegerFunction · 0.80
GeneralTests.cppFile · 0.80
DOCTEST_DEFINE_DECORATORFunction · 0.80

Calls

no outgoing calls

Tested by 8

writeTestAudioFileFunction · 0.64
test8Bit44100WithIntegerFunction · 0.64
test8Bit44100WithIntegerFunction · 0.64
DOCTEST_DEFINE_DECORATORFunction · 0.64