MCPcopy Create free account
hub / github.com/HertzDevil/0CC-FamiTracker / OpenWaveFile

Method OpenWaveFile

Source/PCMImport.cpp:429–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427}
428
429bool 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);

Callers

nothing calls this directly

Calls 8

sizeFunction · 0.85
FormattedWFunction · 0.85
GetErrorMessageMethod · 0.80
SeekMethod · 0.80
GetPositionMethod · 0.80
OpenMethod · 0.45
ReadMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected