Read Microsoft Wave headers By the time we get here the first 32-bits of the file have already been read, and we're pretty sure that we're looking at a WAV file.
(final LameGlobalFlags gfp, final RandomAccessFile sf)
| 506 | * read, and we're pretty sure that we're looking at a WAV file. |
| 507 | */ |
| 508 | private int parse_wave_header(final LameGlobalFlags gfp, |
| 509 | final RandomAccessFile sf) { |
| 510 | int format_tag = 0; |
| 511 | int channels = 0; |
| 512 | int bits_per_sample = 0; |
| 513 | int samples_per_sec = 0; |
| 514 | |
| 515 | boolean is_wav = false; |
| 516 | int data_length = 0, subSize = 0; |
| 517 | int loop_sanity = 0; |
| 518 | |
| 519 | /* file_length = */Read32BitsHighLow(sf); |
| 520 | if (Read32BitsHighLow(sf) != WAV_ID_WAVE) |
| 521 | return -1; |
| 522 | |
| 523 | for (loop_sanity = 0; loop_sanity < 20; ++loop_sanity) { |
| 524 | int type = Read32BitsHighLow(sf); |
| 525 | |
| 526 | if (type == WAV_ID_FMT) { |
| 527 | subSize = Read32BitsLowHigh(sf); |
| 528 | if (subSize < 16) { |
| 529 | return -1; |
| 530 | } |
| 531 | |
| 532 | format_tag = Read16BitsLowHigh(sf); |
| 533 | subSize -= 2; |
| 534 | channels = Read16BitsLowHigh(sf); |
| 535 | subSize -= 2; |
| 536 | samples_per_sec = Read32BitsLowHigh(sf); |
| 537 | subSize -= 4; |
| 538 | /* avg_bytes_per_sec = */Read32BitsLowHigh(sf); |
| 539 | subSize -= 4; |
| 540 | /* block_align = */Read16BitsLowHigh(sf); |
| 541 | subSize -= 2; |
| 542 | bits_per_sample = Read16BitsLowHigh(sf); |
| 543 | subSize -= 2; |
| 544 | |
| 545 | /* WAVE_FORMAT_EXTENSIBLE support */ |
| 546 | if ((subSize > 9) && (format_tag == WAVE_FORMAT_EXTENSIBLE)) { |
| 547 | Read16BitsLowHigh(sf); /* cbSize */ |
| 548 | Read16BitsLowHigh(sf); /* ValidBitsPerSample */ |
| 549 | Read32BitsLowHigh(sf); /* ChannelMask */ |
| 550 | /* SubType coincident with format_tag for PCM int or float */ |
| 551 | format_tag = Read16BitsLowHigh(sf); |
| 552 | subSize -= 10; |
| 553 | } |
| 554 | |
| 555 | if (subSize > 0) { |
| 556 | try { |
| 557 | sf.skipBytes(subSize); |
| 558 | } catch (IOException e) { |
| 559 | return -1; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | } else if (type == WAV_ID_DATA) { |
| 564 | subSize = Read32BitsLowHigh(sf); |
| 565 | data_length = subSize; |
no test coverage detected