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

Use a shift instead of div to have bit exact output for MS Adpcm codec. #306

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dtzxporter
Copy link

This output now matches FFMPEG/ADPCMEncode.exe's output bit for bit.

@dedobbin
Copy link
Contributor

dedobbin commented Oct 3, 2024

Hey,

I played around a bit and wanted to run some files through symphonia-check, i ran into a right shift error though.

thread 'main' panicked at symphonia-codec-adpcm/src/codec_ms.rs:97:25:
attempt to shift right with overflow

tone4_adpmc_ms.wav.zip
The file i used. It's a tone generated in audacity and converted to adpcm_ms

@dtzxporter
Copy link
Author

Should be fixed now.

@dedobbin
Copy link
Contributor

Ah perfect! running the attached file through symphonia-check gives the same output as with master now.

@pdeljanov
Copy link
Owner

The reason why it overflowed is because evaluating 8 + signed_nibble * self.delta took precedence over the shift operation. So the amount shifted was not 8, rather, it was whatever that expression evaluated to, causing an overflow when it was >= 32.

The code below will work without the overhead of wrapping_shr.

let predictor = (((self.sample1 * self.coeff1) + (self.sample2 * self.coeff2)) >> 8) + signed_nibble * self.delta;

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.

3 participants