| 479 | //============================================================= |
| 480 | template <class T> |
| 481 | bool 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 | //============================================================= |
| 526 | template <class T> |
no outgoing calls