Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RF64 wave files #9543

Merged
merged 4 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix wrong RF64 data size and add unit test
  • Loading branch information
KasemJaffer committed Oct 15, 2021
commit 8501e997e036c99e128781e6d1658d0326dcd1a1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static WavHeader peek(ExtractorInput input) throws IOException {
// Allocate a scratch buffer large enough to store the format chunk.
ParsableByteArray scratch = new ParsableByteArray(16);

// Attempt to read the RIFF chunk.
// Attempt to read the RIFF or RF64 chunk.
ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.RF64_FOURCC) {
return null;
Expand Down Expand Up @@ -117,7 +117,10 @@ public static Pair<Long, Long> skipToData(ExtractorInput input) throws IOExcepti
ParsableByteArray scratch = new ParsableByteArray(ChunkHeader.SIZE_IN_BYTES);
// Skip all chunks until we find the data header.
ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);

// Data size holder. To be determined from data chunk or ds64 chunk in case of RF64.
long dataSize = -1;

while (chunkHeader.id != WavUtil.DATA_FOURCC) {
if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.FMT_FOURCC) {
KasemJaffer marked this conversation as resolved.
Show resolved Hide resolved
Log.w(TAG, "Ignoring unknown WAV chunk: " + chunkHeader.id);
Expand All @@ -131,9 +134,9 @@ public static Pair<Long, Long> skipToData(ExtractorInput input) throws IOExcepti
int ds64Size = (int) chunkHeader.size;
ParsableByteArray ds64Bytes = new ParsableByteArray(ds64Size);
input.peekFully(ds64Bytes.getData(), 0, ds64Size);
// ds64 chunk contains 64bit sizes. From position 12 to 20 is the data size
ds64Bytes.setPosition(12);
dataSize = ds64Bytes.readLong();
// ds64 chunk contains 64bit sizes. From position 8 to 16 is the data size
ds64Bytes.setPosition(8);
dataSize = ds64Bytes.readLittleEndianLong();
}
if (bytesToSkip > Integer.MAX_VALUE) {
throw ParserException.createForUnsupportedContainerFeature(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ public void sample_imaAdpcm() throws Exception {
ExtractorAsserts.assertBehavior(
WavExtractor::new, "media/wav/sample_ima_adpcm.wav", simulationConfig);
}

@Test
public void sample_RF64() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to generate the dump files that go with the test. To do so, you need to,

  • Set DUMP_FILE_ACTION to WRITE_TO_LOCAL in DumpFileAsserts.java
  • Run the test. This will create dump files that are a summary of the data extracted by the WavExtractor.
  • Set DUMP_FILE_ACTION back to COMPARE_WITH_EXISTING.
  • Run the test. This will compare the extracted data with the files previously generated. This test need to pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added the dump files and the test is passing :)

ExtractorAsserts
.assertBehavior(WavExtractor::new, "media/wav/sample_rf64.wav", simulationConfig);
}
}
Binary file not shown.