| 427 | } |
| 428 | |
| 429 | bool CPCMImport::OpenWaveFile() |
| 430 | { |
| 431 | // Open and read wave file header |
| 432 | PCMWAVEFORMAT WaveFormat = { }; // // // |
| 433 | char Header[4] = { }; |
| 434 | bool Scanning = true; |
| 435 | bool WaveFormatFound = false; |
| 436 | bool ValidWave = false; |
| 437 | unsigned int BlockSize; |
| 438 | unsigned int FileSize; |
| 439 | CFileException ex; |
| 440 | |
| 441 | m_iWaveSize = 0; |
| 442 | m_ullSampleStart = 0; |
| 443 | |
| 444 | TRACE(L"DPCM import: Loading wave file %s...\n", (LPCWSTR)m_strPath); |
| 445 | |
| 446 | if (!m_fSampleFile.Open(m_strPath, CFile::modeRead, &ex)) { |
| 447 | WCHAR szCause[255] = { }; |
| 448 | ex.GetErrorMessage(szCause, std::size(szCause)); |
| 449 | AfxMessageBox(FormattedW(L"Could not open file: %s", szCause)); // // // |
| 450 | return false; |
| 451 | } |
| 452 | |
| 453 | m_fSampleFile.Read(Header, 4); |
| 454 | |
| 455 | if (memcmp(Header, "RIFF", 4) != 0) { |
| 456 | // Invalid format |
| 457 | Scanning = false; |
| 458 | ValidWave = false; |
| 459 | } |
| 460 | else { |
| 461 | // Read file size |
| 462 | m_fSampleFile.Read(&FileSize, 4); |
| 463 | } |
| 464 | |
| 465 | // Now improved, should handle most files |
| 466 | while (Scanning) { |
| 467 | if (m_fSampleFile.Read(Header, 4) < 4) { |
| 468 | Scanning = false; |
| 469 | TRACE(L"DPCM import: End of file reached\n"); |
| 470 | } |
| 471 | |
| 472 | if (!memcmp(Header, "WAVE", 4)) { |
| 473 | ValidWave = true; |
| 474 | } |
| 475 | else if (Scanning) { |
| 476 | m_fSampleFile.Read(&BlockSize, 4); |
| 477 | |
| 478 | if (!memcmp(Header, "fmt ", 4)) { |
| 479 | // Read the wave-format |
| 480 | TRACE(L"DPCM import: Found fmt block\n"); |
| 481 | int ReadSize = BlockSize; |
| 482 | if (ReadSize > sizeof(PCMWAVEFORMAT)) |
| 483 | ReadSize = sizeof(PCMWAVEFORMAT); |
| 484 | |
| 485 | m_fSampleFile.Read(&WaveFormat, ReadSize); |
| 486 | m_fSampleFile.Seek(BlockSize - ReadSize, CFile::current); |
nothing calls this directly
no test coverage detected