Skip to content

fix bitcrush formula#397

Open
ashinkajay wants to merge 2 commits intospotify:masterfrom
ashinkajay:fix_bitcrush
Open

fix bitcrush formula#397
ashinkajay wants to merge 2 commits intospotify:masterfrom
ashinkajay:fix_bitcrush

Conversation

@ashinkajay
Copy link
Copy Markdown

The scaleFactor used to multiply the the array to create the representation using new bit depth is 2**bit_depth.
But this will result in a representation with more than the expected bits.

The expected formula is: scaleFactor = (2**new_bit_depth)/2+1
New formula reference

Closes #396

gijzelaerr added a commit to gijzelaerr/pedalboard that referenced this pull request Mar 18, 2026
…metry

The scale factor was `pow(2, bitDepth)` which doesn't properly center
quantization around zero for signed audio. Changed to
`pow(2, bitDepth - 1) + 1` so that the quantization is symmetric.

Added tests verifying quantization correctness, symmetry around zero,
output range for signed audio, edge cases (bit_depth=1 and 16), and
expected number of quantization levels.

Fixes spotify#396
Related: spotify#397

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Wrong formula used for BitCrush

2 participants