Skip to content

Conversation

@kroll-j
Copy link
Contributor

@kroll-j kroll-j commented Aug 19, 2017

Samples out of range -1..1 will create corrupt FLAC files.

@swh
Copy link
Owner

swh commented Aug 19, 2017

Thanks for the patch, but the number -0.999 and +0.999 are a bit aggressive, and will lead to legitimate signals being clipped.

The clipping could be better done by the FLAC encoder, as only it knows what it's internal threshold is.

@kroll-j
Copy link
Contributor Author

kroll-j commented Aug 19, 2017

If the FLAC encoder would do the encoding that would be optimal. The WAV encoder seems to clamp, but FLAC does not, resulting in broken encoding. It is not a simple integer wrap-around issue either; out-of-range samples seem to confuse the compression algorithm. I can upload such a file somewhere, you should also be able to reproduce it yourself using an out-of-range audio signal.

Clipping to this range is correct according to my tests. -1 to +1 refers to 0dB full-scale. I added a .001 margin to prevent possible wrap-around in edge cases due to rounding errors.

But it's true, in the long run, fixing he FLAC encoder would be better than this workaround.

@swh
Copy link
Owner

swh commented Aug 21, 2017 via email

@kroll-j
Copy link
Contributor Author

kroll-j commented Aug 21, 2017

Whether .1% of the range of a signal that's already at 0dBfs is too much, I don't know... Clamping when writing to floating-point formats that can reproduce signals >0dB perfectly fine is not nice, I agree on that much :)

I re-checked and the same wrapping issue happens with WAV with an integer format such as SF_FORMAT_PCM_16, only the compression issues are specific to FLAC. I'm opening an issue with libsndfile.

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