Skip to content

fix: normalise FLAC samples by 2^(bps-1) instead of 2^bps - #340

Open
molchalih wants to merge 1 commit into
devgianlu:masterfrom
molchalih:fix/flac-normalisation-divisor
Open

fix: normalise FLAC samples by 2^(bps-1) instead of 2^bps#340
molchalih wants to merge 1 commit into
devgianlu:masterfrom
molchalih:fix/flac-normalisation-divisor

Conversation

@molchalih

Copy link
Copy Markdown
Contributor

Noticed every FLAC track plays about 6 dB quieter than the same track over Vorbis. The decoder divides by 2^bits_per_sample, but libFLAC's write callback delivers signed samples in native range, so converting to [-1, 1] needs 2^(bps-1). The current divisor halves everything: a full-scale 16-bit sine (peak sample 32767) decodes to 0.499985 where it should be 0.999969, the player's own maxSampleValue. The vorbis path gets floats straight from libvorbis with no divisor at all, which is why the two codecs differ by exactly a factor of two at the same gain. 24-bit is affected identically. Added a regression test with a small committed fixture, since nothing else measures output amplitude and this survived compile, CI and review unnoticed.

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.

1 participant