| 421 | } |
| 422 | |
| 423 | bool DLSFile::LoadFile(std::string_view file) |
| 424 | { |
| 425 | Debug(driver, 2, "DMusic: Try to load DLS file {}", file); |
| 426 | |
| 427 | auto of = FileHandle::Open(file, "rb"); |
| 428 | if (!of.has_value()) return false; |
| 429 | auto &f = *of; |
| 430 | |
| 431 | /* Check DLS file header. */ |
| 432 | ChunkHeader hdr; |
| 433 | FOURCC dls_type; |
| 434 | if (fread(&hdr, sizeof(hdr), 1, f) != 1) return false; |
| 435 | if (fread(&dls_type, sizeof(dls_type), 1, f) != 1) return false; |
| 436 | if (hdr.type != FOURCC_RIFF || dls_type != FOURCC_DLS) return false; |
| 437 | |
| 438 | hdr.length -= sizeof(FOURCC); |
| 439 | |
| 440 | Debug(driver, 2, "DMusic: Parsing DLS file"); |
| 441 | |
| 442 | DLSHEADER header{}; |
| 443 | |
| 444 | /* Iterate over all chunks in the file. */ |
| 445 | while (hdr.length > 0) { |
| 446 | ChunkHeader chunk; |
| 447 | if (fread(&chunk, sizeof(chunk), 1, f) != 1) return false; |
| 448 | hdr.length -= chunk.length + sizeof(chunk); |
| 449 | |
| 450 | if (chunk.type == FOURCC_LIST) { |
| 451 | /* Unwrap list header. */ |
| 452 | if (fread(&chunk.type, sizeof(chunk.type), 1, f) != 1) return false; |
| 453 | chunk.length -= sizeof(chunk.type); |
| 454 | } |
| 455 | |
| 456 | switch (chunk.type) { |
| 457 | case FOURCC_COLH: |
| 458 | if (fread(&header, sizeof(header), 1, f) != 1) return false; |
| 459 | break; |
| 460 | |
| 461 | case FOURCC_LINS: // List chunk |
| 462 | if (!this->ReadDLSInstrumentList(f, chunk.length)) return false; |
| 463 | break; |
| 464 | |
| 465 | case FOURCC_WVPL: // List chunk |
| 466 | if (!this->ReadDLSWaveList(f, chunk.length)) return false; |
| 467 | break; |
| 468 | |
| 469 | case FOURCC_PTBL: |
| 470 | POOLTABLE ptbl; |
| 471 | if (fread(&ptbl, sizeof(ptbl), 1, f) != 1) return false; |
| 472 | fseek(f, ptbl.cbSize - sizeof(ptbl), SEEK_CUR); |
| 473 | |
| 474 | /* Read all defined cues. */ |
| 475 | for (ULONG i = 0; i < ptbl.cCues; i++) { |
| 476 | POOLCUE cue; |
| 477 | if (fread(&cue, sizeof(cue), 1, f) != 1) return false; |
| 478 | this->pool_cues.push_back(cue); |
| 479 | } |
| 480 | break; |
no test coverage detected