1

I'm trying to decompress AIFF audio data from an XFDF sound annotation, and play the audio in the browser. Any time I export a sound annotation from Adobe Acrobat and decompress the audio data it results in seemingly garbage data.

The code below works for compressed audio starting with 789C header, but a few compressed streams start with 4889 or 78DA and fail to play in the browser. After numerous tests with Acrobat, exported sound annotations in XFDF start with 4889.


// Two audio examples, one working and one failing.
// Can't paste it all due to char limit.
const compressedHexString_working = `789C3C9C059C13D7FBF5473293F55DBCB8BBBBBB53DC8ABB142FEE5AB4 ...`;
const compressedHexString_failing = `48892C97077C8FE716C7CFF9532EB7418D5E24768492DABB0862146DAF ...`;

// Convert hex string into ArrayBuffer.
const compressedByteArray = new Uint8Array(
  compressedHexString_working
    .match(/[a-fA-F0-9]{2}/g)
    .map((str: string) => parseInt(str, 16))
);

const { default: zlib } = await import('pako');
const audioData = await zlib.inflate(compressedByteArray);

// Parse header bytes to determine audio file.
const fileHeader = new TextDecoder().decode(audioData).substring(0, 4);
console.log('Sound File Header:', fileHeader);

The console.log usually prints ID3, RIFF, or FORM when decompression is successful. But when decompressing the failing example, the result is a garbage value: �D�C.

Am I doing the decompression incorrectly? Or am I missing a step?

AdamInTheOculus
  • 360
  • 4
  • 10
  • Thanks @KJ I've removed `raw` references since the data I'm testing right now is an AIFF file. What's the best way for me to provide a sample of this audio file? I can also provide the XFDF file produced by Adobe Acrobat that contains the audio data I'm trying to decompress. – AdamInTheOculus Jan 10 '22 at 23:43
  • First time using transfer.sh so let me know if I'm doing it wrong! AIFF file: https://transfer.sh/CL1BfR/emajor_over_a.aiff XFDF file: https://transfer.sh/kXs41Y/emajor-over-a-aiff.xfdf – AdamInTheOculus Jan 10 '22 at 23:59
  • PDF: https://transfer.sh/GT600C/test.pdf – AdamInTheOculus Jan 11 '22 at 00:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240939/discussion-between-adamintheoculus-and-k-j). – AdamInTheOculus Jan 11 '22 at 01:04
  • 1
    Both streams are valid zlib up to the (short) length provided. – Mark Adler Jan 11 '22 at 19:03
  • Thanks for confirming, @MarkAdler! In that case I wonder why decompressing the Acrobat data does not recreate the original AIFF sound data ... – AdamInTheOculus Jan 11 '22 at 21:29

0 Answers0