Skip to content

bugfix: handle negative values according to their bit size in decode_truncated_block_i32 - #4

Open
mwicat wants to merge 1 commit into
monomadic:masterfrom
mwicat:bugfix/error-toowide-in-truncated-compression
Open

bugfix: handle negative values according to their bit size in decode_truncated_block_i32#4
mwicat wants to merge 1 commit into
monomadic:masterfrom
mwicat:bugfix/error-toowide-in-truncated-compression

Conversation

@mwicat

@mwicat mwicat commented Aug 19, 2024

Copy link
Copy Markdown

Hi,

I tried to use ncw-convert to convert a sample library consisting of 124 samples from several keygroups. Two of those samples caused some errors which I decided to analyze. This is one of them:

$ ncw-convert testfile-truncated-compression.ncw testfile-truncated-compression.wav
Error: TooWide

Looking at the file, it consists mostly of "delta decode" blocks but there is also one "bit truncation" block near the beginning that is not properly decoded by ncw-convert. Looking at the code, sequences of bytes for "bit truncation" scheme are treated like unsigned types which result in numbers that are too big to be encoded as signed type when writing to wave file and that in turn causes value checks in WavWriter::write_sample to throw an error. For example:

  • inside 24-bit size "bit truncation" block, a byte sequence [0xfc, 0x31, 0xda] is 24-bit little endian representation of -2477572 but decode_truncated_block_i32 will interpret is as 14299644 which is neither real sample value nor a value that can fit inside signed 24-bit type.

After applying my fix the file seems to be decoded properly, I hope this is in line with how "bit truncation" should work in general. Attaching the file that causes the mentioned error.

testfile-truncated-compression.zip

@mwicat
mwicat force-pushed the bugfix/error-toowide-in-truncated-compression branch from cee94fd to 8c89cda Compare August 19, 2024 19:03
@cheesymoo

Copy link
Copy Markdown

How do you reconcile this change with #5 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants